#PropertyDrawer
1 messages · Page 1 of 1 (latest)
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
been hesitating for too long unfortunately haha
thank you so much for all the links and helpful advice
no problem
truly a madlad
PropertyDrawers use SerializedProperty instead of direct object references
i'd suggest reading the documentation for SerializedProperty and SerializedObject to understand it better
yep! im there now
in the case of a PropertyDrawer when you see this line:
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
yep seeing it in the docs
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
ahh okay. i was a bit confused on how to reference stuff inside of the class i made into an array. this clears it up thank you
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