I have created a very simple property drawer to test this:
I use the position passed into the property drawer to both draw a foldout, and to draw a box styled label.
The same position RECT is used to draw both, and I expected the result to look similar to the position as defined in the docs:
Note that in this image (from Unity - Scripting API: EditorGUI.Foldout), the position.xMin is to the left of the triangle indicator.
However, my tests show the position differently! In this test, the position.XMin is to the RIGHT of the triangle indicator. So, it appears, the indicator is NOT actually drawn inside the specified position Rect.
Below is the entirety of my test project. Can someone else confirm they get the same results, and/or explain what I’m misunderstanding?
TestMono.cs
using UnityEngine;
[System.Serializable]
public class PropTestClass
{
string a;
}
public class TestMono : MonoBehaviour {
public PropTestClass p;
}
Editor\ TestMonoPropertDrawer.cs
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(PropTestClass))]
public class TestMonoPropertDrawer : PropertyDrawer
{
bool showDetailsFlag;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Debug.Log("foldout position" + position.ToString());
showDetailsFlag = EditorGUI.Foldout(position, showDetailsFlag, new GUIContent("test Label"), false);
Debug.Log("box position" + position.ToString());
EditorGUI.LabelField(position, GUIContent.none, GUI.skin.box);
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return 20;
}
}
Edit: Both Debug.Log calls, in the property drawer, show the exact same position Rect value.