Esempio n. 1
0
        void DrawGrid()
        {
            float totalAbs = Mathf.Abs(MaxDisplayY - MinDisplayY);
            var   yStep    = totalAbs / (AnimationCurveEditorUtility.NUM_LINES - 1);

            var maxHorizontalLines   = 5;
            var totalHorizontalLines = maxHorizontalLines * 2 + 1;
            var yPixelStep           = DisplayArea.height / (totalHorizontalLines - 1);

            using (new GUIChangeColor(AnimationCurveEditorUtility.LABEL_COLOR))
            {
                var xStep        = 0;
                var runningTotal = XScroll * -1.0f;
                while (runningTotal <= DisplayArea.width)
                {
                    if (runningTotal >= 0)
                    {
                        var startPos = new Vector2(runningTotal, 0.0f);
                        var endPos   = new Vector2(runningTotal, DisplayArea.height);

                        using (new HandlesChangeColor((xStep % AnimationCurveEditorUtility.BOLD_STEP == 0) ? AnimationCurveEditorUtility.BOLD_GRID : AnimationCurveEditorUtility.LIGHT_GRID))
                            AnimationCurveEditorGUIUtility.DrawLine(startPos, endPos);
                    }

                    xStep++;
                    runningTotal += CurrentXMarkerDist;

                    if (xStep > 200)
                    {
                        break;
                    }
                }

                for (var y = 0; y <= AnimationCurveEditorUtility.NUM_LINES; y++)
                {
                    var startPos = new Vector2(0.0f, y * yPixelStep);
                    var endPos   = new Vector2(DisplayArea.xMax, startPos.y);

                    startPos.y = DisplayArea.height - startPos.y;
                    endPos.y   = startPos.y;

                    Handles.color = AnimationCurveEditorUtility.LIGHT_GRID;

                    if (y % AnimationCurveEditorUtility.BOLD_STEP == 0)
                    {
                        GUIStyle style = null;
                        var      skin  = USEditorUtility.USeqSkin;
                        if (skin)
                        {
                            style = skin.GetStyle("AnimCurveLabel");
                        }
                        using (new GUIChangeColor(AnimationCurveEditorUtility.GRID_LABEL_COLOR))
                            GUI.Label(new Rect(startPos.x, y > 0 ? startPos.y : startPos.y - 15, 50, 20), string.Format("{0:F}", y * yStep + MinDisplayY), style);
                        Handles.color = AnimationCurveEditorUtility.BOLD_GRID;
                    }

                    AnimationCurveEditorGUIUtility.DrawLine(startPos, endPos);
                }
            }
        }
Esempio n. 2
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]);
                    }
                }
            }
        }