JG0111.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. onLoad(){
  54. super.onLoad();
  55. this.node.zIndex = -9999;
  56. }
  57. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  58. if (other.node.group != 'bullet') {
  59. this.onBegin(other.tag)
  60. }
  61. }
  62. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
  63. if (other.node.group != 'bullet') {
  64. this.onEnd(other.tag)
  65. }
  66. }
  67. onBegin(tag: number) {
  68. if(tag == 1){
  69. this.isHang = true;
  70. this.mIcon.spriteFrame = this.mIcon1;
  71. this.checkOpen();
  72. }
  73. }
  74. onEnd(tag: number) {
  75. if(tag == 1){
  76. this.isHang = false
  77. this.mIcon.spriteFrame = this.mIcon0
  78. this.isOver = false;
  79. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  80. const element = this.mFenceTrigger[i];
  81. // element.active = true;
  82. this.showFence(element, SpineName.CLOSE);
  83. element.getComponent(cc.PhysicsBoxCollider).enabled = true;
  84. }
  85. }
  86. }
  87. private checkOpen() {
  88. if (this.isOver) {
  89. return
  90. }
  91. //检查其它开关是否打开
  92. for (let i = 0; i < this.mButtons.length; i++) {
  93. const element = this.mButtons[i];
  94. let fdb = element.getComponent(JG0111)
  95. if (!fdb.isHang) return
  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, SpineName.OPEN);
  105. element.zIndex = -9999;
  106. }
  107. this.ff.main.playerEffectByPath(AudioMgr.openDoor);
  108. }),
  109. cc.delayTime(1),
  110. cc.callFunc(() => {
  111. this.resume()
  112. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  113. const element = this.mFenceTrigger[i];
  114. // element.active = false;
  115. element.getComponent(cc.PhysicsBoxCollider).enabled = false;
  116. }
  117. })
  118. ).start();
  119. })
  120. }
  121. private showFence(element, action) {
  122. let nodes = element.children;
  123. for (let i = 0; i < nodes.length; i++) {
  124. const element = nodes[i];
  125. let spine:sp.Skeleton = element.getComponent(sp.Skeleton);
  126. if (spine) {
  127. spine.setAnimation(0, action, false);
  128. }
  129. }
  130. }
  131. }