GetKeyLeftTangentMode() static private method

static private GetKeyLeftTangentMode ( Keyframe key ) : TangentMode
key UnityEngine.Keyframe
return TangentMode
        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 UpdateTangentsFromMode(int index, int componentIndex)
        {
            AnimationCurve curve = GetCurve(componentIndex);

            if (index < 0 || index >= curve.length)
            {
                return;
            }

            Keyframe key = curve[index];

            // Adjust linear tangent
            if (AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.Linear && index >= 1)
            {
                key.inTangent = CalculateLinearTangent(index, index - 1, componentIndex);
                curve.MoveKey(index, key);
            }
            if (AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.Linear && index + 1 < curve.length)
            {
                key.outTangent = CalculateLinearTangent(index, index + 1, componentIndex);
                curve.MoveKey(index, key);
            }

            // Adjust smooth tangents
            if (AnimationUtility.GetKeyLeftTangentMode(key) == TangentMode.ClampedAuto || AnimationUtility.GetKeyRightTangentMode(key) == TangentMode.ClampedAuto)
            {
                key.inTangent = key.outTangent = CalculateSmoothTangent(index, componentIndex);
                curve.MoveKey(index, key);
            }
        }
        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 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 UpdateTangentsFromMode(int index, int componentIndex)
        {
            AnimationCurve curve = this.GetCurve(componentIndex);

            if ((index >= 0) && (index < curve.length))
            {
                Keyframe key = curve[index];
                if ((AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.Linear) && (index >= 1))
                {
                    key.inTangent = this.CalculateLinearTangent(index, index - 1, componentIndex);
                    curve.MoveKey(index, key);
                }
                if ((AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.Linear) && ((index + 1) < curve.length))
                {
                    key.outTangent = this.CalculateLinearTangent(index, index + 1, componentIndex);
                    curve.MoveKey(index, key);
                }
                if ((AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.ClampedAuto) || (AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.ClampedAuto))
                {
                    float num = this.CalculateSmoothTangent(index, componentIndex);
                    key.outTangent = num;
                    key.inTangent  = num;
                    curve.MoveKey(index, key);
                }
            }
        }
示例#7
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);
        }
示例#8
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);
        }
        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");
        }
示例#10
0
        public static AnimationUtility.TangentMode GetKeyLeftTangentMode(AnimationCurve curve, int index)
        {
            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];

            return(AnimationUtility.GetKeyLeftTangentMode(key));
        }
        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");
        }
