Hi! I have a problem creating a propertydrawer for my class. If I draw it without one it comes out fine, but if I put it in a foldout none of the fields can be selected.
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Rect rect = position;
label = EditorGUI.BeginProperty(position, label, property);
//rect = EditorGUI.PrefixLabel(rect, label);
property.isExpanded = EditorGUI.Foldout(rect, property.isExpanded, label);
EditorGUI.EndProperty();
if (!property.isExpanded)
{
return;
}
rect.yMin += height;
rect.xMin += 20;
rect = Utilities.FullLineProperty(rect, "name", property, height);
rect = Utilities.FullLineProperty(rect, "discoveryBrief", property, height);
rect = Utilities.FullLineProperty(rect, "discoveryDescription", property, height);
rect = Utilities.FullLineProperty(rect, "discoveryNarrative", property, NarrativeSectionEditor.height);
rect = Utilities.FullLineProperty(rect, "clueBrief", property, height);
rect = Utilities.FullLineProperty(rect, "clueNarrative", property, NarrativeSectionEditor.height);
rect = Utilities.FullLineProperty(rect, "rewardRP", property, height);
rect = Utilities.FullLineProperty(rect, "hasCreatureData", property, height);
rect = Utilities.FullLineArrayProperty(rect, "tasks", property, height);
}
utilities:
static public Rect FullLineProperty(Rect rect, string propertyName, SerializedProperty property, int height)
{
SerializedProperty prop = property.FindPropertyRelative(propertyName);
EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, height), prop);
rect.y += height;
return rect;
}
static public Rect FullLineArrayProperty(Rect rect, string propertyName, SerializedProperty property, int height)
{
SerializedProperty prop = property.FindPropertyRelative(propertyName);
// do a label and a size field
EditorGUI.LabelField(new Rect(rect.x, rect.y, 150, height), prop.displayName);
//prop.arraySize = EditorGUI.IntField(new Rect(rect.x + rect.width/2, rect.y, rect.width / 2, height), prop.arraySize);
if (GUI.Button(new Rect(rect.x + 150, rect.y, height, height), "+"))
{
prop.arraySize++;
}
for (int i = 0; i < prop.arraySize; i++)
{
EditorGUI.PropertyField(new Rect(rect.x, rect.y + (i + 1) * height, rect.width - height, height), prop.GetArrayElementAtIndex(i));
if (GUI.Button(new Rect(rect.x + rect.width - height, rect.y + (i + 1) * height, height, height), "-"))
{
prop.DeleteArrayElementAtIndex(i);
}
}
rect.y += height * (prop.arraySize + 1);
return rect;
}