Example #1
0
        void DrawCurve(USInternalCurve curve, Color curveColour)
        {
            if (curve.Keys.Count == 0)
            {
                return;
            }

            using (new HandlesChangeColor(curveColour))
            {
                for (var keyframeIndex = 1; keyframeIndex < curve.Keys.Count; keyframeIndex++)
                {
                    var keyframe = curve.Keys[keyframeIndex];
                    for (var segmentIndex = 1; segmentIndex < cachedKeyframePositions[keyframe].CurveSegments.Count; segmentIndex++)
                    {
                        AnimationCurveEditorGUIUtility.DrawLine(
                            cachedKeyframePositions[keyframe].CurveSegments[segmentIndex - 1],
                            cachedKeyframePositions[keyframe].CurveSegments[segmentIndex],
                            XScroll,
                            XScale);
                    }
                }

                for (var keyframeIndex = 0; keyframeIndex < curve.Keys.Count; keyframeIndex++)
                {
                    cachedKeyframePositions[curve.Keys[keyframeIndex]].LeftTangentColor  = Color.white;
                    cachedKeyframePositions[curve.Keys[keyframeIndex]].RightTangentColor = Color.white;
                    if (SelectedTangent == 0)
                    {
                        cachedKeyframePositions[curve.Keys[keyframeIndex]].LeftTangentColor = Color.yellow;
                    }
                    if (SelectedTangent == 1)
                    {
                        cachedKeyframePositions[curve.Keys[keyframeIndex]].RightTangentColor = Color.yellow;
                    }

                    AnimationCurveEditorGUIUtility.KeyframeLabel(
                        curve.Keys[keyframeIndex],
                        cachedKeyframePositions[curve.Keys[keyframeIndex]],
                        (keyframeIndex == 0 && curve.UseCurrentValue),
                        XScroll,
                        XScale);

                    if (SelectedObjects.Count == 1 && SelectedObjects.Contains(curve.Keys[keyframeIndex]))
                    {
                        DrawTangent(cachedKeyframePositions[curve.Keys[keyframeIndex]], curve.Keys[keyframeIndex]);
                    }
                }
            }
        }
Example #2
0
        public void AddKeyframe(USInternalKeyframe internalKeyframe, USInternalCurve curve)
        {
            USUndoManager.PropertyChange(curve, "Add Keyframe");
            curve.Keys.Add(internalKeyframe);

            if (Duration < internalKeyframe.Time)
            {
                Duration = internalKeyframe.Time;
            }

            curve.Keys.Sort(USInternalCurve.KeyframeComparer);
            curve.BuildAnimationCurveFromInternalCurve();

            RebuildCachedCurveInformation();
            AreCurvesDirty = true;
        }
Example #3
0
 public Modification(USInternalCurve curve, float newTime, float newValue)
 {
     this.curve    = curve;
     this.newTime  = newTime;
     this.newValue = newValue;
 }
Example #4
0
        private USInternalKeyframe AddKeyframe(USInternalCurve curve, float time, float value)
        {
            // If a keyframe already exists at this time, use that one.
            USInternalKeyframe internalKeyframe = null;

            foreach (var keyframe in curve.Keys)
            {
                if (Mathf.Approximately(keyframe.Time, time))
                {
                    internalKeyframe = keyframe;
                }

                if (internalKeyframe != null)
                {
                    break;
                }
            }

            // Didn't find a keyframe create a new one.
            if (!internalKeyframe)
            {
                internalKeyframe = CreateInstance <USInternalKeyframe>();
                USUndoManager.RegisterCreatedObjectUndo(internalKeyframe, "Add New Keyframe");
                USUndoManager.RegisterCompleteObjectUndo(curve, "Add Keyframe");
                curve.Keys.Add(internalKeyframe);
            }

            USUndoManager.RegisterCompleteObjectUndo(internalKeyframe, "Add Keyframe");
            internalKeyframe.curve      = curve;
            internalKeyframe.Time       = time;
            internalKeyframe.Value      = value;
            internalKeyframe.InTangent  = 0.0f;
            internalKeyframe.OutTangent = 0.0f;

            if (AutoTangentMode == CurveAutoTangentModes.Smooth)
            {
                internalKeyframe.Smooth();
            }
            else if (AutoTangentMode == CurveAutoTangentModes.Flatten)
            {
                internalKeyframe.Flatten();
            }
            else if (AutoTangentMode == CurveAutoTangentModes.RightLinear)
            {
                internalKeyframe.RightTangentLinear();
            }
            else if (AutoTangentMode == CurveAutoTangentModes.RightConstant)
            {
                internalKeyframe.RightTangentConstant();
            }
            else if (AutoTangentMode == CurveAutoTangentModes.LeftLinear)
            {
                internalKeyframe.LeftTangentLinear();
            }
            else if (AutoTangentMode == CurveAutoTangentModes.LeftConstant)
            {
                internalKeyframe.LeftTangentConstant();
            }
            else if (AutoTangentMode == CurveAutoTangentModes.BothLinear)
            {
                internalKeyframe.BothTangentLinear();
            }
            else if (AutoTangentMode == CurveAutoTangentModes.BothConstant)
            {
                internalKeyframe.BothTangentConstant();
            }

            curve.Keys.Sort(USInternalCurve.KeyframeComparer);

            curve.BuildAnimationCurveFromInternalCurve();

            return(internalKeyframe);
        }