GUI框架添加一个可获取到已显示界面节点对象的API,方便特殊需求可自定义逻辑

This commit is contained in:
donggang
2024-02-22 17:58:54 +08:00
parent 0ec61f895c
commit 66efca25f8
2 changed files with 41 additions and 1 deletions

View File

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

View File

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