- Home /
Is there an Editor Window "IsSelected" equivalent for popup windows?
I'm making an editor which pops up a bunch of popup windows, each of which uses GUI.DragWindow();
Now, when I click and drag these sub windows in the editor window, the title bar highlights, and stays highlighted until I click on some other window. So my assumption is, there must be some core way to figure out if the current window is selected, and I am kind of an idiot and can't figure it out?
I can think of a few workarounds involving checking if there's a change in window Rect position (to detect drags, if not simple selection), or check the mouse position when the LMB is released (I guess hover-over would be easier?). But is there an easier way to use the WindowID to figure out which is the currently selected GUILayout.Window ?
Answer by maxest · Sep 27, 2012 at 10:09 AM
// http://forum.unity3d.com/threads/18109-how-to-get-GUI.Window-focus?p=123442#post123442
static public int focusedWindow
{
get
{
System.Reflection.FieldInfo field =
typeof(GUI).GetField("focusedWindow",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Static);
return (int)field.GetValue(null);
}
}
Answer by Bunny83 · May 07, 2011 at 11:14 AM
Well, i come across the same issue and it seems the only way is to use your own "global" windowID variable. Just set it to the window ID that is passed to your window function. You have to do this in every window function. The variable will contain the last drawn window (top most).
All windows get drawn when you invoke Endwindows(). The only place where the variable would not be correct is inside a window function, but you could wrap the variable into another one after EndWindows that can be used inside a window function.
This doesn't appear to work. The last draw window twitches between one or more windows... :o/
@Bovine: It works fine (just tested it). I guess you forgot to check for the Repaint event. OnGUI (and also the window callback functions) is called multiple times per frame. Usually one time for layouting and one time for repaint. the layouting always happens in the same order as you have called the Window function, but the repaint order is changed according to the current z-order of the windows.
To set the LastDrawnWindow variable you have to make sure you're in the repaint event:
if (Event.current.type == EventType.Repaint)
LastDrawnWindow = ID;
Your answer
Follow this Question
Related Questions
RTS. shift select. 1 Answer
Selecting custom game objects in Scene view window. 1 Answer
Selecting objects in arbitrary 2d space using only arrow keys 2 Answers
UI Elements do not become selected? 0 Answers
Character Dress Up 0 Answers