Dear Community,
I have programmed my own ‘EditorWindow’. In it I draw a table of bools like so:
I would like the horizontal row of numbers (starting with the label ‘x | z’) to be aligned with the rows of toggles beneath it. Because the numbers represent the x-coordinates for the toggles.
This is my code:
Please ignore the curly braces and such. It is a condensed script with only the important method show.
public class RoomEditorWindow : EditorWindow {
private Room target;
private bool[,] bools;
//here everything is drawn
private void OnGUI()
{
DrawObjectField();
if (target != null)
{
DrawHexTable();
DrawSelectButtons();
...
}
}
private void DrawHexTable()
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("x | z");
for (int i = 0; i < bools.GetLength(0); i++)
{
GUILayout.Label(i.ToString());
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginVertical();
for (int ir = 0; ir < bools.GetLength(1); ir++)
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField((target.rows - (ir + 1)).ToString());
for (int ic = 0; ic < bools.GetLength(0); ic++)
{
bools[ic, ir] = EditorGUILayout.Toggle(bools[ic, ir]);
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
}
//methods for drawing all the buttons etc.
private void DrawObjectField()
private void DrawSelectButtons()
...
}
Should I use EditorGUI, instead of EditorGUILayout? Or is there a way to manipulate the distance between members of a horizontal group? E.G. with GUIstyle? I haven’t really grasped the means to manipulate layout.
I’d be grateful for any help.