mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-07 01:01:09 +08:00
CCEntity.addPrefab方法修改为返回节点
This commit is contained in:
@@ -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<T extends ecs.Comp> = __private.__types_globals__Constructor<T> | __private.__types_globals__AbstractedConstructor<T>;
|
||||
export type ECSView = CCViewVM<CCEntity> | CCView<CCEntity>;
|
||||
@@ -75,25 +74,12 @@ export abstract class CCEntity extends ecs.Entity {
|
||||
* @param path 显示资源地址
|
||||
* @param bundleName 资源包名称
|
||||
*/
|
||||
addPrefab<T extends ECSView>(ctor: ECSCtor<T>, parent: Node | GameComponent, path: string, bundleName: string = resLoader.defaultBundleName): Promise<Node> {
|
||||
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<T extends ECSView>(ctor: ECSCtor<T>, 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<T extends CCBusiness<CCEntity>>(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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user