using System; using UnityEngine; using UnityEngine.UI; namespace AlicizaX.UI.Runtime { public abstract class UIWidget : UIBase { private UIBase _parent; internal UIBase Parent => _parent; internal void BindUIHolder(GameObject obj, UIBase parent) { if (_state != UIState.CreatedUI) throw new InvalidOperationException("UI already Created"); var holder = (UIHolderObjectBase)obj.GetComponent(UIHolderType); if (holder == null) { throw new InvalidCastException($"资源{obj.name}上不存在{UIHolderType.FullName}"); } Holder = holder; _parent = parent; _canvas = Holder.transform.GetComponent(); _raycaster = Holder.transform.GetComponent(); Depth = parent.Depth + 5; _state = UIState.Loaded; } public void Open() { InternalOpen(); } public void Close() { InternalClose(); } public void Destroy() { Parent.RemoveWidget(this); } } public abstract class UIWidget : UIWidget where T : UIHolderObjectBase { protected T baseui => (T)Holder; internal override Type UIHolderType => typeof(T); } }