From 5fd4a83224f1f4c58fb345192340a5180930e8bb Mon Sep 17 00:00:00 2001 From: dgflash Date: Tue, 19 Aug 2025 16:59:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96LayerUIElement=E3=80=81Module?= =?UTF-8?q?Util=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/gui/layer/LayerUI.ts | 1 + assets/core/gui/layer/LayerUIElement.ts | 15 +++++-------- assets/module/common/ModuleUtil.ts | 28 ++++++------------------- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/assets/core/gui/layer/LayerUI.ts b/assets/core/gui/layer/LayerUI.ts index 432a1c0..87f3dde 100644 --- a/assets/core/gui/layer/LayerUI.ts +++ b/assets/core/gui/layer/LayerUI.ts @@ -81,6 +81,7 @@ export class LayerUI extends Node { // 窗口事件委托 const dc = vp.node.addComponent(LayerUIElement); dc.params = vp; + //@ts-ignore dc.onCloseWindow = this.onCloseWindow.bind(this); // 显示界面 diff --git a/assets/core/gui/layer/LayerUIElement.ts b/assets/core/gui/layer/LayerUIElement.ts index 142a5d4..8c8c6b5 100644 --- a/assets/core/gui/layer/LayerUIElement.ts +++ b/assets/core/gui/layer/LayerUIElement.ts @@ -22,7 +22,7 @@ export class LayerUIElement extends Component { /** 关闭窗口之前 */ onCloseWindowBefore: Function = null!; /** 界面关闭回调 - 包括关闭动画播放完(辅助框架内存业务流程使用) */ - onCloseWindow: Function = null!; + private onCloseWindow: Function = null!; /** 窗口添加 */ add(): Promise { @@ -56,25 +56,20 @@ export class LayerUIElement extends Component { // 通知外部对象窗口组件上移除之前的事件(关闭窗口前的关闭动画处理) if (typeof this.params.callbacks.onBeforeRemove === "function") { - this.params.callbacks.onBeforeRemove( - this.node, - this.onBeforeRemoveNext.bind(this, isDestroy)); + this.params.callbacks.onBeforeRemove(this.node, this.onBeforeRemoveNext.bind(this, isDestroy)); } else { - this.removed(this.params, isDestroy); + this.onBeforeRemoveNext(isDestroy); } } else { - this.removed(this.params, isDestroy); + this.onBeforeRemoveNext(isDestroy); } } /** 窗口关闭前动画处理完后的回调方法,主要用于释放资源 */ private onBeforeRemoveNext(isDestroy?: boolean) { - if (this.onCloseWindowBefore) { - this.onCloseWindowBefore(); - this.onCloseWindowBefore = null!; - } + this.onCloseWindowBefore && this.onCloseWindowBefore(); this.removed(this.params, isDestroy); } diff --git a/assets/module/common/ModuleUtil.ts b/assets/module/common/ModuleUtil.ts index 5682187..d97867f 100644 --- a/assets/module/common/ModuleUtil.ts +++ b/assets/module/common/ModuleUtil.ts @@ -1,8 +1,8 @@ import { Node, __private } from "cc"; import { oops } from "../../core/Oops"; import { resLoader } from "../../core/common/loader/ResLoader"; -import { LayerUIElement, UICallbacks } from "../../core/gui/layer/LayerUIElement"; import { Uiid } from "../../core/gui/layer/LayerEnum"; +import { LayerUIElement, UICallbacks } from "../../core/gui/layer/LayerUIElement"; import { UIConfig } from "../../core/gui/layer/UIConfig"; import { ViewUtil } from "../../core/utils/ViewUtil"; import { ecs } from "../../libs/ecs/ECS"; @@ -98,28 +98,12 @@ export class ModuleUtil { const comp = node.getComponent(LayerUIElement); if (comp) { - if (comp.params.callbacks.onBeforeRemove) { - comp.onCloseWindowBefore = () => { - ent.remove(ctor, isDestroy); - if (onRemoved) onRemoved(); - }; - } - else if (comp.params.callbacks.onRemoved) { - comp.onCloseWindow = () => { - ent.remove(ctor, isDestroy); - if (onRemoved) onRemoved(); - }; - } - else { - ent.remove(ctor, isDestroy); + comp.onCloseWindowBefore = () => { + // 移除ECS显示组件 + if (isDestroy) ent.remove(ctor, isDestroy); if (onRemoved) onRemoved(); - } + }; + oops.gui.remove(uiId, isDestroy); } - else { - ent.remove(ctor, isDestroy); - if (onRemoved) onRemoved(); - } - - oops.gui.remove(uiId, isDestroy); } } \ No newline at end of file