From 66efca25f8e5648aca387d5832e536f9f4fbf882 Mon Sep 17 00:00:00 2001 From: donggang <> Date: Thu, 22 Feb 2024 17:58:54 +0800 Subject: [PATCH] =?UTF-8?q?GUI=E6=A1=86=E6=9E=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=8F=AF=E8=8E=B7=E5=8F=96=E5=88=B0=E5=B7=B2?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=95=8C=E9=9D=A2=E8=8A=82=E7=82=B9=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=9A=84API=EF=BC=8C=E6=96=B9=E4=BE=BF=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E9=9C=80=E6=B1=82=E5=8F=AF=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=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/LayerManager.ts | 33 ++++++++++++++++++++++++++- assets/core/gui/layer/LayerUI.ts | 9 ++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/assets/core/gui/layer/LayerManager.ts b/assets/core/gui/layer/LayerManager.ts index e5c5ff6..492aac1 100644 --- a/assets/core/gui/layer/LayerManager.ts +++ b/assets/core/gui/layer/LayerManager.ts @@ -187,7 +187,7 @@ export class LayerManager { has(uiId: number): boolean { var config = this.configs[uiId]; if (config == null) { - warn(`编号为【${uiId}】的界面失败,配置信息不存在`); + warn(`编号为【${uiId}】的界面配置不存在,配置信息不存在`); return false; } @@ -209,6 +209,37 @@ export class LayerManager { return result; } + /** + * 缓存中是否存在指定标识的窗口 + * @param uiId 窗口唯一标识 + * @example + * oops.gui.has(UIID.Loading); + */ + get(uiId: number): Node { + var config = this.configs[uiId]; + if (config == null) { + warn(`编号为【${uiId}】的界面配置不存在,配置信息不存在`); + return null!; + } + + var result: Node = null!; + switch (config.layer) { + case LayerType.UI: + result = this.ui.getByPrefabPath(config.prefab); + break; + case LayerType.PopUp: + result = this.popup.getByPrefabPath(config.prefab); + break; + case LayerType.Dialog: + result = this.dialog.getByPrefabPath(config.prefab); + break; + case LayerType.System: + result = this.system.getByPrefabPath(config.prefab); + break; + } + return result; + } + /** * 移除指定标识的窗口 * @param uiId 窗口唯一标识 diff --git a/assets/core/gui/layer/LayerUI.ts b/assets/core/gui/layer/LayerUI.ts index 49a5551..401aaf2 100644 --- a/assets/core/gui/layer/LayerUI.ts +++ b/assets/core/gui/layer/LayerUI.ts @@ -177,6 +177,15 @@ export class LayerUI extends Node { } } + /** + * 根据预制路径获取已打开界面的节点对象 + * @param prefabPath 预制路径 + */ + getByPrefabPath(prefabPath: string): Node { + var uuid = this.getUuid(prefabPath); + return this.getByUuid(uuid); + } + /** * 根据唯一标识获取节点,如果节点不存在或者还在队列中,则返回null * @param uuid 唯一标识