Hi guys,
I’m trying to fake a dictionary in the inspector using an enum and an array. I got to the point where it looks (mostly) correct but when I override GetPropertyHeight it covers the foldout’s child and I can’t edit their values. Does anyone know a solution to this? Thanks in advance.
[15794-propertydrawer+bug.png|15794]ren
[CustomPropertyDrawer(typeof (NameListAttribute))]
public class NameListDrawer : PropertyDrawer
{
private NameListAttribute nameListAttribute { get { return ((NameListAttribute) attribute); }}
private bool foldout = false;
private const float ITEMSIZE = 15f;
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (foldout)
{
return base.GetPropertyHeight(property, label) + ITEMSIZE * Enum.GetNames(nameListAttribute.names).Length;
}
else
{
return base.GetPropertyHeight(property, label);
}
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
foldout = EditorGUI.Foldout(position, foldout, label);
if (foldout)
{
string[] names = Enum.GetNames(nameListAttribute.names);
for (int i = 0; i < names.Length; i++)
{
Rect rect = EditorGUI.IndentedRect(position);
rect.y += 15*(i + 1);
rect.height = 15f;
EditorGUI.PropertyField(rect, property.GetArrayElementAtIndex(i), new GUIContent(names*));*
}
}
}
}