Skip to content

Commit 21b63ac

Browse files
committed
feat(UI组件): 添加根据类型获取已加载UI的方法
添加两个新方法GetLoadedAndShowing和GetLoaded,用于根据类型获取已加载的UI实例,提高UI管理的灵活性
1 parent 22f4e4c commit 21b63ac

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Runtime/UIComponent.Get.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// Official Documentation: https://gameframex.doc.alianblank.com/
3030
// ==========================================================================================
3131

32+
using System;
3233
using System.Collections.Generic;
3334
using GameFrameX.Runtime;
3435

@@ -115,6 +116,25 @@ public List<T> GetLoadedList<T>() where T : class, IUIForm
115116
return results;
116117
}
117118

119+
/// <summary>
120+
/// 获取已加载且正在显示的UI。
121+
/// </summary>
122+
/// <param name="type">UI的具体类型。</param>
123+
/// <returns>返回已加载且正在显示的UI实例,如果未找到则返回null。</returns>
124+
public IUIForm GetLoadedAndShowing(Type type)
125+
{
126+
var fullName = type.FullName;
127+
var uiForms = m_UIManager.GetAllLoadedUIForms();
128+
foreach (var uiForm in uiForms)
129+
{
130+
if (uiForm.FullName == fullName && uiForm.Visible && uiForm.Available)
131+
{
132+
return uiForm;
133+
}
134+
}
135+
136+
return null;
137+
}
118138

119139
/// <summary>
120140
/// 获取已加载且正在显示的UI。
@@ -155,6 +175,26 @@ public bool HasLoadedAndShowing(string uiFormAssetName)
155175
return false;
156176
}
157177

178+
/// <summary>
179+
/// 根据界面逻辑类型获取界面。只要找到任意的一个即返回
180+
/// </summary>
181+
/// <param name="type">逻辑界面类型</param>
182+
/// <returns>返回已加载的UI实例,如果未找到则返回null。</returns>
183+
public IUIForm GetLoaded(Type type)
184+
{
185+
var fullName = type.FullName;
186+
var uiForms = m_UIManager.GetAllLoadedUIForms();
187+
foreach (var uiForm in uiForms)
188+
{
189+
if (uiForm.FullName == fullName)
190+
{
191+
return uiForm;
192+
}
193+
}
194+
195+
return null;
196+
}
197+
158198
/// <summary>
159199
/// 根据界面逻辑类型获取界面。只要找到任意的一个即返回
160200
/// </summary>

0 commit comments

Comments
 (0)