SetKeyRightTangentMode() public static method

public static SetKeyRightTangentMode ( AnimationCurve curve, int index, TangentMode tangentMode ) : void
curve AnimationCurve
index int
tangentMode TangentMode
return void
        public void SetBroken(object _keysToSet)
        {
            List <ChangedCurve>  list  = new List <ChangedCurve>();
            List <KeyIdentifier> list2 = (List <KeyIdentifier>)_keysToSet;

            foreach (KeyIdentifier current in list2)
            {
                AnimationCurve curve    = current.curve;
                Keyframe       keyframe = current.keyframe;
                AnimationUtility.SetKeyBroken(ref keyframe, true);
                if (AnimationUtility.GetKeyRightTangentMode(keyframe) == AnimationUtility.TangentMode.ClampedAuto || AnimationUtility.GetKeyRightTangentMode(keyframe) == AnimationUtility.TangentMode.Auto)
                {
                    AnimationUtility.SetKeyRightTangentMode(ref keyframe, AnimationUtility.TangentMode.Free);
                }
                if (AnimationUtility.GetKeyLeftTangentMode(keyframe) == AnimationUtility.TangentMode.ClampedAuto || AnimationUtility.GetKeyLeftTangentMode(keyframe) == AnimationUtility.TangentMode.Auto)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref keyframe, AnimationUtility.TangentMode.Free);
                }
                curve.MoveKey(current.key, keyframe);
                AnimationUtility.UpdateTangentsFromModeSurrounding(curve, current.key);
                ChangedCurve item = new ChangedCurve(curve, current.curveId, current.binding);
                if (!list.Contains(item))
                {
                    list.Add(item);
                }
            }
            this.updater.UpdateCurves(list, "Set Tangents");
        }
        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 SetBoth(AnimationUtility.TangentMode mode, List <KeyIdentifier> keysToSet)
        {
            List <ChangedCurve> list = new List <ChangedCurve>();

            foreach (KeyIdentifier current in keysToSet)
            {
                AnimationCurve curve    = current.curve;
                Keyframe       keyframe = current.keyframe;
                AnimationUtility.SetKeyBroken(ref keyframe, false);
                AnimationUtility.SetKeyRightTangentMode(ref keyframe, mode);
                AnimationUtility.SetKeyLeftTangentMode(ref keyframe, mode);
                if (mode == AnimationUtility.TangentMode.Free)
                {
                    float num = CurveUtility.CalculateSmoothTangent(keyframe);
                    keyframe.inTangent  = num;
                    keyframe.outTangent = num;
                }
                curve.MoveKey(current.key, keyframe);
                AnimationUtility.UpdateTangentsFromModeSurrounding(curve, current.key);
                ChangedCurve item = new ChangedCurve(curve, current.curveId, current.binding);
                if (!list.Contains(item))
                {
                    list.Add(item);
                }
            }
            this.updater.UpdateCurves(list, "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");
        }
 static internal void SetSmoothEditable(ref Keyframe[] keys, TangentMode tangentMode)
 {
     for (int i = 0; i < keys.Length; i++)
     {
         AnimationUtility.SetKeyBroken(ref keys[i], false);
         AnimationUtility.SetKeyLeftTangentMode(ref keys[i], tangentMode);
         AnimationUtility.SetKeyRightTangentMode(ref keys[i], tangentMode);
     }
 }
Esempio n. 8
0
        public static void SetKeyModeFromContext(AnimationCurve curve, int keyIndex)
        {
            Keyframe key   = curve[keyIndex];
            bool     flag  = false;
            bool     flag2 = false;

            if (keyIndex > 0)
            {
                if (AnimationUtility.GetKeyBroken(curve[keyIndex - 1]))
                {
                    flag = true;
                }
                if (AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]) == AnimationUtility.TangentMode.ClampedAuto)
                {
                    flag2 = true;
                }
            }
            if (keyIndex < curve.length - 1)
            {
                if (AnimationUtility.GetKeyBroken(curve[keyIndex + 1]))
                {
                    flag = true;
                }
                if (AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]) == AnimationUtility.TangentMode.ClampedAuto)
                {
                    flag2 = true;
                }
            }
            AnimationUtility.SetKeyBroken(ref key, flag);
            if (flag && !flag2)
            {
                if (keyIndex > 0)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref key, AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]));
                }
                if (keyIndex < curve.length - 1)
                {
                    AnimationUtility.SetKeyRightTangentMode(ref key, AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]));
                }
            }
            else
            {
                AnimationUtility.TangentMode tangentMode = AnimationUtility.TangentMode.Free;
                if ((keyIndex == 0 || AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]) == AnimationUtility.TangentMode.ClampedAuto) && (keyIndex == curve.length - 1 || AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]) == AnimationUtility.TangentMode.ClampedAuto))
                {
                    tangentMode = AnimationUtility.TangentMode.ClampedAuto;
                }
                else if ((keyIndex == 0 || AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]) == AnimationUtility.TangentMode.Auto) && (keyIndex == curve.length - 1 || AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]) == AnimationUtility.TangentMode.Auto))
                {
                    tangentMode = AnimationUtility.TangentMode.Auto;
                }
                AnimationUtility.SetKeyLeftTangentMode(ref key, tangentMode);
                AnimationUtility.SetKeyRightTangentMode(ref key, tangentMode);
            }
            curve.MoveKey(keyIndex, key);
        }
