DESKTOP-5RP3AKU\Jisol 1683ec01a0 宠物上阵
2023-11-16 02:44:43 +08:00

58 lines
1.1 KiB
TypeScript

import { _decorator, Component, Node } from 'cc';
import { PlayerTacticalItem } from './PlayerTacticalItem';
import { app } from '../../../App';
import { PlayerTacticalEvent } from '../../../data/PlayerTacticalData';
const { ccclass, property } = _decorator;
/**
* 玩家阵法
*/
@ccclass('PlayerTacticalView')
export class PlayerTacticalView extends Component {
//阵法子节点列表
items:PlayerTacticalItem[] = [];
onLoad(){
//阵法
this.items = this.node.getComponentsInChildren(PlayerTacticalItem);
this.items.forEach((item,index) => {
item.onInit(index); //初始化阵法下标
});
this.onUpdateView();
this.onEvent();
}
protected onDestroy(): void {
this.offEvent();
}
//添加监听
onEvent(){
app.event.on(PlayerTacticalEvent.UPDATE_TACTICAL,this.onUpdateView,this);
}
//移除监听
offEvent(){
app.event.off(PlayerTacticalEvent.UPDATE_TACTICAL,this.onUpdateView,this);
}
//更新阵法显示
onUpdateView(){
this.items.forEach(item => {
item.onUpdateView();
})
}
}