using UnityEngine;
using System.Collections;
using UnityEditor;
namespace RootMotion
{
    public static class AnimationUtilityExtended
    {
        /// 
        /// Copies the curves with the specified property names from clipFrom to clipTo.
        /// 
        /// copy from clip.
        /// paste to clip
        /// Property names ("Root.T", "Root.Q", "LeftFoot.T"...).
        public static void CopyCurves(AnimationClip fromClip, AnimationClip toClip, string[] propertyNames)
        {
            EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(fromClip);
            for (int i = 0; i < bindings.Length; i++)
            {
                for (int n = 0; n < propertyNames.Length; n++)
                {
                    if (bindings[i].propertyName == propertyNames[n])
                    {
                        CopyCurve(fromClip, toClip, bindings[i]);
                    }
                }
            }
        }
        public static void CopyCurve(AnimationClip fromClip, AnimationClip toClip, EditorCurveBinding binding)
        {
            AnimationCurve curve = AnimationUtility.GetEditorCurve(fromClip, binding);
            toClip.SetCurve(string.Empty, typeof(Animator), binding.propertyName, curve);
        }
    }
}