* 系统初始化(框架调用) * * 在系统创建时调用。框架内部使用,用户不应直接调用。
()
| 434 | * 在系统创建时调用。框架内部使用,用户不应直接调用。 |
| 435 | */ |
| 436 | public initialize(): void { |
| 437 | // 防止重复初始化 | Prevent re-initialization |
| 438 | if (this._initialized) { |
| 439 | return; |
| 440 | } |
| 441 | |
| 442 | this._initialized = true; |
| 443 | |
| 444 | // 框架内部初始化:触发一次实体查询,以便正确跟踪现有实体 |
| 445 | // Framework initialization: query entities once to track existing entities |
| 446 | if (this.scene) { |
| 447 | // 清理缓存确保初始化时重新查询 | Clear cache to ensure fresh query |
| 448 | this._entityCache.invalidate(); |
| 449 | const entities = this.queryEntities(); |
| 450 | |
| 451 | // 初始化时对已存在的匹配实体触发 onAdded |
| 452 | // Trigger onAdded for existing matching entities during initialization |
| 453 | for (const entity of entities) { |
| 454 | this.onAdded(entity); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | // 调用用户可重写的初始化方法 | Call user-overridable initialization method |
| 459 | this.onInitialize(); |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * 系统初始化回调 |
nothing calls this directly
no test coverage detected