private void SetupWindow(OdinEditorWindow window, EditorWindow prevSelectedWindow) { var prevFocusId = GUIUtility.hotControl; var prevKeybaorFocus = GUIUtility.keyboardControl; this.popupWindowInstance = window; window.WindowPadding = new Vector4(); bool wasConfirmed = false; this.SelectionTree.Selection.SelectionConfirmed += x => UnityEditorEventUtility.DelayAction(() => { if (this.IsValidSelection(this.GetCurrentSelection())) { wasConfirmed = true; window.Close(); if (prevSelectedWindow) { prevSelectedWindow.Focus(); } } }); window.OnBeginGUI += () => { if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) { UnityEditorEventUtility.DelayAction(() => { window.Close(); }); if (prevSelectedWindow) { prevSelectedWindow.Focus(); } Event.current.Use(); } }; window.OnClose += () => { if (!wasConfirmed && this.SelectionCancelled != null) { this.SelectionCancelled(); } GUIUtility.hotControl = prevFocusId; GUIUtility.keyboardControl = prevKeybaorFocus; }; }
private void SetupWindow(OdinEditorWindow window, EditorWindow prevSelectedWindow) { var prevFocusId = GUIUtility.hotControl; var prevKeybaorFocus = GUIUtility.keyboardControl; this.popupWindowInstance = window; window.WindowPadding = new Vector4(); bool wasConfirmed = false; this.SelectionTree.Selection.SelectionConfirmed += x => { var ctrl = Event.current != null && Event.current.modifiers != EventModifiers.Control; UnityEditorEventUtility.DelayAction(() => { if (this.IsValidSelection(this.GetCurrentSelection())) { wasConfirmed = true; // This is so that users can hold control to trigger changes, without the window automatically closing. if (ctrl) { window.Close(); if (prevSelectedWindow) { prevSelectedWindow.Focus(); } } } }); }; window.OnBeginGUI += () => { if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) { UnityEditorEventUtility.DelayAction(() => { window.Close(); }); if (prevSelectedWindow) { prevSelectedWindow.Focus(); } Event.current.Use(); } }; window.OnClose += () => { if (!wasConfirmed && this.SelectionCancelled != null) { this.SelectionCancelled(); } GUIUtility.hotControl = prevFocusId; GUIUtility.keyboardControl = prevKeybaorFocus; }; }