Esempio n. 9
0
        public static void SetKeyModeFromContext(AnimationCurve curve, int keyIndex)
        {
            Keyframe key    = curve[keyIndex];
            bool     broken = false;
            bool     flag2  = false;

            if (keyIndex > 0)
            {
                if (AnimationUtility.GetKeyBroken(curve[keyIndex - 1]))
                {
                    broken = true;
                }
                if (AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]) == AnimationUtility.TangentMode.ClampedAuto)
                {
                    flag2 = true;
                }
            }
            if (keyIndex < (curve.length - 1))
            {
                if (AnimationUtility.GetKeyBroken(curve[keyIndex + 1]))
                {
                    broken = true;
                }
                if (AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]) == AnimationUtility.TangentMode.ClampedAuto)
                {
                    flag2 = true;
                }
            }
            AnimationUtility.SetKeyBroken(ref key, broken);
            if (broken && !flag2)
            {
                if (keyIndex > 0)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref key, AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]));
                }
                if (keyIndex < (curve.length - 1))
                {
                    AnimationUtility.SetKeyRightTangentMode(ref key, AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]));
                }
            }
            else
            {
                AnimationUtility.TangentMode free = AnimationUtility.TangentMode.Free;
                if (((keyIndex == 0) || (AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]) == AnimationUtility.TangentMode.ClampedAuto)) && ((keyIndex == (curve.length - 1)) || (AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]) == AnimationUtility.TangentMode.ClampedAuto)))
                {
                    free = AnimationUtility.TangentMode.ClampedAuto;
                }
                else if (((keyIndex == 0) || (AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]) == AnimationUtility.TangentMode.Auto)) && ((keyIndex == (curve.length - 1)) || (AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]) == AnimationUtility.TangentMode.Auto)))
                {
                    free = AnimationUtility.TangentMode.Auto;
                }
                AnimationUtility.SetKeyLeftTangentMode(ref key, free);
                AnimationUtility.SetKeyRightTangentMode(ref key, free);
            }
            curve.MoveKey(keyIndex, key);
        }
