AnimationData.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. public ClipTransition GetClip(AnimationType type)
  33. {
  34. foreach (var clip in AnimationClips)
  35. {
  36. if (clip.Type == type)
  37. {
  38. return clip.Clip;
  39. }
  40. }
  41. return null;
  42. }
  43. public void PlayAnimation(AnimationType type, Action endcb = null)
  44. {
  45. var clip = GetClip(type);
  46. if (clip != null)
  47. {
  48. var state = Animancer.Play(clip);
  49. state.Time = 0;
  50. if(endcb != null)
  51. {
  52. state.Events.OnEnd = endcb;
  53. }
  54. }
  55. else
  56. {
  57. Log.Error($"Not exist clip({type}) @{gameObject.name}");
  58. }
  59. }
  60. }
  61. }