UnitAction.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { _decorator, Component } from 'cc';
  2. import { CarColors } from './CarColorsGlobalTypes';
  3. import { PinComponent } from './Components/PinComponent';
  4. import { LayerAction } from './LayerAction';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('UnitAction')
  7. export class UnitAction extends Component {
  8. start() {
  9. }
  10. update(deltaTime: number) {
  11. }
  12. public init_layer() {
  13. this.node.children.forEach(layer_node => {
  14. layer_node.getComponent(LayerAction).init_layer();
  15. });
  16. }
  17. public init_pin(color_pin_arr: CarColors[]) {
  18. this.node.children.forEach(layer_node => {
  19. layer_node.getComponent(LayerAction).init_pin(color_pin_arr);
  20. });
  21. }
  22. get_pin_color(arr: PinComponent[]): PinComponent[] {
  23. for (let i = this.node.children.length - 1; i >= 0; i--) {
  24. let layer_action = this.node.children[i].getComponent(LayerAction)!;
  25. layer_action.get_pin_color(arr);
  26. }
  27. return arr
  28. }
  29. get_layer(arr: LayerAction[]): LayerAction[] {
  30. //默认都是不显示的
  31. for (let i = this.node.children.length - 1; i >= 0; i--) {
  32. let layer_action = this.node.children[i]!.getComponent(LayerAction)!;
  33. if (layer_action) {
  34. arr.push(layer_action);
  35. }
  36. }
  37. return arr;
  38. }
  39. get_hole_num(): number {
  40. let hole_num: number = 0;
  41. this.node.children.forEach(layer_node => {
  42. let num = layer_node.getComponent(LayerAction).get_hole_num();
  43. hole_num += num;
  44. });
  45. return hole_num;
  46. }
  47. }