Search Unity

EditorWindow closing when focus lost

Discussion in 'Immediate Mode GUI (IMGUI)' started by BubbaRichard, Apr 11, 2016.

  1. BubbaRichard

    BubbaRichard

    Joined:
    Jul 1, 2012
    Posts:
    51
    I have a EditorWindow shown with EditorWindow.Show() not ShowUtility(). On windows it works fine, I click away from it and it does not close but on Mac, it closes like I showed it with ShowUtility(). Why?

    TestWindow tw = (TestWindow)GetWindow(typeof(TestWindow));
    tw.Focus();
    tw.Show();
    tw.autoRepaintOnSceneChange = true;

    Does anyone have an idea to share here?

    Thanks,
    Bubba
     
  2. bloeys

    bloeys

    Joined:
    Aug 26, 2014
    Posts:
    57
    That is weird, if you don't find a solution for it you might want to file a bug report.
    As a side note, I think you should focus the window after you show it, not before.
     
  3. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    can you use this for a Single instance of your window?

    Code (csharp):
    1.  
    2. public class kissUITools : EditorWindow
    3. {
    4.     public static kissUITools win;
    5.  
    6.     //[MenuItem( "Tools/kissUI/Tools", false, 1100 )]
    7.     public static void ShowWindow ()
    8.     {
    9.         if( kissUITools.win == null )
    10.         {
    11.             //kissUITools.win = EditorWindow.GetWindow< kissUITools >();    //Shows existing window instance. If one doesn't exist, makes one.
    12.             kissUITools.win = EditorWindow.GetWindowWithRect< kissUITools >( new Rect(0,0, 215, 19), false, "Toolbox", true );
    13.        
    14.             kissUITools.win.Show();
    15.         }
    16.         else
    17.         {
    18.             kissUITools.win.Focus();
    19.         }
    20.      
    21.         kissUITools.win.wantsMouseMove = true;
    22.         //kissUITools.win.autoRepaintOnSceneChange = true;
    23.         EditorApplication.modifierKeysChanged += kissUITools.win.Repaint;
    24.     }
    25.  
    26.     //....
    27. }
    28.  
     
  4. BubbaRichard

    BubbaRichard

    Joined:
    Jul 1, 2012
    Posts:
    51
    I'll try both as soon as I get to my computer. Thanks!
     
  5. BubbaRichard

    BubbaRichard

    Joined:
    Jul 1, 2012
    Posts:
    51
    Didn't work, I tried both and on the Mac, the window still disappears when you click away from it, still thanks for the suggestions! I guess I'm going to have to dock the window.
     
  6. BubbaRichard

    BubbaRichard

    Joined:
    Jul 1, 2012
    Posts:
    51
    Update: It doesn't close the window on the Mac, it puts it behind the Unity UI. It also does it to the inspector and any other floating dialog. The problem is, I need to drag materials from the project view to the Custom editor so, that will not work. I'm going to have to dock but I can't find a way to dock with the inspector, only with the SceneView.
     
  7. educaPix

    educaPix

    Joined:
    Apr 8, 2016
    Posts:
    26
    Hi,

    Yes, in Mac the windows are separated from the main one. I use the next code to open and dock my custom window (in Multi Screenshots Suite) with the inspector... but you can also do it manually if you want... just drag and drop.

    // Dock with inspector
    MS_EditorWindow window = (MS_EditorWindow)EditorWindow.GetWindow<MS_EditorWindow>("MS Suite", true, typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow"));
    window.Show();
     
  8. bloeys

    bloeys

    Joined:
    Aug 26, 2014
    Posts:
    57
    It feels weird to me to have to dock windows to use them properly, isn't there a way to just have a floating window?
    Sometimes you need more space to work in.
     
  9. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    i have an older laptop, and slightly overlapping, floating, window panels help allot while using it. Makes me feel like i have more screen space than i really do. :D

    ex:
     
  10. BubbaRichard

    BubbaRichard

    Joined:
    Jul 1, 2012
    Posts:
    51
    IzzySoft, is that in Windows or Mac? Can't tell :)
    EducaPix, thanks a lot, I will try to give it a try as soon as I get a chance!
    Bloeys, that's my feeling on the matter but it push the Floating window behind the UnityUI when it's not docked on Mac.
    Thanks to Everybody!
     
  11. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Windows 10
     
  12. educaPix

    educaPix

    Joined:
    Apr 8, 2016
    Posts:
    26
    I just realise that the "Build Settings" window stay on top in Mac, so it seems possible to apply that behaviour to the Game window... I will try to find out how :)
     
  13. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    Does Unity editor use a ScriptableWizard ( an EditorWindow ) for the Build Settings?
     
  14. BubbaRichard

    BubbaRichard

    Joined:
    Jul 1, 2012
    Posts:
    51
    IzzySoft likes this.
  15. educaPix

    educaPix

    Joined:
    Apr 8, 2016
    Posts:
    26
    Maybe it's an option to open a custom Game window using ScriptableWizard...
    A quick workaround it's to open Unity in full screen. I have just tested that in this case all windows stays on top.
     
  16. atkhy

    atkhy

    Joined:
    Dec 24, 2018
    Posts:
    1
    @BubbaRichard In fact, all you need to do is :
    TestWindow tw = (TestWindow)GetWindow(typeof(TestWindow), true);
     
  17. BubbaRichard

    BubbaRichard

    Joined:
    Jul 1, 2012
    Posts:
    51
    When I asked this question in 2016, that was not the answer. I can't tell you why 3 years latter but I do remember trying that.