示例#12
0
 private static void Internal_UpdateTangents(AnimationCurve curve, int index)
 {
     if (index >= 0 && index < curve.length)
     {
         Keyframe key = curve[index];
         if (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.Linear && index >= 1)
         {
             key.inTangent = AnimationUtility.Internal_CalculateLinearTangent(curve, index, index - 1);
             curve.MoveKey(index, key);
         }
         if (AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.Linear && index + 1 < curve.length)
         {
             key.outTangent = AnimationUtility.Internal_CalculateLinearTangent(curve, index, index + 1);
             curve.MoveKey(index, key);
         }
         if (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.ClampedAuto || AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.ClampedAuto)
         {
             AnimationUtility.Internal_CalculateAutoTangent(curve, index);
         }
         if (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.Auto || AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.Auto)
         {
             curve.SmoothTangents(index, 0f);
         }
         if (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.Free && AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.Free && !AnimationUtility.GetKeyBroken(key))
         {
             key.outTangent = key.inTangent;
             curve.MoveKey(index, key);
         }
         if (AnimationUtility.GetKeyLeftTangentMode(key) == AnimationUtility.TangentMode.Constant)
         {
             key.inTangent = float.PositiveInfinity;
             curve.MoveKey(index, key);
         }
         if (AnimationUtility.GetKeyRightTangentMode(key) == AnimationUtility.TangentMode.Constant)
         {
             key.outTangent = float.PositiveInfinity;
             curve.MoveKey(index, key);
         }
     }
 }
        public void AddTangentMenuItems(GenericMenu menu, List <KeyIdentifier> keyList)
        {
            bool flag  = keyList.Count > 0;
            bool on    = flag;
            bool on2   = flag;
            bool on3   = flag;
            bool on4   = flag;
            bool on5   = flag;
            bool flag2 = flag;
            bool flag3 = flag;
            bool on6   = flag;
            bool flag4 = flag;
            bool flag5 = flag;
            bool flag6 = flag;
            bool on7   = flag;
            bool flag7 = flag;

            foreach (KeyIdentifier current in keyList)
            {
                Keyframe keyframe = current.keyframe;
                AnimationUtility.TangentMode keyLeftTangentMode  = AnimationUtility.GetKeyLeftTangentMode(keyframe);
                AnimationUtility.TangentMode keyRightTangentMode = AnimationUtility.GetKeyRightTangentMode(keyframe);
                bool keyBroken = AnimationUtility.GetKeyBroken(keyframe);
                if (keyLeftTangentMode != AnimationUtility.TangentMode.ClampedAuto || keyRightTangentMode != AnimationUtility.TangentMode.ClampedAuto)
                {
                    on = false;
                }
                if (keyLeftTangentMode != AnimationUtility.TangentMode.Auto || keyRightTangentMode != AnimationUtility.TangentMode.Auto)
                {
                    on2 = false;
                }
                if (keyBroken || keyLeftTangentMode != AnimationUtility.TangentMode.Free || keyRightTangentMode != AnimationUtility.TangentMode.Free)
                {
                    on3 = false;
                }
                if (keyBroken || keyLeftTangentMode != AnimationUtility.TangentMode.Free || keyframe.inTangent != 0f || keyRightTangentMode != AnimationUtility.TangentMode.Free || keyframe.outTangent != 0f)
                {
                    on4 = false;
                }
                if (!keyBroken)
                {
                    on5 = false;
                }
                if (!keyBroken || keyLeftTangentMode != AnimationUtility.TangentMode.Free)
                {
                    flag3 = false;
                }
                if (!keyBroken || keyLeftTangentMode != AnimationUtility.TangentMode.Linear)
                {
                    on6 = false;
                }
                if (!keyBroken || keyLeftTangentMode != AnimationUtility.TangentMode.Constant)
                {
                    flag4 = false;
                }
                if (!keyBroken || keyRightTangentMode != AnimationUtility.TangentMode.Free)
                {
                    flag6 = false;
                }
                if (!keyBroken || keyRightTangentMode != AnimationUtility.TangentMode.Linear)
                {
                    on7 = false;
                }
                if (!keyBroken || keyRightTangentMode != AnimationUtility.TangentMode.Constant)
                {
                    flag7 = false;
                }
                if ((keyframe.weightedMode & WeightedMode.In) == WeightedMode.None)
                {
                    flag2 = false;
                }
                if ((keyframe.weightedMode & WeightedMode.Out) == WeightedMode.None)
                {
                    flag5 = false;
                }
            }
            if (flag)
            {
                menu.AddItem(EditorGUIUtility.TrTextContent("Clamped Auto", null, null), on, new GenericMenu.MenuFunction2(this.SetClampedAuto), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Auto", null, null), on2, new GenericMenu.MenuFunction2(this.SetAuto), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Free Smooth", null, null), on3, new GenericMenu.MenuFunction2(this.SetEditable), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Flat", null, null), on4, new GenericMenu.MenuFunction2(this.SetFlat), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Broken", null, null), on5, new GenericMenu.MenuFunction2(this.SetBroken), keyList);
                menu.AddSeparator("");
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Free", null, null), flag3, new GenericMenu.MenuFunction2(this.SetLeftEditable), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Linear", null, null), on6, new GenericMenu.MenuFunction2(this.SetLeftLinear), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Constant", null, null), flag4, new GenericMenu.MenuFunction2(this.SetLeftConstant), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Weighted", null, null), flag2, new GenericMenu.MenuFunction2(this.ToggleLeftWeighted), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Linear", null, null), on7, new GenericMenu.MenuFunction2(this.SetRightLinear), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Constant", null, null), flag7, new GenericMenu.MenuFunction2(this.SetRightConstant), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Free", null, null), flag6 && flag3, new GenericMenu.MenuFunction2(this.SetBothEditable), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Weighted", null, null), flag5, new GenericMenu.MenuFunction2(this.ToggleRightWeighted), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Constant", null, null), flag7 && flag4, new GenericMenu.MenuFunction2(this.SetBothConstant), keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Weighted", null, null), flag5 && flag2, new GenericMenu.MenuFunction2(this.ToggleBothWeighted), keyList);
            }
            else
            {
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Weighted", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Auto", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Free Smooth", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Flat", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Broken", null, null));
                menu.AddSeparator("");
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Free", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Linear", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Constant", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Free", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Linear", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Constant", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Free", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Linear", null, null));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Constant", null, null));
            }
        }
        // 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);
        }
        public void AddTangentMenuItems(GenericMenu menu, List <KeyIdentifier> keyList)
        {
            bool anyKeys = (keyList.Count > 0);
            // Find out which qualities apply to all the keys
            bool allClampedAuto   = anyKeys;
            bool allAuto          = anyKeys;
            bool allFreeSmooth    = anyKeys;
            bool allFlat          = anyKeys;
            bool allBroken        = anyKeys;
            bool allLeftWeighted  = anyKeys;
            bool allLeftFree      = anyKeys;
            bool allLeftLinear    = anyKeys;
            bool allLeftConstant  = anyKeys;
            bool allRightWeighted = anyKeys;
            bool allRightFree     = anyKeys;
            bool allRightLinear   = anyKeys;
            bool allRightConstant = anyKeys;

            foreach (KeyIdentifier sel in keyList)
            {
                Keyframe    key       = sel.keyframe;
                TangentMode leftMode  = AnimationUtility.GetKeyLeftTangentMode(key);
                TangentMode rightMode = AnimationUtility.GetKeyRightTangentMode(key);
                bool        broken    = AnimationUtility.GetKeyBroken(key);
                if (leftMode != TangentMode.ClampedAuto || rightMode != TangentMode.ClampedAuto)
                {
                    allClampedAuto = false;
                }
                if (leftMode != TangentMode.Auto || rightMode != TangentMode.Auto)
                {
                    allAuto = false;
                }
                if (broken || leftMode != TangentMode.Free || rightMode != TangentMode.Free)
                {
                    allFreeSmooth = false;
                }
                if (broken || leftMode != TangentMode.Free || key.inTangent != 0 || rightMode != TangentMode.Free || key.outTangent != 0)
                {
                    allFlat = false;
                }
                if (!broken)
                {
                    allBroken = false;
                }
                if (!broken || leftMode != TangentMode.Free)
                {
                    allLeftFree = false;
                }
                if (!broken || leftMode != TangentMode.Linear)
                {
                    allLeftLinear = false;
                }
                if (!broken || leftMode != TangentMode.Constant)
                {
                    allLeftConstant = false;
                }
                if (!broken || rightMode != TangentMode.Free)
                {
                    allRightFree = false;
                }
                if (!broken || rightMode != TangentMode.Linear)
                {
                    allRightLinear = false;
                }
                if (!broken || rightMode != TangentMode.Constant)
                {
                    allRightConstant = false;
                }


                if ((key.weightedMode & WeightedMode.In) == WeightedMode.None)
                {
                    allLeftWeighted = false;
                }
                if ((key.weightedMode & WeightedMode.Out) == WeightedMode.None)
                {
                    allRightWeighted = false;
                }
            }
            if (anyKeys)
            {
                menu.AddItem(EditorGUIUtility.TrTextContent("Clamped Auto"), allClampedAuto, SetClampedAuto, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Auto"), allAuto, SetAuto, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Free Smooth"), allFreeSmooth, SetEditable, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Flat"), allFlat, SetFlat, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Broken"), allBroken, SetBroken, keyList);
                menu.AddSeparator("");
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Free"), allLeftFree, SetLeftEditable, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Linear"), allLeftLinear, SetLeftLinear, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Constant"), allLeftConstant, SetLeftConstant, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Left Tangent/Weighted"), allLeftWeighted, ToggleLeftWeighted, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Free"), allRightFree, SetRightEditable, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Linear"), allRightLinear, SetRightLinear, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Constant"), allRightConstant, SetRightConstant, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Right Tangent/Weighted"), allRightWeighted, ToggleRightWeighted, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Free"), allRightFree && allLeftFree, SetBothEditable, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Linear"), allRightLinear && allLeftLinear, SetBothLinear, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Constant"), allRightConstant && allLeftConstant, SetBothConstant, keyList);
                menu.AddItem(EditorGUIUtility.TrTextContent("Both Tangents/Weighted"), allRightWeighted && allLeftWeighted, ToggleBothWeighted, keyList);
            }
            else
            {
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Weighted"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Auto"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Free Smooth"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Flat"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Broken"));
                menu.AddSeparator("");
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Free"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Linear"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Constant"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Left Tangent/Weighted"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Free"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Linear"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Constant"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Right Tangent/Weighted"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Free"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Linear"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Constant"));
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("Both Tangents/Weighted"));
            }
        }
        public void AddTangentMenuItems(GenericMenu menu, List <KeyIdentifier> keyList)
        {
            bool flag   = keyList.Count > 0;
            bool on     = flag;
            bool flag3  = flag;
            bool flag4  = flag;
            bool flag5  = flag;
            bool flag6  = flag;
            bool flag7  = flag;
            bool flag8  = flag;
            bool flag9  = flag;
            bool flag10 = flag;
            bool flag11 = flag;
            bool flag12 = flag;

            foreach (KeyIdentifier identifier in keyList)
            {
                Keyframe key = identifier.keyframe;
                AnimationUtility.TangentMode keyLeftTangentMode  = AnimationUtility.GetKeyLeftTangentMode(key);
                AnimationUtility.TangentMode keyRightTangentMode = AnimationUtility.GetKeyRightTangentMode(key);
                bool keyBroken = AnimationUtility.GetKeyBroken(key);
                if ((keyLeftTangentMode != AnimationUtility.TangentMode.ClampedAuto) || (keyRightTangentMode != AnimationUtility.TangentMode.ClampedAuto))
                {
                    on = false;
                }
                if ((keyLeftTangentMode != AnimationUtility.TangentMode.Auto) || (keyRightTangentMode != AnimationUtility.TangentMode.Auto))
                {
                    flag3 = false;
                }
                if ((keyBroken || (keyLeftTangentMode != AnimationUtility.TangentMode.Free)) || (keyRightTangentMode != AnimationUtility.TangentMode.Free))
                {
                    flag4 = false;
                }
                if ((keyBroken || (keyLeftTangentMode != AnimationUtility.TangentMode.Free)) || (((key.inTangent != 0f) || (keyRightTangentMode != AnimationUtility.TangentMode.Free)) || (key.outTangent != 0f)))
                {
                    flag5 = false;
                }
                if (!keyBroken)
                {
                    flag6 = false;
                }
                if (!keyBroken || (keyLeftTangentMode != AnimationUtility.TangentMode.Free))
                {
                    flag7 = false;
                }
                if (!keyBroken || (keyLeftTangentMode != AnimationUtility.TangentMode.Linear))
                {
                    flag8 = false;
                }
                if (!keyBroken || (keyLeftTangentMode != AnimationUtility.TangentMode.Constant))
                {
                    flag9 = false;
                }
                if (!keyBroken || (keyRightTangentMode != AnimationUtility.TangentMode.Free))
                {
                    flag10 = false;
                }
                if (!keyBroken || (keyRightTangentMode != AnimationUtility.TangentMode.Linear))
                {
                    flag11 = false;
                }
                if (!keyBroken || (keyRightTangentMode != AnimationUtility.TangentMode.Constant))
                {
                    flag12 = false;
                }
            }
            if (flag)
            {
                menu.AddItem(EditorGUIUtility.TextContent("Clamped Auto"), on, new GenericMenu.MenuFunction2(this.SetClampedAuto), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Auto"), flag3, new GenericMenu.MenuFunction2(this.SetAuto), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Free Smooth"), flag4, new GenericMenu.MenuFunction2(this.SetEditable), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Flat"), flag5, new GenericMenu.MenuFunction2(this.SetFlat), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Broken"), flag6, new GenericMenu.MenuFunction2(this.SetBroken), keyList);
                menu.AddSeparator("");
                menu.AddItem(EditorGUIUtility.TextContent("Left Tangent/Free"), flag7, new GenericMenu.MenuFunction2(this.SetLeftEditable), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Left Tangent/Linear"), flag8, new GenericMenu.MenuFunction2(this.SetLeftLinear), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Left Tangent/Constant"), flag9, new GenericMenu.MenuFunction2(this.SetLeftConstant), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Right Tangent/Free"), flag10, new GenericMenu.MenuFunction2(this.SetRightEditable), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Right Tangent/Linear"), flag11, new GenericMenu.MenuFunction2(this.SetRightLinear), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Right Tangent/Constant"), flag12, new GenericMenu.MenuFunction2(this.SetRightConstant), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Both Tangents/Free"), flag10 && flag7, new GenericMenu.MenuFunction2(this.SetBothEditable), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Both Tangents/Linear"), flag11 && flag8, new GenericMenu.MenuFunction2(this.SetBothLinear), keyList);
                menu.AddItem(EditorGUIUtility.TextContent("Both Tangents/Constant"), flag12 && flag9, new GenericMenu.MenuFunction2(this.SetBothConstant), keyList);
            }
            else
            {
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Clamped Auto"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Auto"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Free Smooth"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Flat"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Broken"));
                menu.AddSeparator("");
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Left Tangent/Free"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Left Tangent/Linear"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Left Tangent/Constant"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Right Tangent/Free"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Right Tangent/Linear"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Right Tangent/Constant"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Both Tangents/Free"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Both Tangents/Linear"));
                menu.AddDisabledItem(EditorGUIUtility.TextContent("Both Tangents/Constant"));
            }
        }