From e274dbb0624a480d779e7d1e01518b2d7e64e274 Mon Sep 17 00:00:00 2001 From: dgflash Date: Fri, 10 Apr 2026 22:13:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20loading=20=E8=BD=AC?= =?UTF-8?q?=E5=9C=88=E5=9B=A0=20clearTimeout=20=E6=8F=90=E5=89=8D=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E7=9A=84=20bug=EF=BC=8C=E5=AE=8C=E5=96=84=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E4=B8=8E=E5=85=B3=E9=97=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/core/gui/layer/LayerNotify.ts | 53 +++++++++++++++++++++------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/assets/core/gui/layer/LayerNotify.ts b/assets/core/gui/layer/LayerNotify.ts index ed77afb..be7f5d8 100644 --- a/assets/core/gui/layer/LayerNotify.ts +++ b/assets/core/gui/layer/LayerNotify.ts @@ -20,6 +20,10 @@ export class LayerNotify extends Node { private notify: Node = null!; /** 自定义弹出提示内容资源 */ private notifyItem: Node = null!; + /** 标记是否正在打开等待提示中 */ + private waitOpening: boolean = false; + /** 标记是否在打开过程中被请求关闭 */ + private waitShouldClose: boolean = false; constructor(name: string) { super(name); @@ -31,28 +35,53 @@ export class LayerNotify extends Node { /** 打开等待提示 */ async waitOpen() { - if (this.wait == null) { - // 兼容编辑器预览模式 - if (EDITOR) { - this.wait = await ViewUtil.createPrefabNodeAsync(PromptResType.Wait); - } - else { - this.wait = ViewUtil.createPrefabNode(PromptResType.Wait); - } - } + this.waitOpening = true; - if (this.wait.parent == null) { - this.wait.parent = this; - this.black.enabled = true; + try { + if (this.wait == null) { + // 兼容编辑器预览模式 + if (EDITOR) { + this.wait = await ViewUtil.createPrefabNodeAsync(PromptResType.Wait); + } + else { + this.wait = ViewUtil.createPrefabNode(PromptResType.Wait); + } + } + + // 异步操作完成后,检查是否已被请求关闭 + if (this.waitShouldClose) { + this.waitShouldClose = false; + this.doWaitClose(); + return; + } + + if (this.wait.parent == null) { + this.wait.parent = this; + this.black.enabled = true; + } + } finally { + this.waitOpening = false; } } /** 关闭等待提示 */ waitClose() { + // 如果正在打开中,标记应该关闭,等打开完成后再关闭 + if (this.waitOpening) { + this.waitShouldClose = true; + return; + } + + this.doWaitClose(); + } + + /** 实际执行关闭等待提示 */ + private doWaitClose() { if (this.wait && this.wait.parent) { this.wait.parent = null; this.black.enabled = false; } + this.waitShouldClose = false; } /**