2023-11-15 18:38:00 +08:00
|
|
|
import { _decorator, Component, Node } from 'cc';
|
|
|
|
import { PlayerTacticalItem } from './PlayerTacticalItem';
|
2023-11-16 02:44:43 +08:00
|
|
|
import { app } from '../../../App';
|
|
|
|
import { PlayerTacticalEvent } from '../../../data/PlayerTacticalData';
|
2023-11-15 18:38:00 +08:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 玩家阵法
|
|
|
|
*/
|
|
|
|
@ccclass('PlayerTacticalView')
|
|
|
|
export class PlayerTacticalView extends Component {
|
|
|
|
|
|
|
|
|
|
|
|
//阵法子节点列表
|
|
|
|
items:PlayerTacticalItem[] = [];
|
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
onLoad(){
|
2023-11-15 18:38:00 +08:00
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
//阵法
|
|
|
|
this.items = this.node.getComponentsInChildren(PlayerTacticalItem);
|
|
|
|
this.items.forEach((item,index) => {
|
|
|
|
item.onInit(index); //初始化阵法下标
|
|
|
|
});
|
2023-11-15 18:38:00 +08:00
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
this.onUpdateView();
|
2023-11-15 18:38:00 +08:00
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
this.onEvent();
|
2023-11-15 18:38:00 +08:00
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
2023-11-15 18:38:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|