@cjhd/cj-ecs 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/assets/common/component/MoveComponent.d.ts +141 -0
  2. package/assets/common/component/NodeComponent.d.ts +98 -0
  3. package/assets/common/system/MoveSystem.d.ts +17 -0
  4. package/assets/ecs/EcsComponent.d.ts +89 -0
  5. package/assets/ecs/{EcsDirty.ts → EcsDirty.d.ts} +340 -459
  6. package/assets/ecs/EcsEntity.d.ts +148 -0
  7. package/assets/ecs/EcsSingleton.d.ts +3 -0
  8. package/assets/ecs/EcsSystem.d.ts +96 -0
  9. package/assets/ecs.d.ts +126 -0
  10. package/assets/lib/EcsCache.d.ts +24 -0
  11. package/assets/lib/EcsFilter.d.ts +57 -0
  12. package/assets/lib/EcsManager.d.ts +251 -0
  13. package/assets/lib/{EcsObject.ts → EcsObject.d.ts} +360 -422
  14. package/assets/lib/EcsTimer.d.ts +119 -0
  15. package/assets/lib/EcsTween.d.ts +168 -0
  16. package/assets/lib/EcsUtils.d.ts +82 -0
  17. package/dist/cocos/assets/common/component/MoveComponent.js +4 -0
  18. package/dist/cocos/assets/common/component/NodeComponent.js +4 -0
  19. package/dist/cocos/assets/common/system/MoveSystem.js +2 -0
  20. package/dist/cocos/assets/ecs/EcsComponent.js +4 -0
  21. package/dist/cocos/assets/ecs/EcsDirty.js +4 -0
  22. package/dist/cocos/assets/ecs/EcsEntity.js +4 -0
  23. package/dist/cocos/assets/ecs/EcsSingleton.js +4 -0
  24. package/dist/cocos/assets/ecs/EcsSystem.js +2 -0
  25. package/dist/cocos/assets/ecs.js +2 -0
  26. package/dist/cocos/assets/lib/EcsCache.js +2 -0
  27. package/dist/cocos/assets/lib/EcsFilter.js +2 -0
  28. package/dist/cocos/assets/lib/EcsManager.js +4 -0
  29. package/dist/cocos/assets/lib/EcsObject.js +4 -0
  30. package/dist/cocos/assets/lib/EcsTimer.js +4 -0
  31. package/dist/cocos/assets/lib/EcsTween.js +4 -0
  32. package/dist/cocos/assets/lib/EcsUtils.js +2 -0
  33. package/dist/cocos/index.js +4 -0
  34. package/{index.ts → index.d.ts} +14 -33
  35. package/package.json +27 -7
  36. package/assets/common/component/MoveComponent.ts +0 -292
  37. package/assets/common/component/MoveComponent.ts.meta +0 -9
  38. package/assets/common/component/NodeComponent.ts +0 -315
  39. package/assets/common/component/NodeComponent.ts.meta +0 -9
  40. package/assets/common/component.meta +0 -12
  41. package/assets/common/system/MoveSystem.ts +0 -108
  42. package/assets/common/system/MoveSystem.ts.meta +0 -9
  43. package/assets/common/system.meta +0 -12
  44. package/assets/common.meta +0 -12
  45. package/assets/ecs/EcsComponent.ts +0 -244
  46. package/assets/ecs/EcsComponent.ts.meta +0 -9
  47. package/assets/ecs/EcsDirty.ts.meta +0 -9
  48. package/assets/ecs/EcsEntity.ts +0 -430
  49. package/assets/ecs/EcsEntity.ts.meta +0 -9
  50. package/assets/ecs/EcsSingleton.ts +0 -6
  51. package/assets/ecs/EcsSingleton.ts.meta +0 -9
  52. package/assets/ecs/EcsSystem.ts +0 -191
  53. package/assets/ecs/EcsSystem.ts.meta +0 -9
  54. package/assets/ecs.meta +0 -12
  55. package/assets/ecs.ts +0 -339
  56. package/assets/ecs.ts.meta +0 -9
  57. package/assets/lib/EcsCache.ts +0 -43
  58. package/assets/lib/EcsCache.ts.meta +0 -9
  59. package/assets/lib/EcsFilter.ts +0 -210
  60. package/assets/lib/EcsFilter.ts.meta +0 -9
  61. package/assets/lib/EcsManager.ts +0 -502
  62. package/assets/lib/EcsManager.ts.meta +0 -9
  63. package/assets/lib/EcsObject.ts.meta +0 -9
  64. package/assets/lib/EcsTimer.ts +0 -239
  65. package/assets/lib/EcsTimer.ts.meta +0 -9
  66. package/assets/lib/EcsTween.ts +0 -486
  67. package/assets/lib/EcsTween.ts.meta +0 -9
  68. package/assets/lib/EcsUtils.ts +0 -352
  69. package/assets/lib/EcsUtils.ts.meta +0 -9
  70. package/assets/lib.meta +0 -12
  71. package/assets.meta +0 -9
  72. package/index.ts.meta +0 -9
  73. package/package.json.meta +0 -11
  74. /package/{.cj-ecs.md → README.md} +0 -0
