using System.Collections.Generic; using System.Threading.Tasks; using DG.Tweening; using UnityEngine; /// /// Animation 扩展方法 /// public static class AnimationExtensions { /// /// 播放单个动画并等待完成 /// 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); } /// /// 播放多个动画并等待全部完成 (类似 Task.WhenAll) /// 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); } } /// /// 播放多个动画并等待全部完成 (类似 Task.WhenAll) /// public static async Task PlayAllAndWaitAsync(this Animation animation, IEnumerable clipNames) { if (animation == null || clipNames == null) return; foreach (var name in clipNames) { await animation.PlayAndWaitAsync(name); } } }