AnimationData.cs 1.4 KB

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