using System; using System.Buffers; using System.Collections.Generic; using AlicizaX.Runtime; using UnityEngine; namespace AlicizaX.UI.Runtime { public abstract partial class UIBase:IEventListenerProxy { protected System.Object[] userDatas; public System.Object UserData { get { if (userDatas != null && userDatas.Length >= 1) { return userDatas[0]; } else { return null; } } } public System.Object[] UserDatas => userDatas; /// /// UI实例资源对象。 /// public GameObject gameObject { protected set; get; } /// /// 窗口位置组件。 /// public Transform transform => gameObject.transform; /// /// 窗口矩阵位置组件。 /// public RectTransform rectTransform => gameObject.transform as RectTransform; public virtual string AssetName { get; } public virtual bool Visible { set; get; } internal bool IsLoaded; protected virtual void OnBindUIComponents() { } protected virtual void OnInitlize() { } protected virtual void OnDestroy() { } protected virtual void OnRegisterEvent() { } protected virtual void OnOpen() { } protected virtual void OnClose() { } #region UIElement /// /// UI元素节点。 /// protected UIBindComponent UIBindComponent; /// /// 检测UI元素节点。 /// protected void InitBindComponent() { UIBindComponent = rectTransform.GetComponent(); } /// /// 获取子节点脚本。 /// /// 子节点类型。 /// 子节点索引。 /// 子节点脚本实例。 protected T FChild(int index) where T : Component { return UIBindComponent.FindChild(index); } #endregion #region UIEvent public EventListenerProxy EventListener { get { if (_uiEventProxy == null) { _uiEventProxy = ReferencePool.Acquire(); } return _uiEventProxy; } } internal EventListenerProxy _uiEventProxy; protected void RemoveAllUIEvent() { if (_uiEventProxy != null) { _uiEventProxy.Clear(); } } protected void DisposeEvent() { if (_uiEventProxy != null) { ReferencePool.Release(_uiEventProxy); } } #endregion } }