GUI.Layout layering

Help the noob! Save the GUI!

I have a GUI “panel” that includes a png square overlaid by other png elements. Initially I had built this with GUI and absolute values for placement, allowing me to align the png elements on top of the square.

I changed my build to GUILayout because the panel needs to be movable, BUT now I can’t figure out how to align elements on top of one another using GUILayout.

Here’s my original GUI code:

GUI.Box (Rect (10, 36, 287, 82), "", floorbox);
GUI.Box (Rect (17, 42, 113, 71), "", floor1);
GUI.Label (Rect (70, 70, 20, 20), "1", floorLabelON);
GUI.Button (Rect (138, 42, 61, 71), "", floor2);
GUI.Label (Rect (160, 70, 20, 20), "2", floorLabel);
GUI.Button (Rect (215, 83, 24, 23), "", floor3);
GUI.Label (Rect (223, 87, 20, 20), "3", floorLabel);
GUI.Button (Rect (250, 83, 24, 23), "", floor4);
GUI.Label (Rect (258, 87, 20, 20), "4", floorLabel);

Resulting in:

My GUILayout code:

GUILayout.Box ("", floorbox, GUILayout.Width (287), GUILayout.Height (82));
GUILayout.Box ("", floor1, GUILayout.Width (113), GUILayout.Height (71));
GUILayout.Label ("1", floorLabelON);
GUILayout.Button ("", floor2, GUILayout.Width (61), GUILayout.Height (71));
GUILayout.Label ("2", floorLabel);
GUILayout.Button ("", floor3, GUILayout.Width (24), GUILayout.Height (23));
GUILayout.Label ("3", floorLabel);
GUILayout.Button ("", floor4, GUILayout.Width (24), GUILayout.Height (23));
GUILayout.Label ("4", floorLabel);

Obviously resulting in:

I tried mixing GUI and GUILayout and, while initially the panel looked right, as soon as I turn on another panel this one gets bumped down the screen. The GUI elements don’t get bumped because of the absolute values.

Ideas?

I don’t quite know what you mean by ‘on top of one another’, as I don’t see that in your picture. The layer facilities come into play when using separate and distinct OnGUI() calls in different scripts.

From the look of your picture, you want to explore using BeginHorizontal instead.

Thanks for the response, Quietus.

I am using BeginHorizontal (I just clipped the relevant code). I want to place the shapes on top of the box, BeginHorizontal aligns them in a horizontal row, but won’t draw one shape on top of another.

Beginarea() takes a texture. Use that for the background of the individual elements. Iirc, Beginarea() is required for beginhorizontal() to work anyhow.

If that’s not possible and you need to use layers, then you need to use separate scripts for each layer rendered.

Just thinking along with you, why not use a GUI.Window or GUI.Begingroup() instead? With those you can easily move/control all the content in you floormap.