2025-09-05 19:46:30 +08:00
|
|
|
|
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<AnimationFlow.Runtime.AnimationFlow>();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR && ALICIZAX_UI_EXTENSION_SUPPORT
|
2025-09-05 20:44:40 +08:00
|
|
|
|
[Button("SetHotKeyButtons")]
|
2025-09-05 19:46:30 +08:00
|
|
|
|
private void SetHotKeyButtons()
|
|
|
|
|
{
|
|
|
|
|
hotButtons = transform.GetComponentsInChildren<UXButton>(true);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ALICIZAX_UI_EXTENSION_SUPPORT
|
|
|
|
|
[SerializeField] [HideLabel] [ReadOnly]
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// UI实例资源对象。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public GameObject Target => _target ??= gameObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private RectTransform _rectTransform;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 窗口矩阵位置组件。
|
|
|
|
|
/// </summary>
|
|
|
|
|
public RectTransform RectTransform => _rectTransform ??= _target.transform as RectTransform;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 可见性
|
|
|
|
|
/// </summary>
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|