diff --git a/assets/module/common/CCEntity.ts b/assets/module/common/CCEntity.ts index e83e6bc..9849688 100644 --- a/assets/module/common/CCEntity.ts +++ b/assets/module/common/CCEntity.ts @@ -10,7 +10,6 @@ import { CompType } from "../../libs/ecs/ECSModel"; import { CCBusiness } from "./CCBusiness"; import { CCView } from "./CCView"; import { CCViewVM } from "./CCViewVM"; -import { GameComponent } from "./GameComponent"; export type ECSCtor = __private.__types_globals__Constructor | __private.__types_globals__AbstractedConstructor; export type ECSView = CCViewVM | CCView; @@ -75,25 +74,12 @@ export abstract class CCEntity extends ecs.Entity { * @param path 显示资源地址 * @param bundleName 资源包名称 */ - addPrefab(ctor: ECSCtor, parent: Node | GameComponent, path: string, bundleName: string = resLoader.defaultBundleName): Promise { - return new Promise(async (resolve, reject) => { - let node: Node = null!; - // 跟随父节点施放自动释放当前资源 - if (parent instanceof GameComponent) { - node = await parent.createPrefabNode(path, bundleName); - const comp = node.getComponent(ctor)!; - this.add(comp); - node.parent = parent.node; - } - // 手动内存管理 - else { - node = await ViewUtil.createPrefabNodeAsync(path, bundleName); - const comp = node.getComponent(ctor)!; - this.add(comp); - node.parent = parent; - } - resolve(node); - }); + addPrefab(ctor: ECSCtor, parent: Node, path: string, bundleName: string = resLoader.defaultBundleName): Node { + const node = ViewUtil.createPrefabNode(path, bundleName); + const comp = node.getComponent(ctor)!; + this.add(comp); + node.parent = parent; + return node; } /** @@ -190,7 +176,6 @@ export abstract class CCEntity extends ecs.Entity { * @returns 业务逻辑组件实例 */ getBusiness>(cls: any): T { - if (this.businesss == null) return null!; return this.businesss.get(cls) as T; } @@ -199,10 +184,8 @@ export abstract class CCEntity extends ecs.Entity { * @param cls 业务逻辑组件类 */ removeBusiness(cls: any) { - if (this.businesss) { - let business = this.businesss.get(cls); - if (business) this.businesss.delete(cls); - } + let business = this.businesss.get(cls); + if (business) this.businesss.delete(cls); } //#endregion