Пример #1
0
        public static Keyframe GetNew(float time, float value, TangentMode left, TangentMode right)
        {
            Keyframe keyframe = new Keyframe(time, value);              // cant use struct in reflection

            keyframe.SetKeyBroken(true);
            SetKeyTangentMode(keyframe, 0, left);
            SetKeyTangentMode(keyframe, 1, right);


            if (left == TangentMode.Stepped)
            {
                keyframe.inTangent = float.PositiveInfinity;
            }
            if (right == TangentMode.Stepped)
            {
                keyframe.outTangent = float.PositiveInfinity;
            }

            return(keyframe);
        }
Пример #2
0
        public static void SetKeyModeFromContext(this AnimationCurve curve, int keyIndex)
        {
            Keyframe key  = curve [keyIndex];
            bool     flag = false;

            if (keyIndex > 0 && curve [keyIndex - 1].GetKeyBroken())
            {
                flag = true;
            }
            if (keyIndex < curve.length - 1 && curve [keyIndex + 1].GetKeyBroken())
            {
                flag = true;
            }
            key.SetKeyBroken(flag);
            if (flag)
            {
                if (keyIndex > 0)
                {
                    key.SetKeyTangentMode(0, curve [keyIndex - 1].GetKeyTangentMode(1));
                }
                if (keyIndex < curve.length - 1)
                {
                    key.SetKeyTangentMode(1, curve [keyIndex + 1].GetKeyTangentMode(0));
                }
            }
            else
            {
                TangentMode mode = TangentMode.Smooth;
                if (keyIndex > 0 && curve [keyIndex - 1].GetKeyTangentMode(1) != TangentMode.Smooth)
                {
                    mode = TangentMode.Editable;
                }
                if (keyIndex < curve.length - 1 && curve [keyIndex + 1].GetKeyTangentMode(0) != TangentMode.Smooth)
                {
                    mode = TangentMode.Editable;
                }
                key.SetKeyTangentMode(0, mode);
                key.SetKeyTangentMode(1, mode);
            }
            curve.MoveKey(keyIndex, key);
        }