AnimationData.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. private void Awake ()
  35. {
  36. aniEndcb = null;
  37. foreach (var clip in AnimationClips)
  38. {
  39. if (clip.Type >= AnimationType.Skill0 && clip.Type < AnimationType.SkillMax)
  40. {
  41. clip.Clip.Events.OnEnd = SkillEndCB;
  42. }
  43. }
  44. }
  45. protected void SkillEndCB()
  46. {
  47. if(notifyState != null /*&& notifyState.IsPlaying*/)
  48. {
  49. notifyState.Events = null;
  50. notifyState = null;
  51. }
  52. Action tocall = aniEndcb;
  53. aniEndcb = null;
  54. tocall?.Invoke();
  55. }
  56. public ClipTransition GetClip(AnimationType type)
  57. {
  58. foreach (var clip in AnimationClips)
  59. {
  60. if (clip.Type == type)
  61. {
  62. return clip.Clip;
  63. }
  64. }
  65. return null;
  66. }
  67. public void PlayAnimation(AnimationType type, Action endcb = null)
  68. {
  69. //Log.Debug($"{this.gameObject.name} toplay ani:{type}");
  70. aniEndcb = endcb;
  71. var clip = GetClip(type);
  72. if (clip != null)
  73. {
  74. notifyState = Animancer.Play(clip, 0.1f, FadeMode.FromStart);
  75. }
  76. else
  77. {
  78. Log.Error($"Not exist clip({type}) @{gameObject.name}");
  79. }
  80. }
  81. }
  82. }