FBothwayOpen.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { AudioMgr } from "../../../../main/ViewManage";
  2. import BaseEvent from "../base/BaseEvent";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class FBothwayOpen extends BaseEvent {
  6. /**
  7. * 控制的栅栏机关
  8. */
  9. @property({
  10. displayName: 'left机关',
  11. type: cc.Node,
  12. })
  13. leftFenceTrigger: cc.Node = null;
  14. @property({
  15. displayName: 'right机关',
  16. type: cc.Node,
  17. })
  18. rightFenceTrigger: cc.Node = null;
  19. @property({
  20. displayName: '提示图标',
  21. type: cc.SpriteFrame
  22. })
  23. mTipsIcon: cc.SpriteFrame = null;
  24. @property({
  25. displayName: "动画",
  26. type: sp.Skeleton,
  27. })
  28. spine: sp.Skeleton = null;
  29. openType: string = "";
  30. onBegin(tag) {
  31. if (tag == 0) {
  32. this.showOpt(this.mTipsIcon, () => {
  33. this.spineAction(this.spine, "left", () => {
  34. this.openmFenceTrigger(this.leftFenceTrigger, "left");
  35. })
  36. })
  37. } else if (tag == 1) {
  38. this.showOpt(this.mTipsIcon, () => {
  39. this.spineAction(this.spine, "right", () => {
  40. this.openmFenceTrigger(this.rightFenceTrigger, "right");
  41. })
  42. })
  43. }
  44. }
  45. onEnd(tag: number) {
  46. this.closeOpt();
  47. }
  48. openmFenceTrigger(node: cc.Node, type: string) {
  49. this.pause();
  50. this.moveCamera(node.getPosition(), 1, () => {
  51. cc.tween(this.node).sequence(
  52. cc.callFunc(() => {
  53. if (this.openType != type) {
  54. this.showFence(node, "close");
  55. if (this.openType != "") {
  56. this[`${this.openType}FenceTrigger`].active = true;
  57. this.showFence(this[`${this.openType}FenceTrigger`], "open");
  58. }
  59. }
  60. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  61. }),
  62. cc.delayTime(1),
  63. cc.callFunc(() => {
  64. this.openType = type;
  65. node.active = false;
  66. this.resume();
  67. this.closeOpt();
  68. })
  69. ).start();
  70. })
  71. }
  72. private showFence(element, action) {
  73. let nodes = element.children;
  74. for (let i = 0; i < nodes.length; i++) {
  75. const element = nodes[i];
  76. let spine: sp.Skeleton = element.getComponent(sp.Skeleton);
  77. if (spine) {
  78. spine.setAnimation(0, action, false);
  79. }
  80. }
  81. }
  82. }