Exemplo n.º 1
0
        // This will consider the direction, and curve type to return a float value that's interpolated.
        public float InterpolateFloat(InterpolationCurve curve, InterpolationDirection direction,
                                      float time, float beforeTime, float nextTime,
                                      float previousKeyValue, float nextKeyValue,
                                      float minValue, float maxValue)
        {
            float progressBetweenFrames = ProgressBetweenSurroundingKeyframes(time, beforeTime, nextTime);
            float curvedTime            = CurveAdjustedBlendingTime(curve, progressBetweenFrames);

            // Auto.
            if (direction == InterpolationDirection.Auto)
            {
                return(AutoInterpolation(curvedTime, previousKeyValue, nextKeyValue));
            }

            InterpolationDirection moveDirection = direction;

            float forwardDistance;
            float reverseDistance;

            CalculateCircularDistances(previousKeyValue, nextKeyValue, minValue, maxValue, out forwardDistance, out reverseDistance);

            // Shortest path.
            if (moveDirection == InterpolationDirection.ShortestPath)
            {
                if (reverseDistance > forwardDistance)
                {
                    moveDirection = InterpolationDirection.Foward;
                }
                else
                {
                    moveDirection = InterpolationDirection.Reverse;
                }
            }

            // Forward.
            if (moveDirection == InterpolationDirection.Foward)
            {
                return(ForwardInterpolation(curvedTime, previousKeyValue, nextKeyValue, minValue, maxValue, forwardDistance));
            }

            // Reverse.
            if (moveDirection == InterpolationDirection.Reverse)
            {
                return(ReverseInterpolation(curvedTime, previousKeyValue, nextKeyValue, minValue, maxValue, reverseDistance));
            }

            Debug.LogError("Unhandled interpolation direction: " + moveDirection + ", returning min value.");

            return(minValue);
        }
Exemplo n.º 2
0
        public bool RenderInterpolationDirectionType()
        {
            EditorGUI.BeginChangeCheck();

            InterpolationDirection selectedDirection = (InterpolationDirection)EditorGUILayout.EnumPopup(
                new GUIContent("Animation Direction",
                               "Adjust the animation direction to control how this property animates to the next keyframe value."), keyframe.interpolationDirection);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(profile, "Direction changed");
                keyframe.interpolationDirection = selectedDirection;
                return(true);
            }

            return(false);
        }