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 childWidgets = new List(); internal List withOpenWidget = new List(); #region UIWidget /// /// 创建UIWidget通过游戏物体。 /// 因为资源实例已经存在父物体所以不需要异步。 /// /// 游戏物体。 /// 是否可见。 /// UIWidget。 /// UIWidget实例。 protected T CreateWidget(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; } /// /// 创建UIWidget通过资源定位地址。 /// /// 资源父节点。 /// 资源定位地址。 /// 是否可见。 /// UIWidget。 /// UIWidget实例。 protected T CreateWidgetByPath(Transform parentTrans, string assetLocation, bool visible = true) where T : UIWidget, new() { GameObject goInst = SysModuleCenter.GetModule().LoadGameObject(assetLocation, parent: parentTrans); return CreateWidget(goInst, visible); } /// /// 创建UIWidget通过资源定位地址。 /// /// 资源父节点。 /// 资源定位地址。 /// 是否可见。 /// UIWidget。 /// UIWidget实例。 protected async UniTask CreateWidgetByPathAsync(Transform parentTrans, string assetLocation, bool visible = true) where T : UIWidget, new() { GameObject goInst = await SysModuleCenter.GetModule().LoadGameObjectAsync(assetLocation, parentTrans, gameObject.GetCancellationTokenOnDestroy()); return CreateWidget(goInst, visible); } /// /// 通过UI类型来创建widget。 /// /// 资源父节点。 /// 是否可见。 /// UIWidget。 /// UIWidget实例。 protected T CreateWidgetByType(Transform parentTrans, bool visible = true) where T : UIWidget, new() { return CreateWidgetByPath(parentTrans, typeof(T).Name, visible); } /// /// 通过UI类型来创建widget。 /// /// 资源父节点。 /// 是否可见。 /// UIWidget。 /// UIWidget实例。 protected async UniTask CreateWidgetByTypeAsync(Transform parentTrans, bool visible = true) where T : UIWidget, new() { return await CreateWidgetByPathAsync(parentTrans, typeof(T).Name, visible); } #endregion #region UIWidget更新相关 internal void RemoveWidget(UIWidget widget) { childWidgets.Remove(widget); } #endregion } }