TestAnimation.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System.Reflection;
  6. public class TestAnimation : MonoBehaviour
  7. {
  8. public AnimationPlayer[] apList;
  9. public Text text;
  10. int index = 0;
  11. void Start()
  12. {
  13. apList[0].completeCallback = (res) =>
  14. {
  15. if (res.index == 3)
  16. {
  17. text.text = "正在播放的动画:" + this.animationClips[index].name + "x" + res.completeCount;
  18. if (res.completeCount == 10)
  19. {
  20. index = 0;
  21. }
  22. else {
  23. return;
  24. }
  25. }
  26. else index++;
  27. StartCoroutine(PlayEach());
  28. };
  29. StartCoroutine(PlayEach());
  30. }
  31. IEnumerator PlayEach()
  32. {
  33. yield return new WaitForSecondsRealtime(0.3f);
  34. text.text = "正在播放的动画:" + this.animationClips[index].name;
  35. foreach (var ap in apList) {
  36. ap.play(index, index == 3 ? WrapMode.Loop : WrapMode.Once);
  37. }
  38. }
  39. Animation animationMain;
  40. AnimationClip[] _animationClips;
  41. AnimationClip[] animationClips
  42. {
  43. get
  44. {
  45. if (this.animationMain == null)
  46. {
  47. this.animationMain = this.apList[0].GetComponent<Animation>();
  48. }
  49. if (this._animationClips == null)
  50. {
  51. this._animationClips = new AnimationClip[this.animationMain.GetClipCount()];
  52. int i = 0;
  53. foreach (AnimationState AS in this.animationMain)
  54. {
  55. this._animationClips[i] = this.animationMain.GetClip(AS.name);
  56. i++;
  57. }
  58. }
  59. return this._animationClips;
  60. }
  61. }
  62. }