protected virtual void OnLeftMouseDown(Event inputEvent) { JSONObjectEditorGUI <T> clickedOnObject = null; Vector2 gridPosition = GetEditorPosition(inputEvent.mousePosition); for (int i = 0; i < _editableObjects.Count; i++) { JSONObjectEditorGUI <T> evnt = (JSONObjectEditorGUI <T>)_editableObjects[i]; if (evnt.GetBounds().Contains(gridPosition)) { clickedOnObject = evnt; break; } } if (inputEvent.shift || inputEvent.control) { if (clickedOnObject != null) { if (_selectedObjects.Contains(clickedOnObject)) { _selectedObjects.Remove(clickedOnObject); clickedOnObject = null; } else { _selectedObjects.Add(clickedOnObject); } } } else if (clickedOnObject == null) { _selectedObjects.Clear(); } else if (!_selectedObjects.Contains(clickedOnObject)) { _selectedObjects = new List <ScriptableObject>() { clickedOnObject }; } //Dragging { GetEditorWindow().OnSelectObject(clickedOnObject); _draggedObject = clickedOnObject; _dragMode = eDragType.LeftClick; _dragPos = inputEvent.mousePosition; _dragAreaRect = new Rect(-1.0f, -1.0f, 0.0f, 0.0f); //Save state before dragging foreach (JSONObjectEditorGUI <T> evnt in _selectedObjects) { evnt.SaveUndoState(); } } }
protected void CenterCamera() { if (_editableObjects.Count > 0) { Rect maxBounds = ((JSONObjectEditorGUI <T>)_editableObjects[0]).GetBounds(); for (int i = 1; i < _editableObjects.Count; i++) { JSONObjectEditorGUI <T> editorGUI = (JSONObjectEditorGUI <T>)_editableObjects[i]; maxBounds.xMin = Mathf.Min(maxBounds.xMin, editorGUI.GetBounds().xMin); maxBounds.xMax = Mathf.Max(maxBounds.xMax, editorGUI.GetBounds().xMax); maxBounds.yMin = Mathf.Min(maxBounds.yMin, editorGUI.GetBounds().yMin); maxBounds.yMax = Mathf.Max(maxBounds.yMax, editorGUI.GetBounds().yMax); } _cameraPosition = -maxBounds.center; } else { _cameraPosition = Vector2.zero; } }
protected virtual void OnDragging(Event inputEvent) { Vector2 currentPos = inputEvent.mousePosition; if (_dragMode == eDragType.LeftClick) { _needsRepaint = true; inputEvent.Use(); if (_draggedObject != null) { Vector2 delta = currentPos - _dragPos; _dragPos = currentPos; DragObjects(delta); } else { _dragAreaRect.x = Math.Min(currentPos.x, _dragPos.x); _dragAreaRect.y = Math.Min(currentPos.y, _dragPos.y); _dragAreaRect.height = Math.Abs(currentPos.y - _dragPos.y); _dragAreaRect.width = Math.Abs(currentPos.x - _dragPos.x); _selectedObjects.Clear(); Rect gridDragRect = GetEditorRect(_dragAreaRect); for (int i = 0; i < _editableObjects.Count; i++) { JSONObjectEditorGUI <T> editorGUI = (JSONObjectEditorGUI <T>)_editableObjects[i]; if (editorGUI.GetBounds().Overlaps(gridDragRect)) { _selectedObjects.Add(editorGUI); } } } } else if (_dragMode == eDragType.MiddleMouseClick) { Vector2 delta = currentPos - _dragPos; _dragPos = currentPos; ScrollEditorView(delta); SetNeedsRepaint(); } }