feat: 添加主角实体引用并确保跨局重置
在 SingletonModuleComp 中添加 role 字段存储主角实体引用,并在 MissionComp 任务开始时重置引用,在 Hero 销毁时清理引用。避免跨局数据残留导致引用错误。
This commit is contained in:
@@ -31,6 +31,11 @@ export class Hero extends ecs.Entity {
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
// 如果是主角,清理全局引用
|
||||
if (smc.role === this) {
|
||||
smc.role = null;
|
||||
}
|
||||
|
||||
// 销毁节点,防止视觉残留
|
||||
const view = this.get(HeroViewComp);
|
||||
if (view && view.node && view.node.isValid) {
|
||||
@@ -86,6 +91,7 @@ export class Hero extends ecs.Entity {
|
||||
model.rangeType = hero.rangeType;
|
||||
// 只有主角才挂载天赋组件
|
||||
if (is_master) {
|
||||
smc.role = this; // 记录主角实体引用
|
||||
this.add(TalComp);
|
||||
const talComp = this.get(TalComp);
|
||||
if (talComp) {
|
||||
|
||||
Reference in New Issue
Block a user