From ba94a6966e2e8c43de1415a91c5dfec5d892fa8c Mon Sep 17 00:00:00 2001 From: donggang <> Date: Fri, 29 Mar 2024 16:55:51 +0800 Subject: [PATCH] . --- assets/module/common/ModuleUtil.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/assets/module/common/ModuleUtil.ts b/assets/module/common/ModuleUtil.ts index eb31024..92fe059 100644 --- a/assets/module/common/ModuleUtil.ts +++ b/assets/module/common/ModuleUtil.ts @@ -1,6 +1,7 @@ import { Node, __private } from "cc"; import { oops } from "../../core/Oops"; import { UICallbacks } from "../../core/gui/layer/Defines"; +import { ViewUtil } from "../../core/utils/ViewUtil"; import { ecs } from "../../libs/ecs/ECS"; import { CompType } from "../../libs/ecs/ECSModel"; import { CCComp } from "./CCComp"; @@ -14,7 +15,7 @@ export class ModuleUtil { * @param uiId 界面资源编号 * @param uiArgs 界面参数 */ - public static addView( + public static addViewUi( ent: ecs.Entity, ctor: __private._types_globals__Constructor | __private._types_globals__AbstractedConstructor, uiId: number, @@ -36,7 +37,7 @@ export class ModuleUtil { * @param uiArgs 界面参数 * @returns 界面节点 */ - public static addViewAsync( + public static addViewUiAsync( ent: ecs.Entity, ctor: __private._types_globals__Constructor | __private._types_globals__AbstractedConstructor, uiId: number, @@ -60,8 +61,26 @@ export class ModuleUtil { * @param uiId 界面资源编号 * @param isDestroy 是否释放界面缓存 */ - public static removeView(ent: ecs.Entity, ctor: CompType, uiId: number, isDestroy?: boolean) { + public static removeViewUi(ent: ecs.Entity, ctor: CompType, uiId: number, isDestroy?: boolean) { ent.remove(ctor); oops.gui.remove(uiId, isDestroy); } + + /** + * 添加界面组件 + * @param ent 模块实体 + * @param ctor 界面逻辑组件 + * @param parent 显示对象父级 + * @param url 显示资源地址 + */ + public static addView( + ent: ecs.Entity, + ctor: __private._types_globals__Constructor | __private._types_globals__AbstractedConstructor, + parent: Node, + url: string) { + var node = ViewUtil.createPrefabNode(url); + var comp = node.getComponent(ctor)!; + ent.add(comp); + node.parent = parent; + } } \ No newline at end of file