feat(map): 新增可动态加载的收集物UI组件
- 添加 MGetComp 组件用于管理单个收集物的显示逻辑 - 创建 get.prefab 预制体作为收集物UI模板 - 重构 MissionGetsComp,移除硬编码节点引用,改为动态加载 - 支持通过 load_hui 方法按需加载收集物UI实例
This commit is contained in:
@@ -11,53 +11,19 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('MissionGetsCompComp')
|
||||
@ecs.register('MissionGetsComp', false)
|
||||
export class MissionGetsCompComp extends CCComp {
|
||||
@property(Node)
|
||||
get0:Node = null!
|
||||
@property(Node)
|
||||
get1:Node = null!
|
||||
@property(Node)
|
||||
get2:Node = null!
|
||||
@property(Node)
|
||||
get3:Node = null!
|
||||
@property(Node)
|
||||
get4:Node = null!
|
||||
@property(Node)
|
||||
get5:Node = null!
|
||||
|
||||
start() {
|
||||
oops.message.on(GameEvent.UpdateCollection, this.updateView, this);
|
||||
this.updateView();
|
||||
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
oops.message.off(GameEvent.UpdateCollection, this.updateView, this);
|
||||
|
||||
}
|
||||
|
||||
private updateView() {
|
||||
if (!smc.vmdata || !smc.vmdata.collection) return;
|
||||
const data = smc.vmdata.collection;
|
||||
|
||||
// Talents (get0 - get3)
|
||||
const talentIds = Object.keys(data.talents);
|
||||
const talentNodes = [this.get0, this.get1, this.get2, this.get3];
|
||||
|
||||
for (let i = 0; i < talentNodes.length; i++) {
|
||||
const node = talentNodes[i];
|
||||
if (i < talentIds.length) {
|
||||
const id = Number(talentIds[i]); // Object.keys returns strings
|
||||
const count = data.talents[id];
|
||||
this.updateNodeNum(node, count);
|
||||
} else {
|
||||
this.updateNodeNum(node, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Skill (get4)
|
||||
this.updateNodeNum(this.get4, data.skill.count);
|
||||
|
||||
// Friend (get5)
|
||||
this.updateNodeNum(this.get5, data.friend.count);
|
||||
}
|
||||
load_hui(uuid:number, pos_index: number){
|
||||
var path = "game/gui/get";
|
||||
|
||||
}
|
||||
|
||||
private updateNodeNum(node: Node, num: number) {
|
||||
if (!node) return;
|
||||
|
||||
Reference in New Issue
Block a user