From d8ea324018274fc29a23eab165620fac89e76e58 Mon Sep 17 00:00:00 2001 From: "SNDA\\niujiaqun.nathan" Date: Wed, 24 Sep 2025 18:14:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=BA=E6=99=AF=E7=A7=BB=E9=99=A4=E6=97=B6,?= =?UTF-8?q?=20=E6=B8=85=E7=90=86=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/ECS/Scene.ts | 9 ++++++++- packages/core/src/ECS/Systems/EntitySystem.ts | 1 + packages/core/src/ECS/Utils/EntityProcessorList.ts | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/core/src/ECS/Scene.ts b/packages/core/src/ECS/Scene.ts index 77db491b..6c56281f 100644 --- a/packages/core/src/ECS/Scene.ts +++ b/packages/core/src/ECS/Scene.ts @@ -338,7 +338,14 @@ export class Scene implements IScene { public removeEntityProcessor(processor: EntitySystem) { this.entityProcessors.remove(processor); processor.reset(); - processor.scene = null; + } + + /** + * 从场景中删除系统(removeEntityProcessor的别名) + * @param system 系统 + */ + public removeSystem(system: EntitySystem) { + this.removeEntityProcessor(system); } /** diff --git a/packages/core/src/ECS/Systems/EntitySystem.ts b/packages/core/src/ECS/Systems/EntitySystem.ts index dab90b24..b7194d90 100644 --- a/packages/core/src/ECS/Systems/EntitySystem.ts +++ b/packages/core/src/ECS/Systems/EntitySystem.ts @@ -162,6 +162,7 @@ export abstract class EntitySystem implements ISystemBase { * 当系统从场景中移除时调用,重置初始化状态以便重新添加时能正确初始化。 */ public reset(): void { + this.scene = null; this._initialized = false; this._trackedEntities.clear(); diff --git a/packages/core/src/ECS/Utils/EntityProcessorList.ts b/packages/core/src/ECS/Utils/EntityProcessorList.ts index 80e2116f..f747cfa5 100644 --- a/packages/core/src/ECS/Utils/EntityProcessorList.ts +++ b/packages/core/src/ECS/Utils/EntityProcessorList.ts @@ -65,6 +65,15 @@ export class EntityProcessorList { */ public end(): void { // 清理处理器 + for (const processor of this._processors) { + try { + processor.update(); + } catch (error) { + EntityProcessorList._logger.error(`Error in processor ${getSystemInstanceTypeName(processor)}:`, error); + } + } + this._isDirty = false; + this._processors.length = 0; } /**