AnimationData.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using ET;
  2. using Animancer;
  3. using UnityEngine;
  4. using System;
  5. namespace Mono
  6. {
  7. public class AnimationData : MonoBehaviour
  8. {
  9. public AnimancerComponent Animancer;
  10. public enum AnimationType
  11. {
  12. Idle,
  13. Run,
  14. Dead,
  15. Damage,
  16. Skill0,
  17. Skill1,
  18. Skill2,
  19. Skill3,
  20. Skill4,
  21. Skill5,
  22. Skill6,
  23. SkillMax
  24. }
  25. [Serializable]
  26. public struct AniInfo
  27. {
  28. public AnimationType Type;
  29. public ClipTransition Clip;
  30. }
  31. public AniInfo[] AnimationClips = new AniInfo[1];
  32. private Action aniEndcb;
  33. private AnimancerState notifyState;
  34. public bool IsPauseStatus() { return !Animancer.Playable.IsGraphPlaying; }
  35. private void Awake ()
  36. {
  37. aniEndcb = null;
  38. foreach (var clip in AnimationClips)
  39. {
  40. if (clip.Type >= AnimationType.Skill0 && clip.Type < AnimationType.SkillMax)
  41. {
  42. clip.Clip.Events.OnEnd = SkillEndCB;
  43. }
  44. }
  45. }
  46. protected void SkillEndCB()
  47. {
  48. if(notifyState != null /*&& notifyState.IsPlaying*/)
  49. {
  50. notifyState.Events = null;
  51. notifyState = null;
  52. }
  53. Action tocall = aniEndcb;
  54. aniEndcb = null;
  55. tocall?.Invoke();
  56. }
  57. public ClipTransition GetClip(AnimationType type)
  58. {
  59. foreach (var clip in AnimationClips)
  60. {
  61. if (clip.Type == type)
  62. {
  63. return clip.Clip;
  64. }
  65. }
  66. return null;
  67. }
  68. public void PlayAnimation(AnimationType type, Action endcb = null)
  69. {
  70. if (!Animancer.Playable.IsGraphPlaying)
  71. {
  72. //Log.Error( $"play ani({type}) @ froze status" );
  73. return;
  74. }
  75. //Log.Debug($"{this.gameObject.name} toplay ani:{type}");
  76. aniEndcb = endcb;
  77. var clip = GetClip(type);
  78. if (clip != null)
  79. {
  80. notifyState = Animancer.Play(clip, 0.1f, FadeMode.FromStart);
  81. }
  82. else
  83. {
  84. Log.Error($"Not exist clip({type}) @{gameObject.name}");
  85. }
  86. }
  87. public void Pause()
  88. {
  89. Animancer.Playable.PauseGraph();
  90. }
  91. public void Resume()
  92. {
  93. Animancer.Playable.UnpauseGraph();
  94. }
  95. }
  96. }