public static void OpenOverivew() { var window = OdinEditorWindow.InspectObject(new EditorIconsOverview()); window.ShowUtility(); window.WindowPadding = new Vector4(); }
/// <summary> /// Inspects the object using an existing OdinEditorWindow. /// </summary> public static OdinEditorWindow InspectObject(OdinEditorWindow window, object obj) { var uObj = obj as UnityEngine.Object; if (uObj) { // If it's a Unity object, then it's likely the reference can survive a recompile. window.inspectTargetObject = null; window.inspectorTargetSerialized = uObj; } else { // Otherwise, it can't. In which case we don't want want to serialize it - hence inspectorTargetObject and not inspectorTargetSerialized. // If we did the user would be inspecting a different reference than provided. window.inspectorTargetSerialized = null; window.inspectTargetObject = obj; } if (uObj as Component) { window.titleContent = new GUIContent((uObj as Component).gameObject.name); } else if (uObj) { window.titleContent = new GUIContent(uObj.name); } else { window.titleContent = new GUIContent(obj.ToString()); } EditorUtility.SetDirty(window); return(window); }
/// <summary> /// Opens up the selector instance in a popup with the specified width and height. /// The mouse position is used as the position for the window. /// </summary> public OdinEditorWindow ShowInPopup(float width, float height) { var prevSelectedWindow = EditorWindow.focusedWindow; OdinEditorWindow window = OdinEditorWindow.InspectObjectInDropDown(this, width, height); SetupWindow(window, prevSelectedWindow); return(window); }
/// <summary> /// Opens up the selector instance in a popup at the specified rect position. /// </summary> public OdinEditorWindow ShowInPopup(Rect btnRect, Vector2 windowSize) { var prevSelectedWindow = EditorWindow.focusedWindow; OdinEditorWindow window = OdinEditorWindow.InspectObjectInDropDown(this, btnRect, windowSize); SetupWindow(window, prevSelectedWindow); return(window); }
/// <summary> /// Opens up the selector instance in a popup at the specified position. /// </summary> public OdinEditorWindow ShowInPopup(Vector2 position, float windowWidth) { var prevSelectedWindow = EditorWindow.focusedWindow; OdinEditorWindow window = OdinEditorWindow.InspectObjectInDropDown(this, position, windowWidth); SetupWindow(window, prevSelectedWindow); return(window); }
private void OpenCacheDebugWindow() { var target = new CacheDebugTarget { Entries = this.cache .Select(i => new CacheDebugEntry(i.Key, i.Value)) .ToList() }; OdinEditorWindow.InspectObject(target); }
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; }; }
/// <summary> /// Opens up the selector instance in a popup at the specified position. /// The width of the popup is determined by DefaultWindowWidth, and the height is automatically calculated. /// </summary> public OdinEditorWindow ShowInPopup(Vector2 position) { var prevSelectedWindow = EditorWindow.focusedWindow; OdinEditorWindow window; var width = this.DefaultWindowWidth(); if (width == 0) { window = OdinEditorWindow.InspectObjectInDropDown(this, position); } else { window = OdinEditorWindow.InspectObjectInDropDown(this, position, width); } SetupWindow(window, prevSelectedWindow); return(window); }
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; }; }