I’m working on a custom inspector and in an effort to tidy up the interface, I was wondering how to do staggered sublevels with the foldouts. Here’s an example clip from the scene hierarchy:
And here’s what I have in my inspector:
I’m using the EditorGUILayout classes and there doesn’t seem to be a way to indent things a fixed amount (you can fake it with labels by adding spaces, but the controls are still aligned with the left edge, and the foldout arrows don’t have integrated labels to pad).
I’ve been experimenting with the BeginHorizontal() calls but these seem to evenly space the controls across the inspector, with no ability to control the spacing. Any ideas?
So far as I can tell, the indent width seems to be about (exactly?) 15 pixels, and there’s a 4 pixel margin at the edge of windows. So, you should be able to use:
GUILayout.Space(indentLevel * 15 + 4);
to get the indent spacing you need for GUILayout controls (such as Button()).
Edit: Corrected the pixel count to 15 (had previously stated it was 16, but I’ve checked the source code and know better now).
Edit2: Corrected the formula to always add an additional 4 pixels to compensate for the EditorWindow margin (which is also ignored by GUILayout).
The key function in the above snippet is: recalculating the texPreviewRect using EditorGUI.IndentedRect(Rect source), for which i dont seem to find reference around the API, maybe its a new undocumented thing :), but basically it seems to applies the indentation to the passed rect value
I’m back! So, here’s what I ultimately decided is the most convenient way to do buttons in the Editor layout (short of Unity actually adding EditorGUILayout.Button):