Esempio n. 10
0
 internal static Keyframe[] GetLinearMirrorKeys()
 {
     Keyframe[] keyframeArray = new Keyframe[] { new Keyframe(0f, 1f, -1f, -1f), new Keyframe(1f, 0f, -1f, -1f) };
     for (int i = 0; i < 2; i++)
     {
         AnimationUtility.SetKeyBroken(ref keyframeArray[i], false);
         AnimationUtility.SetKeyLeftTangentMode(ref keyframeArray[i], AnimationUtility.TangentMode.Auto);
         AnimationUtility.SetKeyRightTangentMode(ref keyframeArray[i], AnimationUtility.TangentMode.Auto);
     }
     return(keyframeArray);
 }
        public void ToggleWeighted(WeightedMode weightedMode, List <KeyIdentifier> keysToSet)
        {
            bool flag = keysToSet.TrueForAll((KeyIdentifier key) => (key.keyframe.weightedMode & weightedMode) == weightedMode);
            List <ChangedCurve> list = new List <ChangedCurve>();

            foreach (KeyIdentifier current in keysToSet)
            {
                AnimationCurve curve    = current.curve;
                Keyframe       keyframe = current.keyframe;
                bool           flag2    = (keyframe.weightedMode & weightedMode) == weightedMode;
                if (flag2 == flag)
                {
                    WeightedMode weightedMode2 = keyframe.weightedMode;
                    keyframe.weightedMode = ((!flag2) ? (keyframe.weightedMode | weightedMode) : (keyframe.weightedMode & ~weightedMode));
                    if (keyframe.weightedMode != WeightedMode.None)
                    {
                        AnimationUtility.TangentMode keyRightTangentMode = AnimationUtility.GetKeyRightTangentMode(keyframe);
                        AnimationUtility.TangentMode keyLeftTangentMode  = AnimationUtility.GetKeyLeftTangentMode(keyframe);
                        if ((weightedMode2 & WeightedMode.Out) == WeightedMode.None && (keyframe.weightedMode & WeightedMode.Out) == WeightedMode.Out)
                        {
                            if (keyRightTangentMode == AnimationUtility.TangentMode.Linear || keyRightTangentMode == AnimationUtility.TangentMode.Constant)
                            {
                                AnimationUtility.SetKeyRightTangentMode(ref keyframe, AnimationUtility.TangentMode.Free);
                            }
                            if (current.key < curve.length - 1)
                            {
                                keyframe.outWeight = 0.333333343f;
                            }
                        }
                        if ((weightedMode2 & WeightedMode.In) == WeightedMode.None && (keyframe.weightedMode & WeightedMode.In) == WeightedMode.In)
                        {
                            if (keyLeftTangentMode == AnimationUtility.TangentMode.Linear || keyLeftTangentMode == AnimationUtility.TangentMode.Constant)
                            {
                                AnimationUtility.SetKeyLeftTangentMode(ref keyframe, AnimationUtility.TangentMode.Free);
                            }
                            if (current.key > 0)
                            {
                                keyframe.inWeight = 0.333333343f;
                            }
                        }
                    }
                    curve.MoveKey(current.key, keyframe);
                    AnimationUtility.UpdateTangentsFromModeSurrounding(curve, current.key);
                    ChangedCurve item = new ChangedCurve(curve, current.curveId, current.binding);
                    if (!list.Contains(item))
                    {
                        list.Add(item);
                    }
                }
            }
            this.updater.UpdateCurves(list, "Toggle Weighted");
        }
        public void SetTangent(int leftRight, AnimationUtility.TangentMode mode, List <KeyIdentifier> keysToSet)
        {
            List <ChangedCurve> list = new List <ChangedCurve>();

            foreach (KeyIdentifier current in keysToSet)
            {
                AnimationCurve curve    = current.curve;
                Keyframe       keyframe = current.keyframe;
                AnimationUtility.SetKeyBroken(ref keyframe, true);
                if (leftRight == 2)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref keyframe, mode);
                    AnimationUtility.SetKeyRightTangentMode(ref keyframe, mode);
                }
                else if (leftRight == 0)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref keyframe, mode);
                    if (AnimationUtility.GetKeyRightTangentMode(keyframe) == AnimationUtility.TangentMode.ClampedAuto || AnimationUtility.GetKeyRightTangentMode(keyframe) == AnimationUtility.TangentMode.Auto)
                    {
                        AnimationUtility.SetKeyRightTangentMode(ref keyframe, AnimationUtility.TangentMode.Free);
                    }
                }
                else
                {
                    AnimationUtility.SetKeyRightTangentMode(ref keyframe, mode);
                    if (AnimationUtility.GetKeyLeftTangentMode(keyframe) == AnimationUtility.TangentMode.ClampedAuto || AnimationUtility.GetKeyLeftTangentMode(keyframe) == AnimationUtility.TangentMode.Auto)
                    {
                        AnimationUtility.SetKeyLeftTangentMode(ref keyframe, AnimationUtility.TangentMode.Free);
                    }
                }
                if (mode == AnimationUtility.TangentMode.Constant && (leftRight == 0 || leftRight == 2))
                {
                    keyframe.inTangent = float.PositiveInfinity;
                }
                if (mode == AnimationUtility.TangentMode.Constant && (leftRight == 1 || leftRight == 2))
                {
                    keyframe.outTangent = float.PositiveInfinity;
                }
                curve.MoveKey(current.key, keyframe);
                AnimationUtility.UpdateTangentsFromModeSurrounding(curve, current.key);
                ChangedCurve item = new ChangedCurve(curve, current.curveId, current.binding);
                if (!list.Contains(item))
                {
                    list.Add(item);
                }
            }
            this.updater.UpdateCurves(list, "Set Tangents");
        }
