similar to the question here, but now I am interested in a Generic List of these objects. I know that in the docs for PropertyDrawers they show that these do behave “mostly” well with things like Lists, and arrays, but how would I be able to do that with say a List from System.Collections.Generic?
I do end up using things like List quite a bit as it behaves well, and the added accessing/growth/Removing is great, but I would Like to be able to use the PropertyDrawers with them too.
even if someone could maybe say how the DefaultInspector calls the propertyField of the List it would be helpful.
the order of requirement are as follows:
- the class must be marked Serializable
- the editor must hold a SerializableObject (this can be grabbed in the OnEnable()
- get the List parent as a SerializableProperty
- then iterate over the List as follows:
Code:
//man is the class object pointer for the Custom editor. data is the List<>
//property is SerializedProperty of the list
property = obj.FindProperty("data");
for(int ii = 0; ii < man.data.Count; ii++){
if(property != null){
EditorGUI.PropertyField(GUILayoutUtility.GetRect(
(float)Screen.width, EditorGUI.GetPropertyHeight(property.GetArrayElementAtIndex(ii)) )
, property.GetArrayElementAtIndex(ii),new GUIContent(ii.ToString()));
}else{
// other editor code could go here
}
}