OriginArea.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { _decorator, Component, Node } from 'cc';
  2. import { OriginCup } from './OriginCup';
  3. import { Water } from './Water';
  4. import { EventDispatcher } from 'db://assets/core_tgx/easy_ui_framework/EventDispatcher';
  5. import { GameEvent } from '../Enum/GameEvent';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('OriginArea')
  8. export class OriginArea extends Component {
  9. start() {
  10. this.registerListener();
  11. }
  12. registerListener() {
  13. EventDispatcher.instance.on(GameEvent.EVENT_ORIGIN_CUP_DESTROYED, this.unfreezeCup, this);
  14. }
  15. protected onDestroy(): void {
  16. this.unregisterListener();
  17. }
  18. unregisterListener() {
  19. EventDispatcher.instance.off(GameEvent.EVENT_ORIGIN_CUP_DESTROYED, this.unfreezeCup, this);
  20. }
  21. /** 获取所有原浆杯水节点的mark数量*/
  22. public getTotalMarkCount(): number {
  23. let count = 0;
  24. this.node.children.forEach(originCupNode => {
  25. const originCup = originCupNode.getComponent(OriginCup);
  26. if (originCup) {
  27. originCup.marks.children.forEach(markNode => {
  28. if (markNode.active) {
  29. count++;
  30. }
  31. });
  32. }
  33. });
  34. return count;
  35. }
  36. /** 获取冰冻杯数量*/
  37. public getFrozenCupCount(): number {
  38. let count = 0;
  39. this.node.children.forEach(originCupNode => {
  40. const originCup = originCupNode.getComponent(OriginCup);
  41. if (originCup) {
  42. if (originCup.freezeActive) {
  43. count++;
  44. }
  45. }
  46. });
  47. return count;
  48. }
  49. //解冻冰冻水杯
  50. private unfreezeCup() {
  51. this.node.children.forEach(originCupNode => {
  52. const originCup = originCupNode.getComponent(OriginCup);
  53. if (originCup) {
  54. if (originCup.freezeActive) {
  55. originCup.unFreeze();
  56. }
  57. }
  58. });
  59. }
  60. }