In its most open-ended form, my question is: What is the best way to modify the appearance of serialized properties in the editor, based on a combination of a PropertyAttribute and some additional custom logic?
I can also specify that the “additional logic” involves looking at other parts of the SerializedObject. ie: showing/hiding a field depending on the state of neighboring fields.
I’ve already achieved this with a custom editor, but I really want a simpler and more generalized solution so I can more easily apply the same concept to multiple types without having to create custom editors for each.
Here’s an example of my attempt using a custom property drawer, but it creates infinite recursion and crashes unity (calling PropertyField() calls back to this property drawer):
[CustomPropertyDrawer(typeof(ConditionalHide))]
public class PropDrawer_HideFromLevelSpec : PropertyDrawer
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
VisualElement element = new PropertyField(property); // <- causes infinite recursion, crashes unity
if (SomeAdditionalLogic(property.serializedObject))
element.AddToClassList("slizzard-hidden");
return element;
}
}
My next best idea is to just override the default editor and bake in my custom logic there, or maybe there’s a way to create a PropertyField element while ignoring some/all attributes?
I’m keen know if those more familiar with this stuff have any better ideas.
Bonus points if I can have multiple of these kinds of attributes on one field, each doing their own modifications, but I can live without that.
Thanks.