Search Unity

GuiLayout.Window resizes my rect

Discussion in 'Immediate Mode GUI (IMGUI)' started by pahe, Feb 25, 2015.

  1. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Hi folks.

    I'm playing around with the editor and want to create a node based mission editor. The problem I have is that my editor is resizing my nodes to small rects (width 10, heigth 25). I haven't figured out why it does so though, as other windows are sized correctly (see screenshot):

    Bildschirmfoto 2015-02-25 um 17.42.31.png

    The problem seems to be that GUILayout.Window(3, aRect, DrawNodeWindow, "myWindow"); always gives out a smaller rect, but why?

    My code is:

    Code (csharp):
    1.  
    2. public class MissionEditor : EditorWindow
    3. {
    4.    Rect window1 = new Rect(10, 10, 100, 100);
    5.    MissionData mission;
    6.  
    7.    [MenuItem("Mission Editor")]
    8.    private static void Init()
    9.    {
    10.       window = (MissionEditor)GetWindow(typeof(MissionEditor));
    11.       window.title = "Mission Editor";
    12.       mission = new MissionData();
    13.    }
    14.  
    15.    void DrawNodeWindow(int id)
    16.    {
    17.       GUI.DragWindow();
    18.    }
    19.  
    20.    private void OnGUI()
    21.    {
    22.       BeginWindows();
    23.  
    24.       window1 = GUI.Window(1, window1, DrawNodeWindow, "Window 1"); // test window
    25.  
    26.       if (Event.current.button == 1 && Event.current.type == EventType.MouseDown)
    27.       {
    28.          var aMenu = new GenericMenu();
    29.          aMenu.AddItem(new GUIContent("new gridelement"), false, delegate { mission.currentSelection = new MissionNode(0); });
    30.          aMenu.ShowAsContext();
    31.  
    32.          Event.current.Use();
    33.       }
    34.  
    35.       if (mission.currentSelection != null)
    36.       {
    37.          var aRect = mission.currentSelection.nodeRect;
    38.          aRect = GUILayout.Window(3, aRect, DrawNodeWindow, "myWindow"); // window always resized...
    39.  
    40.          if (aRect.width >= 100 && aRect.height >= 100)
    41.          {
    42.             aBattleGrid.currentSelection.nodeRect = aRect;
    43.          }
    44.          else
    45.             Debug.LogError("wrong size!");
    46.  
    47.          //window2 = GUI.Window(2, window2, DrawNodeWindow, "Window 2"); // this works, why not the above?
    48.       }
    49.       EndWindows();
    50.    }
    51. }
    52.  
    MissionData has nothing more that a reference to a class container (currentSelection) with a rect.

    Anyone a tip what could be the problem here?

    Thanks for help!
     
  2. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    Ok, figured it out myself. Problem is that I use GUILayout.Window the second time, not GUI.Window. So the solution would be, either to setup the GUILayout before or just to use the GUI.Window without the layout.

    Well.... sometimes you just have to write it a second time to see the actual problem ;)