FAltarGear.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { HttpStateType, ReveData } from "../../../../util/CHttp";
  2. import FMap from "../../map/FMap";
  3. import FAltarLight from "./FAltarLight";
  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 FAltarGear extends cc.Component {
  16. @property({
  17. displayName: '对应的地图物件'
  18. })
  19. public mapGoodId: string = '27';
  20. @property({
  21. type: [cc.Node],
  22. displayName: '祭坛灯柱'
  23. })
  24. public altarLight: Array<cc.Node> = [];
  25. private map: FMap = null;
  26. onLoad() {
  27. this.map = this.node.parent.parent.getComponent(FMap);
  28. }
  29. /**
  30. * 检查灯柱点亮情况
  31. */
  32. public check() {
  33. for (let i = 0; i < this.altarLight.length; i++) {
  34. const element = this.altarLight[i];
  35. let altarLight = element.getComponent(FAltarLight)
  36. if (!altarLight.spine.active) {
  37. return false;
  38. }
  39. }
  40. this.openGear();
  41. return true
  42. }
  43. private openGear() {
  44. let ff = this.map.ff;
  45. ff.pauseSprite(true);
  46. this.moveCamera(() => {
  47. let nodes = this.node.children;
  48. nodes.forEach(element => {
  49. let spine = element.children[0].getComponent(sp.Skeleton);
  50. if (spine) {
  51. spine.setCompleteListener(() => {
  52. element.getComponent(cc.PhysicsBoxCollider).enabled = false;
  53. });
  54. spine.setAnimation(0, SpineName.OPEN, false);
  55. }
  56. });
  57. });
  58. }
  59. private moveCamera(callFunc: Function) {
  60. let map = this.map;
  61. let camera = map.mCamera;
  62. let pos = cc.v2();
  63. let winsize = cc.winSize;
  64. pos.x = this.node.x - winsize.width / 2;
  65. pos.y = this.node.y - winsize.height / 2;
  66. cc.tween(camera.node).sequence(
  67. cc.moveTo(1, pos).easing(cc.easeOut(1)),
  68. cc.callFunc(() => {
  69. callFunc && callFunc();
  70. }),
  71. cc.delayTime(1),
  72. cc.callFunc(() => {
  73. map.ff.pauseSprite(false);
  74. })
  75. ).start()
  76. }
  77. }