2025-11-07 20:47:57 +08:00
|
|
|
|
using System;
|
2026-03-17 17:15:31 +08:00
|
|
|
|
using System.Threading;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AlicizaX.UI.Runtime
|
|
|
|
|
|
{
|
|
|
|
|
|
[DisallowMultipleComponent]
|
|
|
|
|
|
public abstract class UIHolderObjectBase : UnityEngine.MonoBehaviour
|
|
|
|
|
|
{
|
2025-09-25 11:11:19 +08:00
|
|
|
|
public Action OnWindowInitEvent;
|
2025-12-17 14:32:03 +08:00
|
|
|
|
public Action OnWindowBeforeShowEvent;
|
|
|
|
|
|
public Action OnWindowAfterShowEvent;
|
|
|
|
|
|
public Action OnWindowBeforeClosedEvent;
|
|
|
|
|
|
public Action OnWindowAfterClosedEvent;
|
2025-09-25 11:11:19 +08:00
|
|
|
|
public Action OnWindowDestroyEvent;
|
|
|
|
|
|
|
2025-09-05 19:46:30 +08:00
|
|
|
|
private GameObject _target;
|
2026-03-17 17:15:31 +08:00
|
|
|
|
private IUITransitionPlayer _transitionPlayer;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
|
|
|
|
|
|
/// <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); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-12-01 16:45:42 +08:00
|
|
|
|
public virtual void Awake()
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
_target = gameObject;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-24 20:44:36 +08:00
|
|
|
|
private bool _isAlive = true;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
|
2025-12-24 20:44:36 +08:00
|
|
|
|
public bool IsValid()
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2025-12-24 20:44:36 +08:00
|
|
|
|
return this != null && _isAlive;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-17 17:15:31 +08:00
|
|
|
|
internal UniTask PlayOpenTransitionAsync(CancellationToken cancellationToken = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
return TryGetTransitionPlayer(out var transitionPlayer)
|
|
|
|
|
|
? transitionPlayer.PlayOpenAsync(cancellationToken)
|
|
|
|
|
|
: UniTask.CompletedTask;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal UniTask PlayCloseTransitionAsync(CancellationToken cancellationToken = default)
|
|
|
|
|
|
{
|
|
|
|
|
|
return TryGetTransitionPlayer(out var transitionPlayer)
|
|
|
|
|
|
? transitionPlayer.PlayCloseAsync(cancellationToken)
|
|
|
|
|
|
: UniTask.CompletedTask;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal void StopTransition()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (TryGetTransitionPlayer(out var transitionPlayer))
|
|
|
|
|
|
{
|
|
|
|
|
|
transitionPlayer.Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool TryGetTransitionPlayer(out IUITransitionPlayer transitionPlayer)
|
|
|
|
|
|
{
|
2026-03-17 17:48:43 +08:00
|
|
|
|
if (_transitionPlayer is Behaviour cachedBehaviour && cachedBehaviour.isActiveAndEnabled)
|
2026-03-17 17:15:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
transitionPlayer = _transitionPlayer;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-17 17:48:43 +08:00
|
|
|
|
_transitionPlayer = null;
|
|
|
|
|
|
int bestPriority = int.MinValue;
|
2026-03-17 17:15:31 +08:00
|
|
|
|
MonoBehaviour[] behaviours = GetComponents<MonoBehaviour>();
|
|
|
|
|
|
for (int i = 0; i < behaviours.Length; i++)
|
|
|
|
|
|
{
|
2026-03-17 17:48:43 +08:00
|
|
|
|
MonoBehaviour behaviour = behaviours[i];
|
|
|
|
|
|
if (!behaviour.isActiveAndEnabled || behaviour is not IUITransitionPlayer player)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (player.Priority > bestPriority)
|
2026-03-17 17:15:31 +08:00
|
|
|
|
{
|
|
|
|
|
|
_transitionPlayer = player;
|
2026-03-17 17:48:43 +08:00
|
|
|
|
bestPriority = player.Priority;
|
2026-03-17 17:15:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-17 17:48:43 +08:00
|
|
|
|
transitionPlayer = _transitionPlayer;
|
|
|
|
|
|
return transitionPlayer != null;
|
2026-03-17 17:15:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-05 19:46:30 +08:00
|
|
|
|
private void OnDestroy()
|
|
|
|
|
|
{
|
2025-12-24 20:44:36 +08:00
|
|
|
|
_isAlive = false;
|
2026-03-17 17:15:31 +08:00
|
|
|
|
_transitionPlayer = null;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|