JG0120.ts 4.0 KB

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