UpdateTangentsFromModeSurrounding() static private method

static private UpdateTangentsFromModeSurrounding ( AnimationCurve curve, int index ) : void
curve AnimationCurve
index int
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 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 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 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");
        }
Example #9
0
        public static void SetKeyBroken(AnimationCurve curve, int index, bool broken)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }
            if (index < 0 || index >= curve.length)
            {
                throw new ArgumentException("Index out of bounds.");
            }
            Keyframe key = curve[index];

            AnimationUtility.SetKeyBroken(ref key, broken);
            curve.MoveKey(index, key);
            AnimationUtility.UpdateTangentsFromModeSurrounding(curve, index);
        }
Example #10
0
        public static void SetKeyBroken(AnimationCurve curve, int index, bool broken)
        {
            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];

            AnimationUtility.SetKeyBroken(ref key, broken);
            curve.MoveKey(index, key);
            AnimationUtility.UpdateTangentsFromModeSurrounding(curve, index);
        }
        public void Flatten(List <KeyIdentifier> keysToSet)
        {
            List <ChangedCurve> list = new List <ChangedCurve>();

            foreach (KeyIdentifier current in keysToSet)
            {
                AnimationCurve curve    = current.curve;
                Keyframe       keyframe = current.keyframe;
                keyframe.inTangent  = 0f;
                keyframe.outTangent = 0f;
                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");
        }
Example #12
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);
        }
        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");
        }