Esempio n. 13
0
        public static void SetKeyRightTangentMode(AnimationCurve curve, int index, AnimationUtility.TangentMode tangentMode)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }
            if (index < 0 || index >= curve.length)
            {
                throw new ArgumentException("Index out of bounds.");
            }
            Keyframe key = curve[index];

            if (tangentMode != AnimationUtility.TangentMode.Free)
            {
                AnimationUtility.SetKeyBroken(ref key, true);
            }
            AnimationUtility.SetKeyRightTangentMode(ref key, tangentMode);
            curve.MoveKey(index, key);
            AnimationUtility.UpdateTangentsFromModeSurrounding(curve, index);
        }
Esempio n. 14
0
        public static void SetKeyRightTangentMode(AnimationCurve curve, int index, AnimationUtility.TangentMode tangentMode)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }
            if (index < 0 || index >= curve.length)
            {
                throw new ArgumentOutOfRangeException("index", string.Format("Index ({0}) must be in the range of 0 to {1}.", index, curve.length - 1));
            }
            Keyframe key = curve[index];

            if (tangentMode != AnimationUtility.TangentMode.Free)
            {
                AnimationUtility.SetKeyBroken(ref key, true);
            }
            AnimationUtility.SetKeyRightTangentMode(ref key, tangentMode);
            curve.MoveKey(index, key);
            AnimationUtility.UpdateTangentsFromModeSurrounding(curve, index);
        }
        // Move me to CurveEditor.cs
        public static void SetKeyModeFromContext(AnimationCurve curve, int keyIndex)
        {
            Keyframe key           = curve[keyIndex];
            bool     broken        = false;
            bool     smoothTangent = false;

            if (keyIndex > 0)
            {
                if (AnimationUtility.GetKeyBroken(curve[keyIndex - 1]))
                {
                    broken = true;
                }
                TangentMode prevTangentMode = AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]);
                if (prevTangentMode == TangentMode.ClampedAuto || prevTangentMode == TangentMode.Auto)
                {
                    smoothTangent = true;
                }
            }
            if (keyIndex < curve.length - 1)
            {
                if (AnimationUtility.GetKeyBroken(curve[keyIndex + 1]))
                {
                    broken = true;
                }
                TangentMode nextTangentMode = AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]);
                if (nextTangentMode == TangentMode.ClampedAuto || nextTangentMode == TangentMode.Auto)
                {
                    smoothTangent = true;
                }
            }

            AnimationUtility.SetKeyBroken(ref key, broken);

            if (broken && !smoothTangent)
            {
                if (keyIndex > 0)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref key, AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]));
                }
                if (keyIndex < curve.length - 1)
                {
                    AnimationUtility.SetKeyRightTangentMode(ref key, AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]));
                }

                // Keys at boundaries.  Make sure left and right tangent modes are the same.
                if (keyIndex == 0)
                {
                    AnimationUtility.SetKeyLeftTangentMode(ref key, AnimationUtility.GetKeyRightTangentMode(key));
                }
                if (keyIndex == curve.length - 1)
                {
                    AnimationUtility.SetKeyRightTangentMode(ref key, AnimationUtility.GetKeyLeftTangentMode(key));
                }
            }
            else
            {
                // If both neighbors or only neighbor are set to TangentMode.Auto or TangentMode.ClampedAuto, set new key to this mode as well.
                // If there are no neighbors, set new key to TangentMode.ClampedAuto.
                // Otherwise, fall back to TangentMode.Free.
                TangentMode mode = TangentMode.Free;
                if ((keyIndex == 0 || AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]) == TangentMode.ClampedAuto) &&
                    (keyIndex == curve.length - 1 || AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]) == TangentMode.ClampedAuto))
                {
                    mode = TangentMode.ClampedAuto;
                }
                else if ((keyIndex == 0 || AnimationUtility.GetKeyRightTangentMode(curve[keyIndex - 1]) == TangentMode.Auto) &&
                         (keyIndex == curve.length - 1 || AnimationUtility.GetKeyLeftTangentMode(curve[keyIndex + 1]) == TangentMode.Auto))
                {
                    mode = TangentMode.Auto;
                }

                AnimationUtility.SetKeyLeftTangentMode(ref key, mode);
                AnimationUtility.SetKeyRightTangentMode(ref key, mode);
            }

            curve.MoveKey(keyIndex, key);
        }