Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Aubrey Hesselgren · Mar 14, 2011 at 10:44 AM · dragselectionselect

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 ?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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);
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bovine · Oct 28, 2011 at 04:03 PM 0
Share

This doesn't appear to work. The last draw window twitches between one or more windows... :o/

avatar image Bunny83 · Oct 28, 2011 at 10:09 PM 0
Share

@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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges