AnimationData.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. Skill0,
  16. Skill1,
  17. Skill2,
  18. Skill3,
  19. Skill4,
  20. Skill5,
  21. Skill6,
  22. SkillMax
  23. }
  24. [Serializable]
  25. public struct AniInfo
  26. {
  27. public AnimationType Type;
  28. public ClipTransition Clip;
  29. }
  30. public AniInfo[] AnimationClips = new AniInfo[1];
  31. public ClipTransition GetClip(AnimationType type)
  32. {
  33. foreach (var clip in AnimationClips)
  34. {
  35. if (clip.Type == type)
  36. {
  37. return clip.Clip;
  38. }
  39. }
  40. return null;
  41. }
  42. public void PlayAnimation(AnimationType type, Action endcb = null)
  43. {
  44. var clip = GetClip(type);
  45. if (clip != null)
  46. {
  47. var state = Animancer.Play(clip);
  48. state.Time = 0;
  49. if(endcb != null)
  50. {
  51. state.Events.OnEnd = endcb;
  52. }
  53. }
  54. else
  55. {
  56. Log.Error($"Not exist clip({type}) @{gameObject.name}");
  57. }
  58. }
  59. }
  60. }