diff --git a/assets/core/Root.ts b/assets/core/Root.ts index 598ab7b..1519e61 100644 --- a/assets/core/Root.ts +++ b/assets/core/Root.ts @@ -100,7 +100,6 @@ export class Root extends Component { oops.game = new GameManager(this.game); oops.gui = new LayerManager(this.gui); this.initGui(); - this.initEcsSystem(); oops.ecs.init(); diff --git a/assets/libs/ecs/ECS.ts b/assets/libs/ecs/ECS.ts index 48d6586..f240143 100644 --- a/assets/libs/ecs/ECS.ts +++ b/assets/libs/ecs/ECS.ts @@ -116,8 +116,17 @@ export module ecs { */ export function register(name: string, canNew: boolean = true) { return function (ctor: any) { + // 注册系统 + if (ctor.s) { + var system: ecs.System = ECSModel.systems.get(name); + if (system == null) { + system = new ecs.System(); + ECSModel.systems.set(name, system); + } + system.add(new ctor); + } // 注册实体 - if (ctor.tid == undefined) { + else if (ctor.tid == undefined) { ECSModel.entityCtors.set(ctor as EntityCtor, name); } // 注册组件 diff --git a/assets/libs/ecs/ECSModel.ts b/assets/libs/ecs/ECSModel.ts index 12afa5e..91b2514 100644 --- a/assets/libs/ecs/ECSModel.ts +++ b/assets/libs/ecs/ECSModel.ts @@ -76,4 +76,7 @@ export class ECSModel { } return group as unknown as ECSGroup; } + + /** 系统组件 */ + static systems: Map = new Map(); } \ No newline at end of file diff --git a/assets/libs/ecs/ECSSystem.ts b/assets/libs/ecs/ECSSystem.ts index 67c4a56..4f91ae5 100644 --- a/assets/libs/ecs/ECSSystem.ts +++ b/assets/libs/ecs/ECSSystem.ts @@ -5,6 +5,8 @@ import { ECSModel } from "./ECSModel"; /** 继承此类实现具体业务逻辑的系统 */ export abstract class ECSComblockSystem { + static s: boolean = true; + protected group: ECSGroup; protected dt: number = 0; @@ -179,6 +181,12 @@ export class ECSRootSystem { } init() { + // 自动注册系统组件 + ECSModel.systems.forEach(s => { + this.add(s); + }); + + // 初始化组件 this.executeSystemFlows.forEach(sys => sys.init()); }