public void SetTangent(int leftRight, TangentMode mode, List <KeyIdentifier> keysToSet)
        {
            List <ChangedCurve> changedCurves = new List <ChangedCurve>();

            foreach (KeyIdentifier keyToSet in keysToSet)
            {
                AnimationCurve animationCurve = keyToSet.curve;
                Keyframe       key            = keyToSet.keyframe;
                AnimationUtility.SetKeyBroken(ref key, true);
                if (leftRight == 2)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref key, mode);
                    AnimationUtility.SetKeyRightTangentMode(ref key, mode);
                }
                else
                {
                    if (leftRight == 0)
                    {
                        AnimationUtility.SetKeyLeftTangentMode(ref key, mode);

                        // Make sure other tangent is handled correctly
                        if (AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.ClampedAuto || AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.Auto)
                        {
                            AnimationUtility.SetKeyRightTangentMode(ref key, TangentMode.Free);
                        }
                    }
                    else                     //if (leftRight == 1)
                    {
                        AnimationUtility.SetKeyRightTangentMode(ref key, mode);

                        // Make sure other tangent is handled correctly
                        if (AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.ClampedAuto || AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.Auto)
                        {
                            AnimationUtility.SetKeyLeftTangentMode(ref key, TangentMode.Free);
                        }
                    }
                }

                if (mode == TangentMode.Constant && (leftRight == 0 || leftRight == 2))
                {
                    key.inTangent = Mathf.Infinity;
                }
                if (mode == TangentMode.Constant && (leftRight == 1 || leftRight == 2))
                {
                    key.outTangent = Mathf.Infinity;
                }

                animationCurve.MoveKey(keyToSet.key, key);
                AnimationUtility.UpdateTangentsFromModeSurrounding(animationCurve, keyToSet.key);
                // Debug.Log ("Before " + DebKey (key) + " after: " + DebKey (animationCurve[keyToSet.key]));

                ChangedCurve changedCurve = new ChangedCurve(animationCurve, keyToSet.curveId, keyToSet.binding);
                if (!changedCurves.Contains(changedCurve))
                {
                    changedCurves.Add(changedCurve);
                }
            }

            updater.UpdateCurves(changedCurves, "Set Tangents");
        }
        public void SetBroken(object _keysToSet)
        {
            List <ChangedCurve>  changedCurves = new List <ChangedCurve>();
            List <KeyIdentifier> keysToSet     = (List <KeyIdentifier>)_keysToSet;

            foreach (KeyIdentifier keyToSet in keysToSet)
            {
                AnimationCurve animationCurve = keyToSet.curve;
                Keyframe       key            = keyToSet.keyframe;
                AnimationUtility.SetKeyBroken(ref key, true);
                if (AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.ClampedAuto || AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.Auto)
                {
                    AnimationUtility.SetKeyRightTangentMode(ref key, TangentMode.Free);
                }
                if (AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.ClampedAuto || AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.Auto)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref key, TangentMode.Free);
                }

                animationCurve.MoveKey(keyToSet.key, key);
                AnimationUtility.UpdateTangentsFromModeSurrounding(animationCurve, keyToSet.key);

                ChangedCurve changedCurve = new ChangedCurve(animationCurve, keyToSet.curveId, keyToSet.binding);
                if (!changedCurves.Contains(changedCurve))
                {
                    changedCurves.Add(changedCurve);
                }
            }

            updater.UpdateCurves(changedCurves, "Set Tangents");
        }
        public void SetBoth(TangentMode mode, List <KeyIdentifier> keysToSet)
        {
            List <ChangedCurve> changedCurves = new List <ChangedCurve>();

            foreach (KeyIdentifier keyToSet in keysToSet)
            {
                AnimationCurve animationCurve = keyToSet.curve;
                Keyframe       key            = keyToSet.keyframe;
                AnimationUtility.SetKeyBroken(ref key, false);
                AnimationUtility.SetKeyRightTangentMode(ref key, mode);
                AnimationUtility.SetKeyLeftTangentMode(ref key, mode);

                // Smooth Tangents based on neighboring nodes
                // Note: not needed since the UpdateTangentsFromModeSurrounding call below will handle it
                //if (mode == TangentMode.ClampedAuto) animationCurve.SmoothTangents(keyToSet.key, 0.0F);
                // Smooth tangents based on existing tangents
                if (mode == TangentMode.Free)
                {
                    float slope = CurveUtility.CalculateSmoothTangent(key);
                    key.inTangent  = slope;
                    key.outTangent = slope;
                }
                animationCurve.MoveKey(keyToSet.key, key);
                AnimationUtility.UpdateTangentsFromModeSurrounding(animationCurve, keyToSet.key);

                ChangedCurve changedCurve = new ChangedCurve(animationCurve, keyToSet.curveId, keyToSet.binding);
                if (!changedCurves.Contains(changedCurve))
                {
                    changedCurves.Add(changedCurve);
                }
            }

            updater.UpdateCurves(changedCurves, "Set Tangents");
        }
        public void ToggleWeighted(WeightedMode weightedMode, List <KeyIdentifier> keysToSet)
        {
            bool allWeighted = keysToSet.TrueForAll(key => (key.keyframe.weightedMode & weightedMode) == weightedMode);

            List <ChangedCurve> changedCurves = new List <ChangedCurve>();

            foreach (KeyIdentifier keyToSet in keysToSet)
            {
                AnimationCurve animationCurve = keyToSet.curve;
                Keyframe       key            = keyToSet.keyframe;

                bool weighted = (key.weightedMode & weightedMode) == weightedMode;
                if (weighted == allWeighted)
                {
                    WeightedMode lastWeightedMode = key.weightedMode;
                    key.weightedMode = weighted ? key.weightedMode & ~weightedMode : key.weightedMode | weightedMode;

                    if (key.weightedMode != WeightedMode.None)
                    {
                        TangentMode rightTangentMode = AnimationUtility.GetKeyRightTangentMode(key);
                        TangentMode leftTangentMode  = AnimationUtility.GetKeyLeftTangentMode(key);

                        if ((lastWeightedMode & WeightedMode.Out) == WeightedMode.None && (key.weightedMode & WeightedMode.Out) == WeightedMode.Out)
                        {
                            if (rightTangentMode == TangentMode.Linear || rightTangentMode == TangentMode.Constant)
                            {
                                AnimationUtility.SetKeyRightTangentMode(ref key, TangentMode.Free);
                            }
                            if (keyToSet.key < (animationCurve.length - 1))
                            {
                                key.outWeight = 1 / 3.0f;
                            }
                        }

                        if ((lastWeightedMode & WeightedMode.In) == WeightedMode.None && (key.weightedMode & WeightedMode.In) == WeightedMode.In)
                        {
                            if (leftTangentMode == TangentMode.Linear || leftTangentMode == TangentMode.Constant)
                            {
                                AnimationUtility.SetKeyLeftTangentMode(ref key, TangentMode.Free);
                            }
                            if (keyToSet.key > 0)
                            {
                                key.inWeight = 1 / 3.0f;
                            }
                        }
                    }

                    animationCurve.MoveKey(keyToSet.key, key);
                    AnimationUtility.UpdateTangentsFromModeSurrounding(animationCurve, keyToSet.key);

                    ChangedCurve changedCurve = new ChangedCurve(animationCurve, keyToSet.curveId, keyToSet.binding);
                    if (!changedCurves.Contains(changedCurve))
                    {
                        changedCurves.Add(changedCurve);
                    }
                }
            }

            updater.UpdateCurves(changedCurves, "Toggle Weighted");
        }
        public void Flatten(List <KeyIdentifier> keysToSet)
        {
            List <ChangedCurve> changedCurves = new List <ChangedCurve>();

            foreach (KeyIdentifier keyToSet in keysToSet)
            {
                AnimationCurve animationCurve = keyToSet.curve;
                Keyframe       key            = keyToSet.keyframe;
                key.inTangent  = 0;
                key.outTangent = 0;
                animationCurve.MoveKey(keyToSet.key, key);
                AnimationUtility.UpdateTangentsFromModeSurrounding(animationCurve, keyToSet.key);

                ChangedCurve changedCurve = new ChangedCurve(animationCurve, keyToSet.curveId, keyToSet.binding);
                if (!changedCurves.Contains(changedCurve))
                {
                    changedCurves.Add(changedCurve);
                }
            }

            updater.UpdateCurves(changedCurves, "Set Tangents");
        }