AnimationUtilityExtended.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;
  4. namespace RootMotion
  5. {
  6. public static class AnimationUtilityExtended
  7. {
  8. /// <summary>
  9. /// Copies the curves with the specified property names from clipFrom to clipTo.
  10. /// </summary>
  11. /// <param name="fromClip">copy from clip.</param>
  12. /// <param name="toClip">paste to clip</param>
  13. /// <param name="propertyNames">Property names ("Root.T", "Root.Q", "LeftFoot.T"...).</param>
  14. public static void CopyCurves(AnimationClip fromClip, AnimationClip toClip, string[] propertyNames)
  15. {
  16. EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(fromClip);
  17. for (int i = 0; i < bindings.Length; i++)
  18. {
  19. for (int n = 0; n < propertyNames.Length; n++)
  20. {
  21. if (bindings[i].propertyName == propertyNames[n])
  22. {
  23. CopyCurve(fromClip, toClip, bindings[i]);
  24. }
  25. }
  26. }
  27. }
  28. public static void CopyCurve(AnimationClip fromClip, AnimationClip toClip, EditorCurveBinding binding)
  29. {
  30. AnimationCurve curve = AnimationUtility.GetEditorCurve(fromClip, binding);
  31. toClip.SetCurve(string.Empty, typeof(Animator), binding.propertyName, curve);
  32. }
  33. }
  34. }