slavniyteo / one-line

One line property drawer for Unity3d
MIT License
146 stars 12 forks source link

Set `FieldInfo` property of Custom Property Drawers #18

Closed slavniyteo closed 6 years ago

slavniyteo commented 6 years ago

I need to search about this field.

When I tried to use this field last time, it always was null.

Need to look inside UnityEditor.dll decompiled

slavniyteo commented 6 years ago

From decompiled internal UnityEditor.PropertyHandler:

public void HandleDrawnType(Type drawnType, Type propertyType, FieldInfo field, PropertyAttribute attribute) {
    Type drawerTypeForType = ScriptAttributeUtility.GetDrawerTypeForType(drawnType);
    if (drawerTypeForType != null) {
        if (typeof(PropertyDrawer).IsAssignableFrom(drawerTypeForType)) {
            if (propertyType == null || !propertyType.IsArrayOrList()) {
                this.m_PropertyDrawer = (PropertyDrawer)Activator.CreateInstance(drawerTypeForType);
                this.m_PropertyDrawer.m_FieldInfo = field;
                this.m_PropertyDrawer.m_Attribute = attribute;
            }
        }
    }
}

I see now, that PropertyDrawer.FieldInfo exists from Unity 5.0. So we need to move onto this rails.

Associated with #16

slavniyteo commented 6 years ago

We can not use FieldInfo from OneLine drawer, because, we recursively walk through types.

So I set fieldInfo property for custom drawers of nested fields.

Done with #20.