104 lines
3.9 KiB
C#
104 lines
3.9 KiB
C#
using System.Collections.Generic;
|
|
using AlicizaX.Resource.Runtime;
|
|
using AlicizaX.Runtime;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace AlicizaX.UI.Runtime
|
|
{
|
|
public abstract partial class UIBase
|
|
{
|
|
internal List<UIWidget> childWidgets = new List<UIWidget>();
|
|
internal List<UIWidget> withOpenWidget = new List<UIWidget>();
|
|
|
|
|
|
#region UIWidget
|
|
|
|
/// <summary>
|
|
/// 创建UIWidget通过游戏物体。
|
|
/// <remarks>因为资源实例已经存在父物体所以不需要异步。</remarks>
|
|
/// </summary>
|
|
/// <param name="goRoot">游戏物体。</param>
|
|
/// <param name="visible">是否可见。</param>
|
|
/// <typeparam name="T">UIWidget。</typeparam>
|
|
/// <returns>UIWidget实例。</returns>
|
|
protected T CreateWidget<T>(GameObject goRoot, bool visible = true) where T : UIWidget, new()
|
|
{
|
|
var widget = new T();
|
|
widget.InternalCreate(this, goRoot);
|
|
widget.Visible = visible;
|
|
childWidgets.Add(widget);
|
|
return widget;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建UIWidget通过资源定位地址。
|
|
/// </summary>
|
|
/// <param name="parentTrans">资源父节点。</param>
|
|
/// <param name="assetLocation">资源定位地址。</param>
|
|
/// <param name="visible">是否可见。</param>
|
|
/// <typeparam name="T">UIWidget。</typeparam>
|
|
/// <returns>UIWidget实例。</returns>
|
|
protected T CreateWidgetByPath<T>(Transform parentTrans, string assetLocation, bool visible = true)
|
|
where T : UIWidget, new()
|
|
{
|
|
GameObject goInst = SysModuleCenter.GetModule<IResourceManager>().LoadGameObject(assetLocation, parent: parentTrans);
|
|
return CreateWidget<T>(goInst, visible);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建UIWidget通过资源定位地址。
|
|
/// </summary>
|
|
/// <param name="parentTrans">资源父节点。</param>
|
|
/// <param name="assetLocation">资源定位地址。</param>
|
|
/// <param name="visible">是否可见。</param>
|
|
/// <typeparam name="T">UIWidget。</typeparam>
|
|
/// <returns>UIWidget实例。</returns>
|
|
protected async UniTask<T> CreateWidgetByPathAsync<T>(Transform parentTrans, string assetLocation,
|
|
bool visible = true) where T : UIWidget, new()
|
|
{
|
|
GameObject goInst = await SysModuleCenter.GetModule<IResourceManager>().LoadGameObjectAsync(assetLocation, parentTrans,
|
|
gameObject.GetCancellationTokenOnDestroy());
|
|
return CreateWidget<T>(goInst, visible);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 通过UI类型来创建widget。
|
|
/// </summary>
|
|
/// <param name="parentTrans">资源父节点。</param>
|
|
/// <param name="visible">是否可见。</param>
|
|
/// <typeparam name="T">UIWidget。</typeparam>
|
|
/// <returns>UIWidget实例。</returns>
|
|
protected T CreateWidgetByType<T>(Transform parentTrans, bool visible = true) where T : UIWidget, new()
|
|
{
|
|
return CreateWidgetByPath<T>(parentTrans, typeof(T).Name, visible);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过UI类型来创建widget。
|
|
/// </summary>
|
|
/// <param name="parentTrans">资源父节点。</param>
|
|
/// <param name="visible">是否可见。</param>
|
|
/// <typeparam name="T">UIWidget。</typeparam>
|
|
/// <returns>UIWidget实例。</returns>
|
|
protected async UniTask<T> CreateWidgetByTypeAsync<T>(Transform parentTrans, bool visible = true)
|
|
where T : UIWidget, new()
|
|
{
|
|
return await CreateWidgetByPathAsync<T>(parentTrans, typeof(T).Name, visible);
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region UIWidget更新相关
|
|
|
|
internal void RemoveWidget(UIWidget widget)
|
|
{
|
|
childWidgets.Remove(widget);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|