using Sirenix.OdinInspector; using System; using System.Collections.Generic; using Cysharp.Threading.Tasks; using Sirenix.Utilities; using UnityEngine; using UnityEngine.UI; namespace AlicizaX.UI.Runtime { [DisallowMultipleComponent] [HideMonoScript] public abstract class UIHolderObjectBase : UnityEngine.MonoBehaviour { #if UNITY_EDITOR && ALICIZAX_UI_ANIMATION_SUPPORT private void SetAnimtionFlow() { // 编辑器模式下自动重置状态 AnimationFlow = GetComponent(); } #endif #if UNITY_EDITOR && ALICIZAX_UI_EXTENSION_SUPPORT private void SetHotKeyButtons() { hotButtons = transform.GetComponentsInChildren(true); } #endif #if ALICIZAX_UI_EXTENSION_SUPPORT #if UNITY_EDITOR [InlineButton("SetHotKeyButtons")] #endif [SerializeField] [HideLabel] internal UXButton[] hotButtons; internal void BindHotKeys() { for (int i = 0; i < hotButtons.Length; i++) { hotButtons[i].BindHotKey(); } } internal void UnBindHotKeys() { for (int i = 0; i < hotButtons.Length; i++) { hotButtons[i].UnBindHotKey(); } } #endif #if ALICIZAX_UI_ANIMATION_SUPPORT public async UniTask PlayAnimtion(string name) { 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 UNITY_EDITOR && ALICIZAX_UI_ANIMATION_SUPPORT [InlineButton("SetAnimtionFlow")] #endif #if ALICIZAX_UI_ANIMATION_SUPPORT [SerializeField] [HideLabel] private AnimationFlow.Runtime.AnimationFlow AnimationFlow; #endif private void Awake() { _target = gameObject; } private bool IsAlive = true; public static implicit operator bool(UIHolderObjectBase exists) { // 先检查Unity对象是否被销毁 if (exists == null) return false; // 再返回自定义的生命状态 return exists.IsAlive; } private void OnDestroy() { IsAlive = false; } } }