Multiple rows in guilayout / horizontal

Hey there,

Say I want to do a gui.layout based of an array which is 8 long, but I want them to be laid out in 2 rows of 4 instead of 1 row of 8, what would be the best way of doing this? (Currenly, I’m using beginhorizontal and begingroup to lay them out in a single row)

Use a nested combination of BeginVertical and BeginHorizontal:

GUILayout.BeginVertical(); // container for rows
  GUILayout.BeginHorizontal(); // container for row 1
    // draw first row components
  GUILayout.EndHorizontal();
  GUILayout.BeginHorizontal(); // container for row 2
    // draw second row components
  GUILayout.EndHorizontal();
GUILayout.EndVerticle();

If you need to, you can use GUILayout.Width to control the width of items in each row, to force them to line up.

You might also look at GUILayout.Toolbar (lays elements out in a row) and GUILayout.SelectionGrid (lays elements out in a NxM grid); they’re limited to providing a single selection from the set of options they display, but if that’s what you need to do it’s the easiest way to achieve it.