- Home /
Draw PropertyDrawers in PropertyDrawers?
I have a Profile Class which right now has no custom editor. it holds a List. SkillGroup holds List and some stuff. Skill has some stuff (ints, enums)
Now I followed these tutorials to build a custom inspector for my skill, easy. Then by making my skillgroup into a monobehaviour, I was able to make a CustomEditor for it and had it draw the list of skills using their PropertyDrawer. Great. Now, SkillGroup shouldn't be a monobehaviour, and I want the customEditor to be for Profile, drawing all the skillgroups and skills and whatnot. So I'm trying to make a SkillGroup CustomDrawer, but I can't seem to draw the skill customDrawers. Here's what I got.
[CustomPropertyDrawer(typeof(SkillGroup))]
public class SkillGroupDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
int lines = property.FindPropertyRelative("Skills").arraySize;
return 16f + 18f + 18f + (18f * lines);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
int indent = EditorGUI.indentLevel;
label = EditorGUI.BeginProperty(position, label, property);//tells the label this is a property, so stuff should have proper content menu
position.height = 16f;
//name
EditorGUI.PropertyField(position, property.FindPropertyRelative("Name"), GUIContent.none);
//skill label
position.y += position.height;
SerializedProperty list = property.FindPropertyRelative("Skills");
EditorGUI.PropertyField(position, list);//Draws foldout, array name
//size label
position.y += position.height;
SerializedProperty size = list.FindPropertyRelative("Array.size");//shows "special relative path" for Array.size, stores property
EditorGUI.PropertyField(position, size);//draw size field as serializesProperty
//items
EditorGUI.indentLevel++;
for (int i = 0; i<list.arraySize; i++)//foreach item in list.array
{
position.y += position.height;
//THIS NEXT LINE SHOULD DRAW THE PROPERTYDRAWER!
EditorGUI.PropertyField(position, list.GetArrayElementAtIndex(i));//draw the item in the array
}
EditorGUI.indentLevel--;
EditorGUI.EndProperty();
EditorGUI.indentLevel = indent;//reset indent
}
}
end result should be:
ProfileEditor
profileName
add'l profile info
SkillGroups
skillGroupDrawer
GroupName
- Skills
size
skillDrawer
skilldrawer
skilldrawer
skillGroupDrawer
GroupName
- Skills
size
skillDrawer
skilldrawer
skilldrawer
Your answer
Follow this Question
Related Questions
Custom Editor: Weird reset when clicking Play 1 Answer
Editor randomly unparents game object after InstantiatePrefab() & SetParent() in OnInspectorGUI() 0 Answers
Cloud recognition in Vuforia 0 Answers
Create Spells through classes in custom editor? 1 Answer
Initializing 2D array via inspector 3 Answers