Esempio n. 1
0
        private void CurveEditorOnGUI(Rect position)
        {
            if (Event.current.type == EventType.Repaint)
            {
                m_CurveEditor.rect = position;
                m_CurveEditor.SetTickMarkerRanges();
            }

            Rect noSlidersRect = new Rect(position.xMin, position.yMin, position.width - kSliderThickness, position.height - kSliderThickness);

            m_CurveEditor.vSlider = m_State.showCurveEditor;
            m_CurveEditor.hSlider = m_State.showCurveEditor;

            // Sync animation curves in curve editor.  Do it only once per frame.
            if (Event.current.type == EventType.Layout)
            {
                UpdateCurveEditorData();
            }

            m_CurveEditor.BeginViewGUI();

            if (!m_State.disabled)
            {
                GUI.Box(noSlidersRect, GUIContent.none, AnimationWindowStyles.curveEditorBackground);
                m_CurveEditor.GridGUI();
            }

            EditorGUI.BeginChangeCheck();
            m_CurveEditor.CurveGUI();
            if (EditorGUI.EndChangeCheck())
            {
                SaveChangedCurvesFromCurveEditor();
            }
            m_CurveEditor.EndViewGUI();
        }
Esempio n. 2
0
        void DrawGrid(Rect rect, Vector2 curveRange)
        {
            var gridXPos     = Mathf.Max(curveRange.x - s_GridLabelWidth, rect.xMin);
            var gridRect     = new Rect(gridXPos, rect.y, s_GridLabelWidth, rect.height);
            var originalRect = m_CurveEditor.rect;

            m_CurveEditor.rect = new Rect(0.0f, 0.0f, rect.width, rect.height);
            using (new GUIGroupScope(gridRect))
                m_CurveEditor.GridGUI();
            m_CurveEditor.rect = originalRect;
        }
Esempio n. 3
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();
        }