UnitAction.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { _decorator, Component } from 'cc';
  2. import { CarColors } from './CarColorsGlobalTypes';
  3. import { PinComponent } from './Components/PinComponent';
  4. import { LayerAction } from './LayerAction';
  5. import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
  6. import { GameEvent } from './Enum/GameEvent';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('UnitAction')
  9. export class UnitAction extends Component {
  10. start() {
  11. EventDispatcher.instance.on(GameEvent.EVENT_UPDATE_LAYER, this.onCheckLayerChild, this);
  12. }
  13. onCheckLayerChild() {
  14. if (!this.node) return
  15. this.node.children.forEach(layer_node => {
  16. const layer_action = layer_node.getComponent(LayerAction)!;
  17. if (layer_action.node.children.length <= 0) {
  18. console.log('删除一个Layer层 没有element元素了---->')
  19. layer_action.node.removeFromParent();
  20. layer_action.node.destroy();
  21. }
  22. });
  23. }
  24. update(deltaTime: number) {
  25. }
  26. public init_layer() {
  27. this.node.children.forEach(layer_node => {
  28. layer_node.getComponent(LayerAction).init_layer();
  29. });
  30. }
  31. public init_pin(color_pin_arr: CarColors[]) {
  32. this.node.children.forEach(layer_node => {
  33. layer_node.getComponent(LayerAction).init_pin(color_pin_arr);
  34. });
  35. }
  36. get_pin_color(arr: PinComponent[]): PinComponent[] {
  37. for (let i = this.node.children.length - 1; i >= 0; i--) {
  38. let layer_action = this.node.children[i].getComponent(LayerAction)!;
  39. layer_action.get_pin_color(arr);
  40. }
  41. return arr
  42. }
  43. get_layer(arr: LayerAction[]): LayerAction[] {
  44. //默认都是不显示的
  45. for (let i = this.node.children.length - 1; i >= 0; i--) {
  46. let layer_action = this.node.children[i]!.getComponent(LayerAction)!;
  47. if (layer_action) {
  48. arr.push(layer_action);
  49. }
  50. }
  51. return arr;
  52. }
  53. get_hole_num(): number {
  54. let hole_num: number = 0;
  55. this.node.children.forEach(layer_node => {
  56. let num = layer_node.getComponent(LayerAction).get_hole_num();
  57. hole_num += num;
  58. });
  59. return hole_num;
  60. }
  61. }