123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import { _decorator, Component } from 'cc';
- import { CarColors } from './CarColorsGlobalTypes';
- import { PinComponent } from './Components/PinComponent';
- import { LayerAction } from './LayerAction';
- import { EventDispatcher } from '../../core_tgx/easy_ui_framework/EventDispatcher';
- import { GameEvent } from './Enum/GameEvent';
- const { ccclass, property } = _decorator;
- @ccclass('UnitAction')
- export class UnitAction extends Component {
- start() {
- EventDispatcher.instance.on(GameEvent.EVENT_UPDATE_LAYER, this.onCheckLayerChild, this);
- }
- onCheckLayerChild() {
- if (!this.node) return
- // console.log('检查Layer层是否有element元素了---->');
- this.node.children.forEach(layer_node => {
- if (layer_node.children.length <= 0) {
- console.log('layer层级没有element元素了,移除layer层----')
- layer_node.removeFromParent();
- layer_node.destroy();
- }
- });
- }
- update(deltaTime: number) {
- }
- public init_layer() {
- this.node.children.forEach(layer_node => {
- layer_node.getComponent(LayerAction).init_layer();
- });
- }
- public init_pin(color_pin_arr: CarColors[]) {
- this.node.children.forEach(layer_node => {
- layer_node.getComponent(LayerAction).init_pin(color_pin_arr);
- });
- }
- get_pin_color(arr: PinComponent[]): PinComponent[] {
- for (let i = this.node.children.length - 1; i >= 0; i--) {
- let layer_action = this.node.children[i].getComponent(LayerAction)!;
- layer_action.get_pin_color(arr);
- }
- return arr
- }
- get_layer(arr: LayerAction[]): LayerAction[] {
- //默认都是不显示的
- for (let i = this.node.children.length - 1; i >= 0; i--) {
- let layer_action = this.node.children[i]!.getComponent(LayerAction)!;
- if (layer_action) {
- arr.push(layer_action);
- }
- }
- return arr;
- }
- get_hole_num(): number {
- let hole_num: number = 0;
- this.node.children.forEach(layer_node => {
- let num = layer_node.getComponent(LayerAction).get_hole_num();
- hole_num += num;
- });
- return hole_num;
- }
- }
|