- Home /
How do I change WindowEditor's GUILayout?
Hi, I wanted to resize the Editor Fields to something like in the image.
Vector3 fields => Shorten down to a certain size. Align everything to the left.
Could anyone guide me on this?
editorquestion.jpg
(62.0 kB)
Comment
Best Answer
Answer by numberkruncher · Nov 24, 2013 at 12:55 AM
You can pass GUILayout.Width(100)
, with custom values naturally, into your various GUI controls to explicitly specify widths within your GUI:
GUILayout.Button("Foo", GUILayout.Width(100));
Though I would recommend using absolute positioning instead where it comes to more complicated user interfaces like the one in your screenshot. Use the layout engine to get the overall rectangle, and then manually offset within those bounds.
float itemHeight = 100;
float spacing = 10;
float itemOffset = itemHeight + spacing;
Rect totalRect = GUILayoutUtility.GetRect(0, itemHeight * itemCount);
// Position of current item (first item).
Rect position = new Rect(totalRect.x, totalRect.y, totalRect.width, itemHeight);
for (int i = 0; i < itemCount; ++i) {
GUI.Box(position, "Test");
// Advance position for next item.
position.y += itemOffset;
}