using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.Reflection; public class TestAnimation : MonoBehaviour { public AnimationPlayer[] apList; public Text text; int index = 0; void Start() { apList[0].completeCallback = (res) => { if (res.index == 3) { text.text = "正在播放的动画:" + this.animationClips[index].name + "x" + res.completeCount; if (res.completeCount == 10) { index = 0; } else { return; } } else index++; StartCoroutine(PlayEach()); }; StartCoroutine(PlayEach()); } IEnumerator PlayEach() { yield return new WaitForSecondsRealtime(0.3f); text.text = "正在播放的动画:" + this.animationClips[index].name; foreach (var ap in apList) { ap.play(index, index == 3 ? WrapMode.Loop : WrapMode.Once); } } Animation animationMain; AnimationClip[] _animationClips; AnimationClip[] animationClips { get { if (this.animationMain == null) { this.animationMain = this.apList[0].GetComponent(); } if (this._animationClips == null) { this._animationClips = new AnimationClip[this.animationMain.GetClipCount()]; int i = 0; foreach (AnimationState AS in this.animationMain) { this._animationClips[i] = this.animationMain.GetClip(AS.name); i++; } } return this._animationClips; } } }