Exemplo n.º 1
0
        public void DrawCurveEditor(Rect animEditorRect, WindowState state, Vector2 activeRange, bool loop, bool selected)
        {
            var curveStart    = state.TimeToPixel(m_DataSource.start);
            var minCurveStart = animEditorRect.xMax - 1.0f;

            if (curveStart > minCurveStart) // Prevent the curve from drawing inside small rect
            {
                animEditorRect.xMax += curveStart - minCurveStart;
            }

            UpdateCurveEditorIfNeeded(state);

            DrawCurveEditorBackground(animEditorRect);

            float localCurveStart = curveStart - animEditorRect.xMin;

            // adjust the top margin so smaller rectangle have smaller top / bottom margins.
            m_CurveEditor.topmargin = m_CurveEditor.bottommargin = CalculateTopMargin(animEditorRect.height);
            // calculate the margin needed to align the curve with the clip.
            m_CurveEditor.rightmargin = 0.0f;
            m_CurveEditor.leftmargin  = localCurveStart;

            m_CurveEditor.rect = new Rect(0.0f, 0.0f, animEditorRect.width, animEditorRect.height);

            m_CurveEditor.SetShownHRangeInsideMargins(0.0f, (state.PixelToTime(animEditorRect.xMax) - m_DataSource.start) * m_DataSource.timeScale);

            if (m_LastFrameRate != state.referenceSequence.frameRate)
            {
                m_CurveEditor.hTicks.SetTickModulosForFrameRate(state.referenceSequence.frameRate);
                m_LastFrameRate = state.referenceSequence.frameRate;
            }

            foreach (CurveWrapper cw in m_CurveEditor.animationCurves)
            {
                cw.renderer.SetWrap(WrapMode.Default, loop ? WrapMode.Loop : WrapMode.Default);
            }

            m_CurveEditor.BeginViewGUI();

            Color oldColor = GUI.color;

            GUI.color = Color.white;

            GUI.BeginGroup(animEditorRect);

            // Draw a line at 0
            Graphics.DrawLine(new Vector2(localCurveStart, 0.0f), new Vector2(localCurveStart, animEditorRect.height), new Color(1.0f, 1.0f, 1.0f, 0.5f));

            float rangeStart = activeRange.x - animEditorRect.x;
            float rangeWidth = activeRange.y - activeRange.x;

            // draw selection outline underneath the curves.
            if (selected)
            {
                var selectionRect = new Rect(rangeStart, 0.0f, rangeWidth, animEditorRect.height);
                DrawOutline(selectionRect);
            }

            EditorGUI.BeginChangeCheck();

            Event evt = Event.current;

            if ((evt.type == EventType.Layout) || (evt.type == EventType.Repaint) || selected)
            {
                m_CurveEditor.CurveGUI();
            }

            m_CurveEditor.EndViewGUI();

            if (EditorGUI.EndChangeCheck())
            {
                OnCurvesUpdated();
            }

            // draw overlays on top of curves
            var overlayColor = DirectorStyles.Instance.customSkin.colorInlineCurveOutOfRangeOverlay;

            var leftSide = new Rect(localCurveStart, 0.0f, rangeStart - localCurveStart, animEditorRect.height);

            EditorGUI.DrawRect(leftSide, overlayColor);

            var rightSide = new Rect(rangeStart + rangeWidth, 0.0f, animEditorRect.width - rangeStart - rangeWidth, animEditorRect.height);

            EditorGUI.DrawRect(rightSide, overlayColor);

            GUI.color = oldColor;

            GUI.EndGroup();

            // draw the grid labels last
            Rect gridRect = animEditorRect;

            gridRect.width = s_GridLabelWidth;
            float offset = localCurveStart - s_GridLabelWidth;

            if (offset > 0.0f)
            {
                gridRect.x = animEditorRect.x + offset;
            }

            GUI.BeginGroup(gridRect);

            m_CurveEditor.GridGUI();

            GUI.EndGroup();
        }