com.alicizax.unity.framework/Runtime/UI/UIBase/UIHolderObjectBase.cs

84 lines
2.0 KiB
C#
Raw Normal View History

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
{
2025-09-25 11:11:19 +08:00
public Action OnWindowInitEvent;
public Action OnWindowShowEvent;
public Action OnWindowClosedEvent;
public Action OnWindowDestroyEvent;
2025-09-05 19:46:30 +08:00
#if ALICIZAX_UI_ANIMATION_SUPPORT
public async UniTask PlayAnimtion(string name)
{
2025-09-25 19:28:20 +08:00
if (AnimationFlow == null)
{
AnimationFlow = transform.GetComponent<AnimationFlow.Runtime.AnimationFlow>();
}
2025-09-05 19:46:30 +08:00
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 ALICIZAX_UI_ANIMATION_SUPPORT
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;
}
}
}