I can’t seem to get objects put inside a EditorGUILayout.BeginVertical(“Box”); to center. I have a Texture2D, Label, and Button. The Texture right justifies, the Label center justifies, and the button left justifies. How can I force all of these objects to display in the center of the box?
EditorGUILayout.BeginHorizontal ();
for (int i = 0; i < textureObjects.Length; i++){
EditorGUILayout.BeginVertical("Box");
textureObjects[i] = (Texture2D)EditorGUILayout.ObjectField ("", textureObjects[i], typeof(Texture2D), true, GUILayout.Width(100));
if(textureObjects[i])
EditorGUILayout.LabelField(textureObjects[i].name, GUILayout.Width(100));
else EditorGUILayout.LabelField("None", GUILayout.Width(100));
if (GUILayout.Button (new GUIContent("Delete","Delete texture"), GUILayout.Height (15), GUILayout.Width(75)))
deleteButtonTexture ();
EditorGUILayout.EndVertical();
if ((i+1) % 3 == 0){
EditorGUILayout.EndHorizontal ();
EditorGUILayout.BeginHorizontal ();
}
}
EditorGUILayout.EndHorizontal ();

I tried putting just the texture in another EditorGUILayout.BeginHorizontal (); and added GUILayout.Space(30); inline after it. It centers it but only because it makes the “Box” bigger by 30 pixels. It’s as if there is a mandatory 30 pixel space in front of the Texture.
Anyone have any ideas?
You could try GUILayout.FlexibleSpace() left and right of your ObjectField, inside a horizontal group. But if you want perfect layout control, you can’t use the auto-layout system, but have to calculate your Rects, using the window’s position.width and GUIStyle.CalcSize.
Thanks for the reply. It didn’t solve the problem, however, when I was researching your suggestion, I found a solution that works for me. As a test I tried to use Space() like css in HTML. It just seemed like there was a “margin” in front of the texture. so I did this:
EditorGUILayout.BeginVertical("Box");
EditorGUILayout.BeginHorizontal ();
GUILayout.Space(-15);
textureObjects[i] = (Texture2D)EditorGUILayout.ObjectField ("", textureObjects[i], typeof(Texture2D), true, GUILayout.Width(100));
EditorGUILayout.EndHorizontal ();
...
EditorGUILayout.EndVertical();
Putting a -15 in the Space() removed the margin in front of the Texture. A hack? Maybe, but it now looks how I want it to. I also added GUILayout.Space(15); in front of the button to move it into place.
