using System; using Cysharp.Threading.Tasks; using UnityEngine; namespace AlicizaX.UI.Runtime { [DisallowMultipleComponent] public abstract class UIHolderObjectBase : UnityEngine.MonoBehaviour { public Action OnWindowInitEvent; public Action OnWindowBeforeShowEvent; public Action OnWindowAfterShowEvent; public Action OnWindowBeforeClosedEvent; public Action OnWindowAfterClosedEvent; public Action OnWindowDestroyEvent; #if ALICIZAX_UI_ANIMATION_SUPPORT public async UniTask PlayAnimtion(string name) { if (AnimationFlow == null) { AnimationFlow = transform.GetComponent(); } await AnimationFlow.PlayAsync(name); } #endif private GameObject _target; /// /// UI实例资源对象。 /// public GameObject Target => _target ??= gameObject; private RectTransform _rectTransform; /// /// 窗口矩阵位置组件。 /// public RectTransform RectTransform => _rectTransform ??= _target.transform as RectTransform; /// /// 可见性 /// public bool Visible { get => Target.activeSelf; internal set { _target.SetActive(value); } } #if ALICIZAX_UI_ANIMATION_SUPPORT private AnimationFlow.Runtime.AnimationFlow AnimationFlow; #endif public virtual void Awake() { _target = gameObject; #if ALICIZAX_UI_ANIMATION_SUPPORT AnimationFlow = GetComponent(); #endif } private bool _isAlive = true; /// /// Checks if this holder is still valid (not destroyed). /// Use this instead of null check for better clarity. /// public bool IsValid() { return this != null && _isAlive; } private void OnDestroy() { _isAlive = false; } } }