FOpenDoorButton.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import FqLogin from "../../../../login/FqLogin";
  2. import { AudioMgr } from "../../../../main/ViewManage";
  3. import BaseEvent from "../base/BaseEvent";
  4. /**
  5. * 多组按钮控制开门
  6. */
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class FOpenDoorButton extends BaseEvent {
  10. @property({
  11. displayName: '替换的图片',
  12. type: cc.Sprite,
  13. })
  14. mIcon: cc.Sprite = null;
  15. @property({
  16. displayName: '未踩上图片',
  17. type: cc.SpriteFrame,
  18. })
  19. mIcon0: cc.SpriteFrame = null;
  20. @property({
  21. displayName: '踩上后的图片',
  22. type: cc.SpriteFrame,
  23. })
  24. mIcon1: cc.SpriteFrame = null;
  25. /**
  26. * 控制的栅栏机关
  27. */
  28. @property({
  29. displayName: '其它开关',
  30. type: [cc.Node],
  31. })
  32. mButtons: Array<cc.Node> = [];
  33. /**
  34. * 控制的栅栏机关
  35. */
  36. @property({
  37. displayName: '控制的机关',
  38. type: [cc.Node],
  39. })
  40. mFenceTrigger: Array<cc.Node> = [];
  41. /**
  42. * 是否选中
  43. */
  44. public isHang = false;
  45. /**
  46. * 机关是否已经结束
  47. */
  48. public isOver = false;
  49. private count = 0;
  50. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  51. if (other.node.group != 'bullet') {
  52. this.count++
  53. this.onBegin(self.tag)
  54. }
  55. }
  56. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  57. if (other.node.group != 'bullet') {
  58. this.count--
  59. if (this.count <= 0) {
  60. this.count = 0;
  61. this.onEnd(self.tag)
  62. }
  63. }
  64. }
  65. onBegin(tag: number) {
  66. this.isHang = true
  67. this.mIcon.spriteFrame = this.mIcon1
  68. this.checkOpen()
  69. }
  70. onEnd(tag: number) {
  71. this.isHang = false
  72. this.mIcon.spriteFrame = this.mIcon0
  73. this.isOver = false;
  74. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  75. const element = this.mFenceTrigger[i];
  76. element.active = true;
  77. this.showFence(element, 'open');
  78. }
  79. }
  80. private checkOpen() {
  81. // cc.log('checkOpen : ',this.isOver)
  82. if (this.isOver) {
  83. return
  84. }
  85. //检查其它开关是否打开
  86. for (let i = 0; i < this.mButtons.length; i++) {
  87. const element = this.mButtons[i];
  88. let fdb = element.getComponent(FOpenDoorButton)
  89. if (!fdb.isHang) {
  90. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  91. const element = this.mFenceTrigger[i];
  92. this.showFence(element, 'shake');
  93. }
  94. return
  95. }
  96. }
  97. this.isOver = true
  98. this.pause()
  99. this.moveCamera(this.mFenceTrigger[0].getPosition(), 1, () => {
  100. cc.tween(this.node).sequence(
  101. cc.callFunc(() => {
  102. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  103. const element = this.mFenceTrigger[i];
  104. this.showFence(element, 'close');
  105. }
  106. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  107. }),
  108. cc.delayTime(1),
  109. cc.callFunc(() => {
  110. this.resume()
  111. FqLogin.commitEvent(this.node.name, '', '');
  112. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  113. const element = this.mFenceTrigger[i];
  114. element.active = false;
  115. }
  116. })
  117. ).start();
  118. })
  119. }
  120. private showFence(element, action) {
  121. let nodes = element.children;
  122. for (let i = 0; i < nodes.length; i++) {
  123. const element = nodes[i];
  124. let spine = element.getComponent(sp.Skeleton);
  125. if (spine) {
  126. spine.setAnimation(0, action, false);
  127. }
  128. }
  129. }
  130. }