JG0111.ts 3.9 KB

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