import { Vec3, Node, MeshRenderer, RenderableComponent, Color } from "cc"; import { ViewUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/ViewUtil"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { SubwayModelComp } from "./model/SubwayModelComp"; import { SubwayViewComp } from "./view/SubwayViewComp"; import { SubwayEnum } from "./model/SubwayEnum"; import { SubwayGenPuppetComp, SubwayGenPuppetSystem } from "./bll/SubwayGenPuppet"; /** * 地铁实体 * 1、生成地铁关卡初始数据 */ @ecs.register('Subway') export class Subway extends ecs.Entity { SubwayModel!: SubwayModelComp; SubwayView!: SubwayViewComp; protected init() { // 添加关卡数据组件 this.addComponents(SubwayModelComp); } destroy(): void { // 如果该组件对象是由ecs系统外部创建的,则不可回收,需要用户自己手动进行回收。 this.remove(SubwayViewComp); super.destroy(); } /** 加载地铁显示对象(cc.Component在创建后,添加到ECS框架中,使实体上任何一个ECS组件都可以通过 ECS API 获取到视图层对象 */ load(parent: Node, pos: Vec3 = Vec3.ZERO,type=SubwayEnum.RIGHT) { const node = ViewUtil.createPrefabNode(this.getSubwayModelPath(type)); const mv = node.getComponent(SubwayViewComp)!; this.add(mv); node.parent = parent; node.setPosition(pos); this.add(SubwayGenPuppetComp) } getSubwayModelPath(type:SubwayEnum){ switch (type) { case SubwayEnum.LEFT: return 'game/prefab/box_l' case SubwayEnum.RIGHT: return 'game/prefab/box_r' default: return 'game/prefab/box_l' } } } export class EcsSubwaySystem extends ecs.System { constructor() { super(); this.add(new SubwayGenPuppetSystem()); } }