I am trying to create a lot of windows and sort them automatically.
But I found the size of any window is wrong.
Rect newR = GUILayout.Window(i, new Rect(triggerGroupManager.triggerGroupList[i].posInEditor.x, triggerGroupManager.triggerGroupList[i].posInEditor.y, 0, 0), DrawTriggerGroup, "" + i);
I use GUILayout system to create contents in windows. So the size of window should be fit the contents, which is smart. But I found the width or height of variable newR is 0 as the beginning.
Plz help me, I am wondering to get the real size of a window.
So, the Rect you are passing to the [GUILayout.Window](http://docs.unity3d.com/ScriptReference/GUILayout.Window.html) function is defined as follows:
// Width and Height are 0!
Rect windowRect = new Rect(triggerGroupManager.triggerGroupList[i].posInEditor.x, triggerGroupManager.triggerGroupList[i].posInEditor.y, 0, 0);
Rect newR = GUILayout.Window(i, windowRect, DrawTriggerGroup, "" + i);
You’re passing 0 for width and height. Are you actually seeing something on-screen when the code runs?
Thanks for replying.
As the Unity guide says : The layouting system will attempt to fit the window inside it - if that cannot be done, it will adjust the rectangle to fit.
I am using GUILayout functions to draw my GUI, so that everything in this window works fine and smart. But the Rect value is same with I defined before. windowRect equals “new Rect(triggerGroupManager.triggerGroupList_.posInEditor.x, triggerGroupManager.triggerGroupList*.posInEditor.y, 0, 0)”*_ Actually, I want to get the real rect size, so that I can sort all windows one by one.
First off, I don’t think you answered my question: Are you actually seeing something on-screen when the code runs?
I’m asking this because in theory a sub-window of size (0,0) will not be visible. Nowhere does the documentation say that “specifying a size of 0 will cause the window to autofit”, which I think is what you’re assuming/trying.
Yes, it does indeed say that. However, I interpret that to imply that the layouting system will shrink the content if the specified size is too large for the specified area. This is why I asked if
I would suggest trying the following:
// Width and Height are set to the entire size of the containing window!
Rect windowRect = new Rect(triggerGroupManager.triggerGroupList[i].posInEditor.x, triggerGroupManager.triggerGroupList[i].posInEditor.y, position.width, position.height);
Rect newR = GUILayout.Window(i, windowRect, DrawTriggerGroup, "" + i);
Note that you could also do something like position.width/numHorizontalSubWindows (and similar for height).
But, again, when you use a size of (0,0), Are you actually seeing something on-screen when the code runs?
Yes. The window shows well no-matter the size is (0,0). But It is that drives me crazy. Because I can’t get the real size of any window if the content of window is a little more.
I tried “position.width/numHorizontalSubWindows” way. But if the content is larger than size, windows are covered by others.
Glad to hear that it worked! I suspect that internally, the following code exists somewhere:
//NOTE: this is pseudocode.
Rect actualRect = GetActualRect(userRect);
return Mathf.MinRect(actualRect, userRect);
So if you were to pass in (0,0), the MinRect would always be the one you passed in…
Which sounds like a bug, honestly - either in implementation or in documentation. Could you file a bug with Unity on this one? Do so by selecting Help→Report a Bug… from within Unity. Then they could either fix it to work with your expectations or adjust the documentation!