/// <summary>
        /// Bakes motion from the skeleton to the constraints in the Rig.
        /// </summary>
        /// <param name="rig">The Rig whose RigConstraints are to be baked.</param>
        public static void TransferMotionToConstraint(Rig rig)
        {
            var rigBuilder = rig.GetComponentInParent <RigBuilder>();

            if (rigBuilder == null)
            {
                throw new InvalidOperationException("No rigbuilder was found in the hierarchy.");
            }

            TransferMotionToConstraint(rigBuilder, new Rig[] { rig });
        }
        /// <summary>
        /// Validates if the Editor and the provided Rig are in a correct state to do motion transfer.
        /// </summary>
        /// <param name="rig">The Rig that will be used for motion transfer.</param>
        /// <returns>Returns true if both the editor and the provided Rig are in a valid state for motion transfer. Returns false if the requirements are not met.</returns>
        public static bool TransferMotionValidate(Rig rig)
        {
            if (!AnimationWindowUtils.isPreviewing || AnimationWindowUtils.activeAnimationClip == null)
            {
                return(false);
            }

            var selected = Selection.instanceIDs;

            if (selected.Length != 1)
            {
                return(false);
            }

            var selectedGO = EditorUtility.InstanceIDToObject(selected[0]) as GameObject;

            if (selectedGO != rig.gameObject)
            {
                return(false);
            }

            var rigBuilder = rig.GetComponentInParent <RigBuilder>();

            if (rigBuilder == null)
            {
                return(false);
            }

            var animator = rigBuilder.GetComponent <Animator>();

            if (animator.isHuman)
            {
                return(false);
            }

            bool inRigBuilder = false;
            var  layers       = rigBuilder.layers;

            for (int i = 0; i < layers.Count; ++i)
            {
                if (layers[i].rig == rig && layers[i].active)
                {
                    inRigBuilder = true;
                }
            }

            return(inRigBuilder);
        }