优化默认的AnimationFlowTransition

This commit is contained in:
陈思海 2026-03-20 14:19:37 +08:00
parent e7c6b174fe
commit 4c86d6bbda

View File

@ -1,3 +1,4 @@
#if ALICIZAX_UI_ANIMATION_SUPPORT
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
@ -5,42 +6,24 @@ using UnityEngine;
namespace AlicizaX.UI.Runtime
{
[DisallowMultipleComponent]
public sealed class UIAnimationFlowTransition : MonoBehaviour, IUITransitionPlayer
public sealed class UIAnimationFlowTransition : AnimationFlow.Runtime.AnimationFlow, IUITransitionPlayer
{
public int Priority => 0;
#if ALICIZAX_UI_ANIMATION_SUPPORT
[SerializeField] private AnimationFlow.Runtime.AnimationFlow animationFlow;
[SerializeField] private string openClip = "Open";
[SerializeField] private string closeClip = "Close";
#endif
public UniTask PlayOpenAsync(CancellationToken cancellationToken = default)
{
#if ALICIZAX_UI_ANIMATION_SUPPORT
return PlayAsync(openClip, cancellationToken);
#else
return UniTask.CompletedTask;
#endif
}
public UniTask PlayCloseAsync(CancellationToken cancellationToken = default)
{
#if ALICIZAX_UI_ANIMATION_SUPPORT
return PlayAsync(closeClip, cancellationToken);
#else
return UniTask.CompletedTask;
#endif
}
public void Stop()
{
#if ALICIZAX_UI_ANIMATION_SUPPORT
ResolveAnimationFlow()?.Stop();
#endif
}
#if ALICIZAX_UI_ANIMATION_SUPPORT
private UniTask PlayAsync(string clipName, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested || string.IsNullOrWhiteSpace(clipName))
@ -48,29 +31,10 @@ namespace AlicizaX.UI.Runtime
return UniTask.CompletedTask;
}
AnimationFlow.Runtime.AnimationFlow flow = ResolveAnimationFlow();
return flow == null ? UniTask.CompletedTask : flow.PlayAsync(clipName);
}
private AnimationFlow.Runtime.AnimationFlow ResolveAnimationFlow()
{
if (animationFlow == null)
{
animationFlow = GetComponent<AnimationFlow.Runtime.AnimationFlow>();
}
return animationFlow;
return PlayAsync(clipName);
}
#if UNITY_EDITOR
private void OnValidate()
{
if (animationFlow == null)
{
animationFlow = GetComponent<AnimationFlow.Runtime.AnimationFlow>();
}
}
#endif
#endif
}
}
#endif