OpenDoor.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import FqLogin from "../../login/FqLogin";
  2. import { AudioMgr } from "../../main/ViewManage";
  3. import BaseEvent from "../fight/evnet/base/BaseEvent";
  4. const SpineName = {
  5. IDLE: "idle",
  6. IDLE2: "idle2",
  7. CLOSE: "close",
  8. OPEN: "open"
  9. }
  10. /**
  11. * 多组按钮控制开门
  12. */
  13. const { ccclass, property } = cc._decorator;
  14. @ccclass
  15. export default class OpenDoor extends BaseEvent {
  16. @property({
  17. displayName: '道具ID',
  18. })
  19. goodID: number = 2001;
  20. /**
  21. * 控制的栅栏机关
  22. */
  23. @property({
  24. displayName: '控制的机关',
  25. type: [cc.Node],
  26. })
  27. mFenceTrigger: Array<cc.Node> = [];
  28. @property({
  29. displayName: '提示图标',
  30. type:cc.SpriteFrame
  31. })
  32. mTipsIcon: cc.SpriteFrame = null;
  33. private count = 0;
  34. onBegin(tag: number) {
  35. let head = this.ff.mFFheader;
  36. let count = head.getTmpCount(this.goodID);
  37. if (count > 0) {
  38. head.removeTmpGood(this.goodID, 1);
  39. this.showOpt(this.mTipsIcon,()=>{
  40. this.checkOpen();
  41. })
  42. }else{
  43. }
  44. }
  45. onEnd(tag: number) {
  46. this.closeOpt();
  47. }
  48. private checkOpen() {
  49. //检查其它开关是否打开
  50. this.pause();
  51. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  52. cc.tween(this.node).sequence(
  53. cc.callFunc(() => {
  54. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  55. const element = this.mFenceTrigger[i];
  56. this.showFence(element, SpineName.OPEN);
  57. }
  58. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  59. }),
  60. cc.delayTime(1),
  61. cc.callFunc(() => {
  62. this.resume()
  63. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  64. const element = this.mFenceTrigger[i];
  65. // element.active = false;
  66. element.getComponent(cc.PhysicsBoxCollider).enabled = false;
  67. }
  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. }