PropertyAccessor.

GetField(Object) Method

Summary

Returns the InspectorGadgets.Editor.PropertyAccessor.Field if there is one or tries to get it from the object's type.

Syntax

public FieldInfo GetField(ref Object obj)

Examples

[Serializable]
public class InnerClass
{
    public float value;
}

[Serializable]
public class RootClass
{
    public InnerClass inner;
}

public class MyBehaviour : MonoBehaviour
{
    public RootClass root;
}

[UnityEditor.CustomEditor(typeof(MyBehaviour))]
public class MyEditor : UnityEditor.Editor
{
    private void OnEnable()
    {
        var serializedObject = new SerializedObject(target);
        var rootProperty = serializedObject.FindProperty("root");
        var innerProperty = rootProperty.FindPropertyRelative("inner");
        var valueProperty = innerProperty.FindPropertyRelative("value");

        var accessor = valueProperty.GetAccessor();

        object obj = target;
        var valueField = accessor.GetField(ref obj);
        // valueField is a FieldInfo referring to InnerClass.value.
        // obj now holds the ((MyBehaviour)target).root.inner.
    }
}

Remarks

If this accessor has a InspectorGadgets.Editor.PropertyAccessor.Parent, the `obj` must be associated with the root UnityEditor.SerializedProperty and this method will change it to reference the parent field's value.

Parameters

Name Type Description
obj Object

Return Value

Type Description
FieldInfo