I’m currently struggling with a weird issue on my property drawer.
I have this 3 lines of code to make an editor that looks like: [Variable][Predicates][Value]. For example I’ll have on my inspector: [Apple][Equals][3]
So I took the position.width and I divided by 3 to make that happen. Pretty simple but I can’t figured out why it’s getting buggy when the inspector indent my drawer.
It works only for the last one when there is no indentation.
Hum it fix the issue but the 3 fields are drawn like the last one on my screenshot, so it’s less readable.
I have a quick solution but I’m not really satisfied to not understand why it doesn’t work in the first place. So I calculated myself the gap between fields and I “adjust” the position from my fields. Here it’s the gap adjustement “float adjust = EditorGUI.indentLevel * 7.5f;”
Unity is Indenting the rect automatically for you. If you have access to a C# decompiler, like jetBrains dotPeek. You can see the internal method indents the supplied rectangle:
//UnityEdtitor.dll
public static int Popup(Rect position, int selectedIndex, GUIContent[] displayedOptions, [DefaultValue("EditorStyles.popup")] GUIStyle style)
{
return EditorGUI.DoPopup(EditorGUI.IndentedRect(position), GUIUtility.GetControlID(EditorGUI.s_PopupHash, FocusType.Keyboard, position), selectedIndex, displayedOptions, style);
}