Grid.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. GridView!: GridViewComp;
  13. protected init() {
  14. // 添加关卡数据组件
  15. this.addComponents<ecs.Comp>(GridModelComp);
  16. }
  17. destroy(): void {
  18. // 如果该组件对象是由ecs系统外部创建的,则不可回收,需要用户自己手动进行回收。
  19. this.remove(GridViewComp);
  20. super.destroy();
  21. }
  22. /** 加载关卡显示对象(cc.Component在创建后,添加到ECS框架中,使实体上任何一个ECS组件都可以通过 ECS API 获取到视图层对象 */
  23. load(parent: Node, pos: Vec3 = Vec3.ZERO) {
  24. var node = ViewUtil.createPrefabNode("game/prefab/grid");
  25. var mv = node.getComponent(GridViewComp)!;
  26. this.add(mv);
  27. node.parent = parent;
  28. node.setPosition(pos);
  29. }
  30. }
  31. export class EcsGridSystem extends ecs.System {
  32. constructor() {
  33. super();
  34. }
  35. }