private void DrawLabels() { if (dragMode == DragMode.None) { return; } RectangleToolFlags flags = m_CurveEditor.settings.rectangleToolFlags; bool canScaleX = !Mathf.Approximately(selectionBounds.size.x, 0f); bool canScaleY = !Mathf.Approximately(selectionBounds.size.y, 0f); if (flags == RectangleToolFlags.FullRectangleTool) { // Horizontal labels if ((dragMode & DragMode.MoveScaleHorizontal) != 0) { if (canScaleX) { GUIContent leftLabelContent = new GUIContent(string.Format("{0}", m_CurveEditor.FormatTime(selectionBounds.min.x, m_CurveEditor.invSnap, m_CurveEditor.timeFormat))); GUIContent rightLabelContent = new GUIContent(string.Format("{0}", m_CurveEditor.FormatTime(selectionBounds.max.x, m_CurveEditor.invSnap, m_CurveEditor.timeFormat))); Vector2 leftLabelSize = styles.dragLabel.CalcSize(leftLabelContent); Vector2 rightLabelSize = styles.dragLabel.CalcSize(rightLabelContent); EditorGUI.DoDropShadowLabel(new Rect(m_Layout.leftLabelAnchor.x - leftLabelSize.x, m_Layout.leftLabelAnchor.y, leftLabelSize.x, leftLabelSize.y), leftLabelContent, styles.dragLabel, 0.3f); EditorGUI.DoDropShadowLabel(new Rect(m_Layout.rightLabelAnchor.x, m_Layout.rightLabelAnchor.y, rightLabelSize.x, rightLabelSize.y), rightLabelContent, styles.dragLabel, 0.3f); } else { GUIContent labelContent = new GUIContent(string.Format("{0}", m_CurveEditor.FormatTime(selectionBounds.center.x, m_CurveEditor.invSnap, m_CurveEditor.timeFormat))); Vector2 labelSize = styles.dragLabel.CalcSize(labelContent); EditorGUI.DoDropShadowLabel(new Rect(m_Layout.leftLabelAnchor.x, m_Layout.leftLabelAnchor.y, labelSize.x, labelSize.y), labelContent, styles.dragLabel, 0.3f); } } // Vertical labels if ((dragMode & DragMode.MoveScaleVertical) != 0) { if (canScaleY) { GUIContent bottomLabelContent = new GUIContent(string.Format("{0}", m_CurveEditor.FormatValue(selectionBounds.min.y))); GUIContent topLabelContent = new GUIContent(string.Format("{0}", m_CurveEditor.FormatValue(selectionBounds.max.y))); Vector2 bottomLabelSize = styles.dragLabel.CalcSize(bottomLabelContent); Vector2 topLabelSize = styles.dragLabel.CalcSize(topLabelContent); EditorGUI.DoDropShadowLabel(new Rect(m_Layout.bottomLabelAnchor.x, m_Layout.bottomLabelAnchor.y, bottomLabelSize.x, bottomLabelSize.y), bottomLabelContent, styles.dragLabel, 0.3f); EditorGUI.DoDropShadowLabel(new Rect(m_Layout.topLabelAnchor.x, m_Layout.topLabelAnchor.y - topLabelSize.y, topLabelSize.x, topLabelSize.y), topLabelContent, styles.dragLabel, 0.3f); } else { GUIContent labelContent = new GUIContent(string.Format("{0}", m_CurveEditor.FormatValue(selectionBounds.center.y))); Vector2 labelSize = styles.dragLabel.CalcSize(labelContent); EditorGUI.DoDropShadowLabel(new Rect(m_Layout.topLabelAnchor.x, m_Layout.topLabelAnchor.y - labelSize.y, labelSize.x, labelSize.y), labelContent, styles.dragLabel, 0.3f); } } } else if (flags == RectangleToolFlags.MiniRectangleTool) { if ((dragMode & DragMode.MoveBothAxis) != 0) { Vector2 localPosition = (canScaleX || canScaleY) ? new Vector2(PixelToTime(Event.current.mousePosition.x, frameRate), PixelToValue(Event.current.mousePosition.y)) : (Vector2)selectionBounds.center; Vector2 labelPosition = new Vector2(TimeToPixel(localPosition.x), ValueToPixel(localPosition.y)); GUIContent labelContent = new GUIContent(string.Format("{0}, {1}", m_CurveEditor.FormatTime(localPosition.x, m_CurveEditor.invSnap, m_CurveEditor.timeFormat), m_CurveEditor.FormatValue(localPosition.y))); Vector2 labelSize = styles.dragLabel.CalcSize(labelContent); EditorGUI.DoDropShadowLabel(new Rect(labelPosition.x, labelPosition.y - labelSize.y, labelSize.x, labelSize.y), labelContent, styles.dragLabel, 0.3f); } } }