mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-09 22:02:45 +08:00
扩展ECS框架可通过@ecs.register('Initialize')方式注册系统组件
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -116,8 +116,17 @@ export module ecs {
|
||||
*/
|
||||
export function register<T>(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<T>, name);
|
||||
}
|
||||
// 注册组件
|
||||
|
||||
@@ -76,4 +76,7 @@ export class ECSModel {
|
||||
}
|
||||
return group as unknown as ECSGroup<E>;
|
||||
}
|
||||
|
||||
/** 系统组件 */
|
||||
static systems: Map<string, ecs.System> = new Map<string, ecs.System>();
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import { ECSModel } from "./ECSModel";
|
||||
|
||||
/** 继承此类实现具体业务逻辑的系统 */
|
||||
export abstract class ECSComblockSystem<E extends ECSEntity = ECSEntity> {
|
||||
static s: boolean = true;
|
||||
|
||||
protected group: ECSGroup<E>;
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user