59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Animation 扩展方法
|
|
/// </summary>
|
|
public static class AnimationExtensions
|
|
{
|
|
/// <summary>
|
|
/// 播放单个动画并等待完成
|
|
/// </summary>
|
|
public static async Task PlayAndWaitAsync(this Animation animation, string clipName)
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(clipName) || animation == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var clip = animation[clipName];
|
|
if (clip == null)
|
|
{
|
|
Debug.LogWarning($"Animation clip '{clipName}' not found on {animation.gameObject.name}");
|
|
return;
|
|
}
|
|
|
|
animation.Play(clipName);
|
|
await Awaiters.Seconds(clip.length);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 播放多个动画并等待全部完成 (类似 Task.WhenAll)
|
|
/// </summary>
|
|
public static async Task PlayAllAndWaitAsync(this Animation animation, params string[] clipNames)
|
|
{
|
|
if (animation == null || clipNames == null || clipNames.Length == 0)
|
|
return;
|
|
|
|
foreach (var name in clipNames)
|
|
{
|
|
await animation.PlayAndWaitAsync(name);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 播放多个动画并等待全部完成 (类似 Task.WhenAll)
|
|
/// </summary>
|
|
public static async Task PlayAllAndWaitAsync(this Animation animation, IEnumerable<string> clipNames)
|
|
{
|
|
if (animation == null || clipNames == null)
|
|
return;
|
|
foreach (var name in clipNames)
|
|
{
|
|
await animation.PlayAndWaitAsync(name);
|
|
}
|
|
}
|
|
} |