I’m building an open source asset to add some attributes, as the ones available (Naughty Attributes and Unity Editor Toolbox) didn’t cover all my needs.
I’m currently working on a [ShowIf]
attribute and its variants and I’m making my life harder by considering non-serialized values as in:
[SerializeField] [ShowIf(nameof(_teste2))]
private bool _test1;
private bool _teste2;
I can access the fields of a object if I initialize it with a given type:
System.Object obj = new PlayerController();
var fields = HelperMethods.GetAllFields(obj, f => f.IsPrivate);
foreach (var item in fields)
{
print(item);
}
But I can’t do the same inside the drawer, as I can’t initialize it with predefined class, even with the knowledge I gained looking here and here.
var comparisonAttribute = attribute as ConditionalAttribute;
System.Object propertyObj = HelperMethods.GetTargetObjectOfProperty(property);
BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
var fields = propertyObj.GetType().GetFields(flags);
Debug.Log(propertyObj);
foreach (var item in fields)
{
Debug.Log(item);
}
Debug.Log(fields.Length);
All I’m getting now is the type, where I can only access the property’s field, as the console print can show.
I’ll be very grateful by any help anyone can provide.