Subway.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Vec3, Node, MeshRenderer, RenderableComponent, Color } 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 { SubwayModelComp } from "./model/SubwayModelComp";
  5. import { SubwayViewComp } from "./view/SubwayViewComp";
  6. import { SubwayEnum } from "./model/SubwayEnum";
  7. import { SubwayGenPuppetComp, SubwayGenPuppetSystem } from "./bll/SubwayGenPuppet";
  8. /**
  9. * 地铁实体
  10. * 1、生成地铁关卡初始数据
  11. */
  12. @ecs.register('Subway')
  13. export class Subway extends ecs.Entity {
  14. SubwayModel!: SubwayModelComp;
  15. SubwayView!: SubwayViewComp;
  16. protected init() {
  17. // 添加关卡数据组件
  18. this.addComponents<ecs.Comp>(SubwayModelComp);
  19. }
  20. destroy(): void {
  21. // 如果该组件对象是由ecs系统外部创建的,则不可回收,需要用户自己手动进行回收。
  22. this.remove(SubwayViewComp);
  23. super.destroy();
  24. }
  25. /** 加载地铁显示对象(cc.Component在创建后,添加到ECS框架中,使实体上任何一个ECS组件都可以通过 ECS API 获取到视图层对象 */
  26. load(parent: Node, pos: Vec3 = Vec3.ZERO,type=SubwayEnum.RIGHT) {
  27. const node = ViewUtil.createPrefabNode(this.getSubwayModelPath(type));
  28. const mv = node.getComponent(SubwayViewComp)!;
  29. this.add(mv);
  30. node.parent = parent;
  31. node.setPosition(pos);
  32. this.add(SubwayGenPuppetComp)
  33. }
  34. getSubwayModelPath(type:SubwayEnum){
  35. switch (type) {
  36. case SubwayEnum.LEFT:
  37. return 'game/prefab/box_l'
  38. case SubwayEnum.RIGHT:
  39. return 'game/prefab/box_r'
  40. default:
  41. return 'game/prefab/box_l'
  42. }
  43. }
  44. }
  45. export class EcsSubwaySystem extends ecs.System {
  46. constructor() {
  47. super();
  48. this.add(new SubwayGenPuppetSystem());
  49. }
  50. }