77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
using System.Threading;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace AlicizaX.UI.Runtime
|
|
{
|
|
[DisallowMultipleComponent]
|
|
public sealed class UIAnimationFlowTransition : MonoBehaviour, 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))
|
|
{
|
|
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;
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
private void OnValidate()
|
|
{
|
|
if (animationFlow == null)
|
|
{
|
|
animationFlow = GetComponent<AnimationFlow.Runtime.AnimationFlow>();
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|