OpenDoor.ts 2.5 KB

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