internal static void Edit( dfGUIManager view, dfDesignGuide guide ) { var window = dfDesignGuideEditor.GetWindow<dfDesignGuideEditor>(); window.title = "Edit Guide"; window.minSize = window.maxSize = new Vector2( 250, 75 ); window.guide = guide; window.view = view; window.ShowUtility(); }
internal static void Edit(dfGUIManager view, dfDesignGuide guide) { var window = dfDesignGuideEditor.GetWindow <dfDesignGuideEditor>(); window.title = "Edit Guide"; window.minSize = window.maxSize = new Vector2(250, 75); window.guide = guide; window.view = view; window.ShowUtility(); }
private void closeWindow(EditorWindow window) { if (guide != null) { var maxValue = (guide.orientation == dfControlOrientation.Vertical) ? view.FixedWidth : view.FixedHeight; if (guide.position <= 0 || guide.position >= maxValue) { EditorUtility.SetDirty(view); view.guides.Remove(guide); } view = null; guide = null; this.Close(); } }
private void addContextDesignGuide( List<ContextMenuItem> menu, dfDesignGuide designGuide ) { var view = target as dfGUIManager; menu.Add( new ContextMenuItem() { MenuText = "Guide/Edit Guide", Handler = () => { dfEditorUtil.DelayedInvoke( () => { dfDesignGuideEditor.Edit( view, designGuide ); } ); } } ); menu.Add( new ContextMenuItem() { MenuText = "Guide/Delete Guide", Handler = () => { view.guides.Remove( designGuide ); } } ); if( view.guides.Count > 0 ) { menu.Add( new ContextMenuItem() { MenuText = "Guide/Clear All Guides", Handler = () => { view.guides.Clear(); SceneView.RepaintAll(); } } ); } }
public void OnSceneGUI() { if( Selection.objects.Length > 1 ) { return; } if( Event.current.isMouse && Event.current.button == 2 ) return; var view = target as dfGUIManager; var evt = Event.current; var id = GUIUtility.GetControlID( GetType().Name.GetHashCode(), FocusType.Passive ); var eventType = evt.GetTypeForControl( id ); var showGuidesConfig = EditorPrefs.GetBool( "dfGUIManager.ShowGuides", true ); var createVerticalGuideRect = new Rect(); var createHorizontalGuideRect = new Rect(); if( SceneView.currentDrawingSceneView.camera.orthographic ) { //if( createNewGuide() ) //{ // GUIUtility.hotControl = GUIUtility.keyboardControl = id; // evt.Use(); //} if( showGuidesConfig ) { EditorGUIUtility.AddCursorRect( createVerticalGuideRect = getNewVerticalGuideRect(), MouseCursor.ResizeHorizontal ); EditorGUIUtility.AddCursorRect( createHorizontalGuideRect = getNewHorizontalGuideRect(), MouseCursor.ResizeVertical ); addGuideCursorRects(); } } if( eventType == EventType.repaint ) { drawActionHints( evt ); } else if( eventType == EventType.mouseDown ) { var modifierKeyPressed = evt.alt || evt.control || evt.shift; if( evt.button != 0 || modifierKeyPressed ) { if( evt.button == 1 && !modifierKeyPressed ) { // Ensure that the mouse point is actually contained within the Manager var ray = HandleUtility.GUIPointToWorldRay( evt.mousePosition ); RaycastHit hitInfo; if( view.GetComponent<Collider>().Raycast( ray, out hitInfo, 1000 ) ) { displayContextMenu(); evt.Use(); return; } } GUIUtility.hotControl = GUIUtility.keyboardControl = 0; } if( Tools.current == Tool.Move && evt.button == 0 && showGuidesConfig ) { if( createVerticalGuideRect.Contains( evt.mousePosition ) ) { view.guides.Add( selectedGuide = new dfDesignGuide() { orientation = dfControlOrientation.Vertical, position = 0 } ); GUIUtility.hotControl = GUIUtility.keyboardControl = id; evt.Use(); currentAction = EditorAction.DraggingGuide; } else if( createHorizontalGuideRect.Contains( evt.mousePosition ) ) { view.guides.Add( selectedGuide = new dfDesignGuide() { orientation = dfControlOrientation.Horizontal, position = 0 } ); GUIUtility.hotControl = GUIUtility.keyboardControl = id; evt.Use(); currentAction = EditorAction.DraggingGuide; } else { var guide = getGuideUnderMouse(); if( guide != null ) { currentAction = EditorAction.DraggingGuide; selectedGuide = guide; GUIUtility.hotControl = GUIUtility.keyboardControl = id; evt.Use(); SceneView.RepaintAll(); } else { var hit = HandleUtility.PickGameObject( evt.mousePosition, true ); if( hit != null ) { Selection.activeGameObject = hit; return; } } } } } else if( eventType == EventType.mouseUp && selectedGuide != null ) { currentAction = EditorAction.None; endDraggingGuide(); SceneView.RepaintAll(); } else if( evt.keyCode == KeyCode.Escape && selectedGuide != null ) { currentAction = EditorAction.None; endDraggingGuide(); SceneView.RepaintAll(); } else if( currentAction == EditorAction.DraggingGuide && selectedGuide != null ) { dragDesignGuide( evt.mousePosition ); } if( evt.type == EventType.keyDown && evt.keyCode == KeyCode.G && evt.shift && evt.control ) { var showGuides = EditorPrefs.GetBool( "dfGUIManager.ShowGuides", true ); EditorPrefs.SetBool( "dfGUIManager.ShowGuides", !showGuides ); SceneView.RepaintAll(); } }
private void endDraggingGuide() { var view = target as dfGUIManager; if( selectedGuide == null ) return; if( selectedGuide.position == 0 || selectedGuide.position == view.FixedWidth ) view.guides.Remove( selectedGuide ); selectedGuide = null; GUIUtility.hotControl = GUIUtility.keyboardControl = 0; SceneView.RepaintAll(); }
private Rect calculateGuideCursorRect( dfDesignGuide guide ) { var view = this.target as dfGUIManager; var corners = view.GetCorners(); var cursorRect = new Rect(); if( guide.orientation == dfControlOrientation.Vertical ) { var pos1 = HandleUtility.WorldToGUIPoint( Vector3.Lerp( corners[ 0 ], corners[ 1 ], (float)guide.position / (float)view.FixedWidth ) ); var pos2 = HandleUtility.WorldToGUIPoint( Vector3.Lerp( corners[ 3 ], corners[ 2 ], (float)guide.position / (float)view.FixedWidth ) ); cursorRect = new Rect( pos1.x - 5, pos1.y, 10, Mathf.Abs( pos2.y - pos1.y ) ); } else { var pos1 = HandleUtility.WorldToGUIPoint( Vector3.Lerp( corners[ 0 ], corners[ 3 ], (float)guide.position / (float)view.FixedHeight ) ); var pos2 = HandleUtility.WorldToGUIPoint( Vector3.Lerp( corners[ 1 ], corners[ 2 ], (float)guide.position / (float)view.FixedHeight ) ); cursorRect = new Rect( pos1.x, pos1.y - 5, Mathf.Abs( pos2.x - pos1.x ), 10 ); } // Compensate for fast mouse movement if( guide == selectedGuide ) { cursorRect.x -= 100; cursorRect.y -= 100; cursorRect.width += 200; cursorRect.height += 200; } return cursorRect; }
private void closeWindow( EditorWindow window ) { if( guide != null ) { var maxValue = ( guide.orientation == dfControlOrientation.Vertical ) ? view.FixedWidth : view.FixedHeight; if( guide.position <= 0 || guide.position >= maxValue ) { EditorUtility.SetDirty( view ); view.guides.Remove( guide ); } view = null; guide = null; this.Close(); } }