Grid.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Vec3, Node } from "cc";
  2. import { ViewUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/ViewUtil";
  3. import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
  4. import { GridModelComp } from "./model/GridModelComp";
  5. import { GridViewComp } from "./view/GridViewComp";
  6. /**
  7. * 棋盘格实体
  8. */
  9. @ecs.register('Grid')
  10. export class Grid extends ecs.Entity {
  11. GridModel!: GridModelComp;
  12. protected init() {
  13. // 添加关卡数据组件
  14. this.addComponents<ecs.Comp>(GridModelComp);
  15. }
  16. destroy(): void {
  17. // 如果该组件对象是由ecs系统外部创建的,则不可回收,需要用户自己手动进行回收。
  18. this.remove(GridViewComp);
  19. super.destroy();
  20. }
  21. /** 加载关卡显示对象(cc.Component在创建后,添加到ECS框架中,使实体上任何一个ECS组件都可以通过 ECS API 获取到视图层对象 */
  22. load(parent: Node, pos: Vec3 = Vec3.ZERO) {
  23. var node = ViewUtil.createPrefabNode("game/prefab/grid");
  24. var mv = node.getComponent(GridViewComp)!;
  25. this.add(mv);
  26. node.parent = parent;
  27. node.setPosition(pos);
  28. }
  29. }
  30. export class EcsGridSystem extends ecs.System {
  31. constructor() {
  32. super();
  33. }
  34. }