@@ -1,430 +0,0 @@
1
- import { error, Node } from 'cc';
2
- import { DEV } from 'cc/env';
3
- import { ECS } from '../ecs';
4
- import { componentCache } from '../lib/EcsCache';
5
- import { classManager, flagManager } from '../lib/EcsManager';
6
- import { EcsBaseComponent, EcsBaseEntity, IComponent, IComponentName, IECS, IEntity, ITypeofComponent } from '../lib/EcsObject';
7
- import { ArrayMap } from '../lib/EcsUtils';
8
- import { EcsComponent } from './EcsComponent';
9
-
10
- export class EcsEntity extends EcsBaseEntity implements IEntity {
11
- /**位运算 */
12
- private flag: number[] = new Array(flagManager.bits).fill(0);
13
-
14
- private instNames: string[] = [];
15
-
16
- /**组件的名字 => 组件数组 */
17
- private instNameToComps: ArrayMap<IComponentName, IComponent> = new ArrayMap();
18
-
19
- /**组件父类的名字 => 组件数组 */
20
- private superNameToComps: ArrayMap<IComponentName, IComponent> = new ArrayMap();
21
-
22
- private _isValid = false;
23
- /**是否有效 */
24
- public get isValid() {
25
- return this._isValid;
26
- }
27
- private set isValid(value) {
28
- this._isValid = value;
29
- }
30
-
31
- private _enabled = true;
32
- /**标记是否生效 */
33
- public get enabled() {
34
- return this._enabled;
35
- }
36
- public set enabled(value) {
37
- if (this._enabled === value) return;
38
- this._enabled = value;
39
- if (value) {
40
- this.onEnable();
41
- } else {
42
- this.onDisable();
43
- }
44
- // 更新组件状态
45
- this.instNameToComps.forEach((comps) => {
46
- for (let index = 0; index < comps.length; index++) {
47
- EcsComponent.updateEnable(comps[index] as EcsComponent);
48
- }
49
- });
50
- }
51
-
52
- /**指定ecs */
53
- private _ecs: ECS | null = null;
54
- /**获取对应的ecs */
55
- protected get ecs() {
56
- return this._ecs as IECS;
57
- }
58
-
59
- /**节点 */
60
- private _node: Node | null = null;
61
- public get node() {
62
- return this._node;
63
- }
64
- public set node(value: Node | null) {
65
- this._node = value;
66
- }
67
-
68
- /**标记是否已经销毁 */
69
- private _isDestroyed = true;
70
-
71
- /**
72
- * 内部初始化函数
73
- */
74
- protected innerInit(ecs: IECS, node: Node | null = null) {
75
- this._ecs = ecs as ECS;
76
- this._node = node;
77
- this._isValid = true;
78
- this._enabled = true;
79
- this._isDestroyed = false;
80
- this.onAdd();
81
- this._enabled && this.onEnable();
82
- }
83
-
84
- /**
85
- * 添加组件(内部调用)
86
- */
87
- protected innerAddComponent(com: EcsComponent) {
88
- // 组件类名字
89
- const componentName = com.ecsName;
90
-
91
- // 添加父类名字到uuid的转换
92
- classManager.eachSuperName(componentName, (superName) => {
93
- this.superNameToComps.add(superName, com);
94
- });
95
-
96
- // 添加名字到uuid的转换
97
- const len = this.instNameToComps.add(componentName, com);
98
-
99
- if (len === 1) {
100
- // 记录组件实例的名字
101
- this.instNames.push(componentName);
102
- // 更新标记位
103
- flagManager.addFlag(this.flag, flagManager.getAllByName(componentName));
104
- }
105
-
106
- EcsComponent.onAdd(com, this);
107
- }
108
-
109
- /**
110
- * 移除组件(内部调用)
111
- */
112
- protected innerRemoveComponent(com: EcsComponent) {
113
- // 组件类名字
114
- const componentName = com.ecsName;
115
-
116
- // 删除父类名字到uuid的转换
117
- classManager.eachSuperName(componentName, (superName) => {
118
- this.superNameToComps.sub(superName, com);
119
- });
120
-
121
- // 删除名字到uuid的转换
122
- const del = this.instNameToComps.subDel(componentName, com);
123
-
124
- if (del) {
125
- const index = this.instNames.indexOf(componentName);
126
- this.instNames.splice(index, 1);
127
- // 更新标记位
128
- flagManager.getAllByNames(this.instNames, this.flag);
129
- }
130
-
131
- EcsComponent.onRemove(com);
132
- }
133
-
134
- /**
135
- * 根据组件名字获取对应的组件数组(先查inst再查询super)
136
- */
137
- private getCompsByName(componentName: string): readonly IComponent<IEntity>[] | null {
138
- const instComps = this.instNameToComps.get(componentName);
139
- if (instComps && instComps.length) {
140
- return instComps;
141
- }
142
-
143
- const superComps = this.superNameToComps.get(componentName);
144
- if (superComps && superComps.length) {
145
- return superComps;
146
- }
147
-
148
- return null;
149
- }
150
-
151
- /**
152
- * 根据组件名字获取对应的组件数组(先查inst再查询super)
153
- */
154
- private getCompsByName2(componentName: string) {
155
- const out: IComponent[] = [];
156
- const instComps = this.instNameToComps.get(componentName);
157
- if (instComps && instComps.length) {
158
- Array.prototype.push.apply(out, instComps);
159
- }
160
-
161
- const superComps = this.superNameToComps.get(componentName);
162
- if (superComps && superComps.length) {
163
- Array.prototype.push.apply(out, superComps);
164
- }
165
-
166
- return out;
167
- }
168
-
169
- /**
170
- * 移除当前所有组件
171
- */
172
- private clear() {
173
- const keys = this.instNames;
174
-
175
- for (let index = keys.length - 1; index >= 0; index--) {
176
- const comps = this.instNameToComps.get(keys[index]);
177
- if (!comps) continue;// 如果在某个组件的onRemove中主动移除其它组件,这个会是null
178
- for (let index = comps.length - 1; index >= 0; index--) {
179
- this.removeComponent(comps[index]);
180
- }
181
- }
182
-
183
- this.flag.fill(0);
184
- this.instNames.length = 0;
185
- this.instNameToComps.clear();
186
- this.superNameToComps.clear();
187
- }
188
-
189
- /**
190
- * 销毁
191
- */
192
- public destroy() {
193
- if (this._isDestroyed) return false;
194
- this._isDestroyed = true;
195
-
196
- this.enabled && this.onDisable();
197
- this.onRemove();
198
- this.clear();
199
- this._node = null;
200
- this._isValid = false;
201
- this._ecs!.removeEntity(this);
202
- this._ecs = null;
203
- return true;
204
- }
205
-
206
- /**添加*/
207
- protected onAdd() { }
208
- /**生效*/
209
- protected onEnable() { }
210
- /**失效*/
211
- protected onDisable() { }
212
- /**移除*/
213
- protected onRemove() { }
214
-
215
- /**
216
- * 检查是否包含全部
217
- */
218
- checkFlagAll(flag: number[]) {
219
- return flagManager.checkFlagAll(this.flag, flag);
220
-
221
- }
222
- /**
223
- * 检查是否包含任一
224
- */
225
- checkFlagAny(flag: number[]) {
226
- return flagManager.checkFlagAny(this.flag, flag);
227
- }
228
-
229
- /**
230
- * 检查是否仅包含全部
231
- */
232
- checkFlagOnly(flag: number[]) {
233
- const componentNames = this.instNames;
234
- for (let index = 0; index < componentNames.length; index++) {
235
- const componentName = componentNames[index];
236
- const comFlag = flagManager.getAllByName(componentName);
237
- const success = flagManager.checkFlagAny(comFlag, flag);
238
- if (!success) {
239
- return false;
240
- }
241
- }
242
- return true;
243
- }
244
-
245
- /**
246
- * 根据组件名字检查是否存在启用且有效的组件
247
- */
248
- hasEnabledComponentName(componentName: string): boolean {
249
- const comps = this.getCompsByName(componentName);
250
- if (!comps || comps.length === 0) return false;
251
- for (let index = 0; index < comps.length; index++) {
252
- const comp = comps[index];
253
- if (comp.enabledInHierarchy && comp.isStrictValid) return true;
254
- }
255
- return false;
256
- }
257
-
258
- /**
259
- * 添加相应类型的组件
260
- * @see 同add
261
- * @param param 类型
262
- */
263
- addComponent<T extends ITypeofComponent>(param: T | IComponent): InstanceType<T> | null {
264
- return this.add(param);
265
- }
266
-
267
- /**
268
- * 添加相应类型的组件
269
- * @param param 类型
270
- */
271
- add<T extends ITypeofComponent>(param: T | IComponent): InstanceType<T> | null {
272
- if (DEV && param.ecsName === EcsComponent.ecsName) {
273
- console.error('请使用ecsclass修饰Component', param);
274
- return null;
275
- }
276
-
277
- // 是实例
278
- if (param instanceof EcsBaseComponent) {
279
- if (param.entity === this) {
280
- error(`不允许重复添加同一个组件实例\nuuid: ${param.uuid}\n组件名: ${param.ecsName}`);
281
- return null;
282
- } else if (param.entity) {
283
- error(`不允许添加其它实体的组件实例\nuuid: ${param.uuid}\n组件名: ${param.ecsName}`);
284
- return null;
285
- } else if (!param.allowMultiple) {
286
- const comps = this.instNameToComps.get(param.ecsName);
287
- if (comps && comps.length) {
288
- error(`此类型的组件不允许重复添加\nuuid: ${param.uuid}\n组件名: ${param.ecsName}`);
289
- return null;
290
- }
291
- }
292
- this._ecs!.addComponent(this, param);
293
- return param as InstanceType<T>;
294
- } else {
295
- // 如果不允许重复添加
296
- if (!param.allowMultiple) {
297
- const comps = this.instNameToComps.get(param.ecsName);
298
- if (comps && comps.length) {
299
- error(`此类型的组件不允许重复添加\n组件名: ${param.ecsName}`);
300
- return null;
301
- }
302
- }
303
- const com = componentCache.get(param.ecsName) || new param();
304
- this._ecs!.addComponent(this, com);
305
- return com as InstanceType<T>;
306
- }
307
- }
308
-
309
- /**
310
- * 移除相应类型的第一个组件
311
- * @see 同remove
312
- * @param param 类型或实例(当组件开启allowMultiple后,需要传入实例)
313
- */
314
- removeComponent(param: ITypeofComponent | IComponent): boolean {
315
- return this.remove(param);
316
- }
317
-
318
- /**
319
- * 移除相应类型的第一个组件
320
- * @param param 类型或实例(当组件开启allowMultiple后,需要传入实例)
321
- */
322
- remove(param: ITypeofComponent | IComponent): boolean {
323
- if (!param) return false;
324
-
325
- if (param instanceof EcsBaseComponent) {
326
- if (param.entity !== this) {
327
- error(`移除的组件不属于当前实体\n组件名: ${param.ecsName}`);
328
- return false;
329
- }
330
- this._ecs!.removeComponent(param);
331
- if (param.allowRecycling) {
332
- EcsBaseComponent.updateUUID(param);
333
- componentCache.put(param.ecsName, param);
334
- }
335
- return true;
336
- } else {
337
- if (param.allowMultiple) {
338
- error(`开启allowMultiple的组件只能通过实例进行移除\n组件名: ${param.ecsName}`);
339
- return false;
340
- }
341
- const com = this.get(param);
342
- if (!com) return false;
343
- this._ecs!.removeComponent(com);
344
- if (param.allowRecycling) {
345
- EcsBaseComponent.updateUUID(com);
346
- componentCache.put(param.ecsName, com);
347
- }
348
- return true;
349
- }
350
- }
351
-
352
- /**
353
- * 移除相应组件的所有组件
354
- * @see 同removeAll
355
- * @param Com 类型
356
- */
357
- removeComponents(Com: ITypeofComponent): boolean {
358
- return this.removeAll(Com);
359
- }
360
-
361
- /**
362
- * 移除相应组件的所有组件
363
- * @param Com 类型
364
- */
365
- removeAll(Com: ITypeofComponent): boolean {
366
- const comps = this.getAll(Com);
367
- if (!comps.length) return false;
368
-
369
- let success = true;
370
- for (let index = 0; index < comps.length; index++) {
371
- success = this.remove(comps[index]) && success;
372
- }
373
- return success;
374
- }
375
-
376
- /**
377
- * 有没有相应类型的组件
378
- * @see 同has
379
- * @param Com 类型
380
- */
381
- hasComponent(Com: ITypeofComponent): boolean {
382
- return this.has(Com);
383
- }
384
-
385
- /**
386
- * 有没有相应类型的组件
387
- * @param Com 类型
388
- */
389
- has(Com: ITypeofComponent): boolean {
390
- const comps = this.getCompsByName(Com.ecsName);
391
- if (!comps || comps.length === 0) return false;
392
- return true;
393
- }
394
-
395
- /**
396
- * 获取相应类型的组件
397
- * @see 同get
398
- * @param Com 类型
399
- */
400
- getComponent<T extends ITypeofComponent>(Com: T): InstanceType<T> | null {
401
- return this.get(Com);
402
- }
403
-
404
- /**
405
- * 获取相应类型的组件
406
- * @param Com 类型
407
- */
408
- get<T extends ITypeofComponent>(Com: T): InstanceType<T> | null {
409
- const comps = this.getCompsByName(Com.ecsName);
410
- if (!comps || comps.length === 0) return null;
411
- return comps[0] as InstanceType<T>;
412
- }
413
-
414
- /**
415
- * 获取相应类型的组件
416
- * @see 同getAll
417
- * @param Com 类型
418
- */
419
- getComponents<T extends ITypeofComponent>(Com: T): InstanceType<T>[] {
420
- return this.getAll(Com);
421
- }
422
-
423
- /**
424
- * 获取相应类型的组件
425
- * @param Com 类型
426
- */
427
- getAll<T extends ITypeofComponent>(Com: T): InstanceType<T>[] {
428
- return this.getCompsByName2(Com.ecsName) as InstanceType<T>[];
429
- }
430
- }
@@ -1,9 +0,0 @@
1
- {
2
- "ver": "4.0.24",
3
- "importer": "typescript",
4
- "imported": true,
5
- "uuid": "3cb5697e-06df-4707-b30d-e99115ba656b",
6
- "files": [],
7
- "subMetas": {},
8
- "userData": {}
9
- }
@@ -1,6 +0,0 @@
1
- import { ecsclass } from '../lib/EcsManager';
2
- import { EcsBaseSingleton, ISingleton } from '../lib/EcsObject';
3
-
4
- @ecsclass('EcsSingleton')
5
- export class EcsSingleton extends EcsBaseSingleton implements ISingleton {
6
- }
@@ -1,9 +0,0 @@
1
- {
2
- "ver": "4.0.24",
3
- "importer": "typescript",
4
- "imported": true,
5
- "uuid": "b51e6cff-6340-4e4a-84ea-29f3795eed70",
6
- "files": [],
7
- "subMetas": {},
8
- "userData": {}
9
- }
@@ -1,191 +0,0 @@
1
- import { Node } from 'cc';
2
- import { Filter } from '../lib/EcsFilter';
3
- import { EcsBaseSystem, IComponent, IECS, IEntity, IEntityUUID, IFilter, ISystem, ITypeofComponent, ITypeofEntity, ITypeofSingleton } from '../lib/EcsObject';
4
- import { TimerManager } from '../lib/EcsTimer';
5
- import { TweenManager } from '../lib/EcsTween';
6
- import type { IEcsObservedQuery } from './EcsDirty';
7
-
8
- export class EcsSystem extends EcsBaseSystem implements ISystem {
9
- static matchEntity(system: EcsSystem, entity: IEntity) {
10
- system.matchEntity(entity);
11
- }
12
-
13
- private _ecs: IECS | null = null;
14
- /**获取对应的ecs */
15
- protected get ecs() {
16
- return this._ecs as IECS;
17
- }
18
- /** observed runtime 查询入口。未安装 cj-ecs-observed 时为 null,系统需要自行兜底。 */
19
- protected get observed(): IEcsObservedQuery | null {
20
- return this.ecs.getObservedQuery();
21
- }
22
- private set ecs(v) {
23
- this._ecs = v;
24
- }
25
-
26
- /**
27
- * Timer管理器
28
- * @example
29
- * // 创建timer
30
- * const timer = new Timer(() => { consoe.log('timer'); });
31
- * timer.delay(1);
32
- * timer.repeat(10);
33
- * // 添加管理
34
- * this.timer.add(timer);
35
- * // 迭代一次
36
- * this.timer.step(dt);
37
- */
38
- protected timer = new TimerManager();
39
-
40
- /**
41
- * Tween管理器
42
- * @example
43
- * // 创建tween
44
- * const tween = new Tween(ECS组件实例);
45
- * tween.to(1, ...);
46
- * tween.delay(1);
47
- * tween.by(1, ...);
48
- * // 添加管理
49
- * this.tween.add(tween);
50
- * // 迭代一次
51
- * this.tween.step(dt);
52
- */
53
- protected tween = new TweenManager();
54
-
55
- /**
56
- * 指定ecs
57
- */
58
- constructor(ecs: IECS) {
59
- super();
60
- this.ecs = ecs;
61
- }
62
-
63
- /**添加 */
64
- protected onAdd() { }
65
-
66
- /**移除 */
67
- protected onRemove() { }
68
-
69
- /**查询实体 */
70
- protected query<T extends IEntity>(filter: IFilter): T[];
71
- protected query<T extends IComponent>(filter: IFilter, Component: { new(): T }): T[];
72
- protected query<T>(filter: IFilter, Component?: any): T[] {
73
- if (this.matcher === filter) {
74
- if (Component) {
75
- return Array.from(this.matchEntities.values()).map((entity) => entity.getComponent(Component as ITypeofComponent)) as T[];
76
- }
77
- return Array.from(this.matchEntities.values()) as T[];
78
- }
79
- return this.ecs.query(filter, Component as ITypeofComponent) as T[];
80
- }
81
-
82
- /**查询实体 */
83
- protected find<T extends IEntity>(filter: IFilter): T | null;
84
- protected find<T extends IComponent>(filter: IFilter, Component: { new(): T }): T | null;
85
- protected find<T>(filter: IFilter, Component?: any): T | null {
86
- if (this.matcher === filter) {
87
- if (Component) {
88
- return this.matchEntities.values().next().value?.getComponent(Component as ITypeofComponent) as T || null;
89
- }
90
- return this.matchEntities.values().next().value as T || null;
91
- }
92
- return this.ecs.find(filter, Component as ITypeofComponent) as T || null;
93
- }
94
-
95
- /**是否存在实体 */
96
- protected exist(filter: IFilter): boolean {
97
- if (this.matcher === filter) {
98
- return this.matchEntities.size > 0;
99
- }
100
- return this.ecs.exist(filter);
101
- }
102
-
103
- /**遍历当前系统 matcher 命中的实体,避免 query(this.matcher) 每帧分配数组 */
104
- protected forEachMatchedEntity<T extends IEntity = IEntity>(handle: (entity: T) => void) {
105
- this.matchEntities.forEach((entity) => {
106
- handle(entity as T);
107
- });
108
- }
109
-
110
- /**当前系统 matcher 命中的实体数量 */
111
- protected get matchedEntityCount() {
112
- return this.matchEntities.size;
113
- }
114
-
115
- /**创建实体 */
116
- protected createEntity<T extends ITypeofEntity>(Entity: T, options?: Node | { node?: Node }) {
117
- return this.ecs.createEntity(Entity, options);
118
- }
119
-
120
- /**查询实体 */
121
- protected findByUuid(uuid: IEntityUUID) {
122
- return this.ecs.findByUuid(uuid);
123
- }
124
-
125
- /**是否存在实体 */
126
- protected existByUuid(uuid: IEntityUUID) {
127
- return this.ecs.existByUuid(uuid);
128
- }
129
-
130
- /**获取单例组件 */
131
- protected getSingleton<T extends ITypeofSingleton>(param: T) {
132
- return this.ecs.getSingleton(param);
133
- }
134
-
135
- /**
136
- * 过滤实体
137
- * - 配置后才能响应onEntityEnter、onEntityLeave
138
- * - 如果query、find、exist方法中的值与matcher中的值相同,则会直接从缓存中获取实体
139
- */
140
- protected matcher: IFilter | null = null;
141
-
142
- /**实体进入系统,会在execute流程最开始调用*/
143
- protected onEntityEnter(entity: IEntity) { entity; }
144
-
145
- /**实体离开系统,会在execute流程最开始调用*/
146
- protected onEntityLeave(entity: IEntity) { entity; }
147
-
148
- private matchEntities: Map<IEntityUUID, IEntity> = new Map();
149
- private matchEntity(entity: IEntity) {
150
- if (this.matcher) {
151
- const isInMatch = this.matchEntities.has(entity.uuid);
152
- const isMatch = Filter.check(entity, this.matcher as Filter);
153
- if (isMatch) {
154
- if (!isInMatch) {
155
- this.matchEntities.set(entity.uuid, entity);
156
- this.onEntityEnter(entity);
157
- }
158
- } else {
159
- if (isInMatch) {
160
- this.matchEntities.delete(entity.uuid);
161
- this.onEntityLeave(entity);
162
- }
163
- }
164
- } else if (this.matchEntities.size > 0) {
165
- this.matchEntities.forEach((entity) => {
166
- this.onEntityLeave(entity);
167
- });
168
- this.matchEntities.clear();
169
- }
170
- }
171
-
172
- // 由ecs.execute驱动
173
- protected execute(dt?: number, ...args: any[]) { dt; args; }
174
- protected beforeExecute(dt?: number, ...args: any[]) { dt; args; }
175
- protected afterExecute(dt?: number, ...args: any[]) { dt; args; }
176
-
177
- // 由ecs.update驱动
178
- protected update(dt?: number, ...args: any[]) { dt; args; }
179
- protected beforeUpdate(dt?: number, ...args: any[]) { dt; args; }
180
- protected afterUpdate(dt?: number, ...args: any[]) { dt; args; }
181
-
182
- protected log(...args: any[]) {
183
- console.log(`[${this.ecsName}] [log]`, ...args);
184
- }
185
- protected warn(...args: any[]) {
186
- console.warn(`[${this.ecsName}] [warn]`, ...args);
187
- }
188
- protected error(...args: any[]) {
189
- console.error(`[${this.ecsName}] [error]`, ...args);
190
- }
191
- }
@@ -1,9 +0,0 @@
1
- {
2
- "ver": "4.0.24",
3
- "importer": "typescript",
4
- "imported": true,
5
- "uuid": "0937d0e1-37d9-408b-940f-7e46779f90c7",
6
- "files": [],
7
- "subMetas": {},
8
- "userData": {}
9
- }
package/assets/ecs.meta DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "ver": "1.2.0",
3
- "importer": "directory",
4
- "imported": true,
5
- "uuid": "b27fed30-3c52-4d46-92cf-072148f885fe",
6
- "files": [],
7
- "subMetas": {},
8
- "userData": {
9
- "compressionType": {},
10
- "isRemoteBundle": {}
11
- }
12
- }