private static Rect GetCurrentRect(bool screenSpace, float textureWidth, float textureHeight, Vector2 startPoint, Vector2 endPoint) { Rect rect = EditorGUIExt.FromToRect(Handles.s_InverseMatrix.MultiplyPoint(startPoint), Handles.s_InverseMatrix.MultiplyPoint(endPoint)); rect = SpriteEditorUtility.ClampedRect(SpriteEditorUtility.RoundToInt(rect), new Rect(0f, 0f, textureWidth, textureHeight), false); if (screenSpace) { Vector2 vector = Handles.matrix.MultiplyPoint(new Vector2(rect.xMin, rect.yMin)); Vector2 vector2 = Handles.matrix.MultiplyPoint(new Vector2(rect.xMax, rect.yMax)); rect = new Rect(vector.x, vector.y, vector2.x - vector.x, vector2.y - vector.y); } return(rect); }
static private Rect GetCurrentRect(bool screenSpace, Rect clampArea, Vector2 startPoint, Vector2 endPoint) { Rect r = EditorGUIExt.FromToRect(Handles.inverseMatrix.MultiplyPoint(startPoint), Handles.inverseMatrix.MultiplyPoint(endPoint)); r = SpriteEditorUtility.ClampedRect(SpriteEditorUtility.RoundToInt(r), clampArea, false); if (screenSpace) { Vector2 topleft = Handles.matrix.MultiplyPoint(new Vector2(r.xMin, r.yMin)); Vector2 bottomright = Handles.matrix.MultiplyPoint(new Vector2(r.xMax, r.yMax)); r = new Rect(topleft.x, topleft.y, bottomright.x - topleft.x, bottomright.y - topleft.y); } return(r); }
private void RectSelect(Rect r, ShapeEditor.SelectionType selectionType) { var localRect = EditorGUIExt.FromToRect(ScreenToLocal(r.min), ScreenToLocal(r.max)); m_SelectionRect = localRect; }
private void SelectPointsInRect(Rect r, SelectionType st) { var localRect = EditorGUIExt.FromToRect(ScreenToLocal(r.min), ScreenToLocal(r.max)); m_Selection.RectSelect(localRect, st); }
private void RectSelect(Rect r, ShapeEditor.SelectionType selectionType) { Rect value = EditorGUIExt.FromToRect(this.ScreenToLocal(r.min), this.ScreenToLocal(r.max)); this.m_SelectionRect = new Rect?(value); }
public void OnGUI() { var evt = UnityEvent.current; Handles.BeginGUI(); Vector2 mousePos = evt.mousePosition; int id = m_RectSelectionID; switch (evt.GetTypeForControl(id)) { case EventType.Layout: if (!Tools.viewToolActive) { HandleUtility.AddDefaultControl(id); } break; case EventType.MouseDown: if (HandleUtility.nearestControl == id && evt.button == 0) { guiUtility.hotControl = id; m_SelectStartPoint = mousePos; } break; case EventType.MouseDrag: if (guiUtility.hotControl == id) { if (!m_RectSelecting && (mousePos - m_SelectStartPoint).magnitude > k_MinSelectionSize) { m_RectSelecting = true; } if (m_RectSelecting) { m_SelectMousePoint = mousePos; SelectionType type = SelectionType.Normal; if (UnityEvent.current.control) { type = SelectionType.Subtractive; } else if (UnityEvent.current.shift) { type = SelectionType.Additive; } RectSelect(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint), type); } evt.Use(); } break; case EventType.Repaint: if (guiUtility.hotControl == id && m_RectSelecting) { EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint), GUIContent.none, false, false, false, false); } break; case EventType.MouseUp: if (guiUtility.hotControl == id && evt.button == 0) { guiUtility.hotControl = 0; guiUtility.keyboardControl = 0; if (m_RectSelecting) { m_SelectMousePoint = new Vector2(mousePos.x, mousePos.y); SelectionType type = SelectionType.Normal; if (UnityEvent.current.control) { type = SelectionType.Subtractive; } else if (UnityEvent.current.shift) { type = SelectionType.Additive; } RectSelect(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint), type); m_RectSelecting = false; } else { ClearSelection(); } evt.Use(); } break; } Handles.EndGUI(); }