AlicizaX/Client/Packages/com.alicizax.unity.ui/Runtime/UI/UIBase/UIHolderObjectBase.cs

81 lines
1.9 KiB
C#
Raw Normal View History

2025-04-28 19:45:45 +08:00
using Sirenix.OdinInspector;
2025-03-04 18:40:14 +08:00
using System;
2025-04-28 19:45:45 +08:00
using Cysharp.Threading.Tasks;
2025-03-04 18:40:14 +08:00
using UnityEngine;
using UnityEngine.UI;
2025-01-24 16:21:00 +08:00
2025-03-04 18:40:14 +08:00
namespace AlicizaX.UI.Runtime
2025-01-24 16:21:00 +08:00
{
2025-03-04 18:40:14 +08:00
[DisallowMultipleComponent]
[HideMonoScript]
public abstract class UIHolderObjectBase : UnityEngine.MonoBehaviour
2025-01-24 16:21:00 +08:00
{
2025-04-28 19:45:45 +08:00
#if UNITY_EDITOR
private void SetAnimtionFlow()
{
// 编辑器模式下自动重置状态
AnimationFlow = GetComponent<AnimationFlow.Runtime.AnimationFlow>();
}
#endif
public async UniTask PlayAnimtion(string name)
{
await AnimationFlow.PlayAsync(name);
}
2025-01-24 16:21:00 +08:00
2025-03-04 18:40:14 +08:00
private GameObject _target;
2025-01-24 16:21:00 +08:00
2025-03-04 18:40:14 +08:00
/// <summary>
/// UI实例资源对象。
/// </summary>
public GameObject Target => _target ??= gameObject;
2025-01-24 16:21:00 +08:00
2025-03-04 18:40:14 +08:00
private RectTransform _rectTransform;
/// <summary>
/// 窗口矩阵位置组件。
/// </summary>
public RectTransform RectTransform => _rectTransform ??= _target.transform as RectTransform;
/// <summary>
/// 可见性
/// </summary>
2025-04-28 19:45:45 +08:00
public bool Visible
{
get => Target.activeSelf;
internal set { _target.SetActive(value); }
}
#if UNITY_EDITOR
[InlineButton("SetAnimtionFlow")]
#endif
[SerializeField]
2025-07-11 21:00:00 +08:00
[HideLabel]
2025-04-28 19:45:45 +08:00
private AnimationFlow.Runtime.AnimationFlow AnimationFlow;
2025-03-04 18:40:14 +08:00
private void Awake()
{
_target = gameObject;
}
2025-04-28 19:45:45 +08:00
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;
}
2025-01-24 16:21:00 +08:00
}
}