Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by MattSawrey · Nov 21, 2016 at 09:09 PM · guieditorwindoweventdragwindow

GUI.Window makes custom EditorWindow drag header unresponsive

I've made a custom EditorWindow that displays a lot of "GUI.Window"s and I've made them all draggable using the "GUI.DragWindow" method. Moving a draggable gui window around makes the overall EditorWindow header (the top horizontal strip of the window you can click on to drag the window around) unresponsive.

I believe this has something to do with how "GUI.DragWindow" processes the current event. I manually process all of the events that happen in the EditorWindow and use the current event through "currentEvent.Use()". I don't manually "Use" the current event when the user clicks on a "GUI.Window", because doing so would stop the "GUI.DragWindow()" from working (the windows are no longer draggable). However, using the event before GUI.DragWindow does stop the overall EditorWindow from becoming unresponsive.

Has anyone else come across this issue? And if so, could you advise as to how I might approach solving this (have both the GUI.DragWindow windows and the overall EditorWindow be responsive)

Thanks in advance. Matt

Comment
Add comment · Show 2
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 MattSawrey · Nov 21, 2016 at 09:17 PM 0
Share

I've noticed that if I check the event type when the EditorWindow header strip is being unresponsive, the type is "Ignore".

avatar image MattSawrey · Nov 21, 2016 at 09:25 PM 0
Share

I've also noticed that the GuiUtility.hotcontrol value isn't registering as 0 when I click on the EditorWindow after having dragged a GUI.window around. That's probably the issue.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MattSawrey · Nov 21, 2016 at 09:32 PM

Solved it.

If you're going to use GUI.DragWindow, but want to be able to resize and drag the custom EditorWindow around afterwards, make sure to reset the GuiUtility.hotcontrol value to 0 on the mouseup/dragexited event after that drag has finished.

I would have thought that this would have been handled by the DragWindow method, but I don't know exactly what happens inside that, so maybe there's something I'm missing.

Hope this is useful to others!

Thanks, Matt

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 · Nov 22, 2016 at 03:00 AM

Uhm, did you actually place your GUI.Window calls between BeginWindows and EndWindows? EditorWindows are handled a bit different.

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 MattSawrey · Nov 22, 2016 at 07:42 AM 0
Share

Yes, I already knew to do this. Thanks for the response though.

avatar image Bunny83 MattSawrey · Nov 22, 2016 at 11:13 AM 0
Share

Hmm, then you must do something else wrong as setting hotcontrol to 0 shouldn't be necessary. Are you filter some required events? $$anonymous$$aybe the layout event? The layout event is required for GUI.Windows, even when you don't use GUILayout. $$anonymous$$aybe you draw your windows "conditionally" and stop drawing it at the "wrong point". That's a general problem with the I$$anonymous$$GUI system. If something uses a generic passive control id it might get reassigned or moved to another control when you remove or add one in between.

GUI.DragWindow used to allocate a passive ID:

 int controlID = GUIUtility.GetControlID(FocusType.Passive);

Unfortunately Unity moved the code of DragWindow into the native core recently, so we can't see what it does exactly. In the past (about Unity 3.3) it looked like this:

 // UnityEngine.GUI
 public static void DragWindow(Rect position)
 {
     GUIUtility.CheckOnGUI();
     if (GUI._Window.current == null)
     {
         Debug.LogError("Dragwindow can only be called within a window callback");
         return;
     }
     int controlID = GUIUtility.GetControlID(FocusType.Passive);
     GUI._Window current = GUI._Window.current;
     Event current2 = Event.current;
     if (current == null)
     {
         return;
     }
     GUI.WindowDragState windowDragState = (GUI.WindowDragState)GUIUtility.GetStateObject(typeof(GUI.WindowDragState), controlID + 100);
     switch (Event.current.GetTypeForControl(controlID))
     {
     case EventType.$$anonymous$$ouseDown:
         if (position.Contains(current2.mousePosition) && GUIUtility.hotControl == 0)
         {
             GUIUtility.hotControl = controlID;
             Event.current.Use();
             $$anonymous$$atrix4x4 matrix = GUI._Window.current.matrix;
             windowDragState.dragStartPos = GUIClip.GetAbsolute$$anonymous$$ousePosition() - matrix.$$anonymous$$ultiplyPoint(new Vector2(current.rect.x, current.rect.y));
             windowDragState.dragStartRect = current.rect;
         }
         break;
     case EventType.$$anonymous$$ouseUp:
         if (GUIUtility.hotControl == controlID)
         {
             GUIUtility.hotControl = 0;
             Event.current.Use();
         }
         break;
     case EventType.$$anonymous$$ouseDrag:
         if (GUIUtility.hotControl == controlID)
         {
             Vector2 vector = GUI._Window.current.matrix.inverse.$$anonymous$$ultiplyPoint(GUIClip.GetAbsolute$$anonymous$$ousePosition() - windowDragState.dragStartPos);
             current.rect = new Rect(vector.x, vector.y, windowDragState.dragStartRect.width, windowDragState.dragStartRect.height);
             current.moved = true;
             Event.current.Use();
         }
         break;
     }
 }

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

92 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

EditorWindow not properly drawing 1 Answer

GenericMenu Renders Incorrectly On Second Monitor 0 Answers

EditorWindow.focusedWindow.SendEvent crashes Unity. 1 Answer

Is it possible to render a UnityAction field in a custom editor window? 0 Answers

Is there an event being fired off when the Inspector is being resized? 1 Answer


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