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 唯一标识