PropertyDrawer with a Generic List Property?

I’ve been working on a PropertyDrawer for my Attribute class:

[System.Serializable]
public class Attribute : IGUIItemInfo
{
	public EAttributeName 	attributeName;
	public float			max;
	public float 			current;
	public float			baseValue;	
	public List<Modifier> 	mods;

My issue is with the mods property. With the default inspector I can see the mods just fine. When I try to add them to my custom PropertyDrawer, I just see a fold icon and no contents:

EditorGUI.PropertyField (r, property.FindPropertyRelative ("mods"), GUIContent.none);

The default shows up as follows:

9578-untitled.png

The custom one shows this:

9579-untitled2.png

How would I code for the mods to show up like the first example?

I'm looking for a way to make property drawers for a List too. No luck so far!

2 Answers

2

Simply don’t forget to set the latest parameter of method EditorGUI.PropertyField :

EditorGUI.PropertyField ( ..., includeChildren:true );

Yep, that should do ^^. +1

4 hours... thank you very much..

Necro revival -- but damn man, thanks! :D

The default one uses an array, not a list. That’s why it has a set size which you must define at the start. Lists are dynamic, they can change sizes easily, but regular arrays are not.

You can change this by switching this:

public List<Modifier> mods;

to this:

public Modifier[] mods;

If you aren’t familiar with arrays, be sure to read up on them.

http://docs.unity3d.com/ScriptReference/Array.html

Although I would guess more of the problem is in understanding what makes properties appear that way in the editor, not how arrays work. :slight_smile: