refactor: 移除全局主角引用,改用ECS查询定位主角实体

- 移除 SingletonModuleComp 中的 role 字段及相关设置
- 在 MissionComp 中移除重置 role 的代码
- 修改 Hero 类的销毁方法,不再清理 role 引用
- 在 MissionCardComp 中通过 HeroMasterComp 查询来定位主角实体
- 增加详细调试日志以追踪天赋、技能等组件的添加过程
This commit is contained in:
panw
2026-02-03 15:56:22 +08:00
parent 63dd22fb88
commit 147131d3c2
4 changed files with 25 additions and 38 deletions

View File

@@ -33,12 +33,6 @@ export class Hero extends ecs.Entity {
}
destroy(): void {
// 如果是主角,清理全局引用
if (smc.role === this) {
console.log(`[Hero] 主角销毁,清除 smc.role`);
smc.role = null;
}
// 销毁节点,防止视觉残留
const view = this.get(HeroViewComp);
if (view && view.node && view.node.isValid) {
@@ -49,6 +43,7 @@ export class Hero extends ecs.Entity {
this.remove(HeroAttrsComp);
this.remove(HeroSkillsComp);
this.remove(TalComp);
this.remove(HeroMasterComp)
super.destroy();
}
@@ -94,8 +89,7 @@ export class Hero extends ecs.Entity {
model.rangeType = hero.rangeType;
// 只有主角才挂载天赋组件
if (is_master) {
smc.role = this; // 记录主角实体引用
console.log(`[Hero] 主角创建,设置 smc.role, uuid=${uuid}`);
console.log(`[Hero] 主角创建, uuid=${uuid}`);
this.add(TalComp);
this.add(HeroMasterComp)
const talComp = this.get(TalComp);