fix: 修复系统 onAdded 回调受注册顺序影响的问题 (#270)

This commit is contained in:
YHH
2025-12-04 12:56:19 +08:00
committed by GitHub
parent eec89b626c
commit dbebb4f4fb
5 changed files with 547 additions and 13 deletions

View File

@@ -321,11 +321,19 @@ export class Entity {
/**
* 通知Scene中的QuerySystem实体组件发生变动
*
* Notify the QuerySystem in Scene that entity components have changed
*
* @param changedComponentType 变化的组件类型(可选,用于优化通知) | Changed component type (optional, for optimized notification)
*/
private notifyQuerySystems(): void {
private notifyQuerySystems(changedComponentType?: ComponentType): void {
if (this.scene && this.scene.querySystem) {
this.scene.querySystem.updateEntity(this);
this.scene.clearSystemEntityCaches();
// 事件驱动:立即通知关心该组件的系统 | Event-driven: notify systems that care about this component
if (this.scene.notifyEntityComponentChanged) {
this.scene.notifyEntityComponentChanged(this, changedComponentType);
}
}
}
@@ -381,7 +389,7 @@ export class Entity {
});
}
this.notifyQuerySystems();
this.notifyQuerySystems(componentType);
return component;
}
@@ -514,7 +522,7 @@ export class Entity {
});
}
this.notifyQuerySystems();
this.notifyQuerySystems(componentType);
}
/**