#PropertyDrawer

1 messages · Page 1 of 1 (latest)

dusky idol
#

if you've never done this sort of thing, you're probably gonna struggle a little bit

#

feel free to ask any questions you have

rough pulsar
rough pulsar
dusky idol
#

no problem

rough pulsar
#

truly a madlad

dusky idol
#

PropertyDrawers use SerializedProperty instead of direct object references

#

i'd suggest reading the documentation for SerializedProperty and SerializedObject to understand it better

rough pulsar
#

yep! im there now

dusky idol
#

in the case of a PropertyDrawer when you see this line:

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
dusky idol
#

the property means the instance the type that the drawer is targetting

#

in your case you had an array of Display or whatever you named your type

#

the drawer will target each of the array elements

#

you can access the fields in your Display class by getting them as SerializedPropertys using the field names

#

so you'd do something like

property.FindPropertyRelative("_displayType");
property.FindPropertyRelative("_name");
#

or whatever names you used for the fields

rough pulsar
dusky idol
#

yeah Unity uses the serialized versions of the data in the IMGUI stuff

#

and because you don't get the actual field type you need to use the SerializedProperty stuff to get the values

#

so instead of

Display.name

you'd need to do something like:

property.FindPropertyRelative("_name").stringValue;
#

another way to let Unity automatically handle SerializedProperties is using a PropertyField:
EditorGUILayout.PropertyField(property.FindPropertyRelative("amount"));

#

it's like a generic way of drawing a field, you could probably use this for your enum