I’ve built a bunch of monobehaviours that I’m using purely to edit game data.
I’m trying to avoid duplicating field references, so I can add/change stuff later without it being a total nightmare.
My first question is, does anyone have a good approach to avoiding duplication when an inspector is using FindProperty( fieldname ) – at least something where changing the fieldname itself can be handled through automated refactoring (like resharper’s name change). Is there some unity magic or just general cleverness that can avoid the duplication?
My second question, is it possible to work with serialized properties such that they’re writing to a field not contained directly in the editor Target object? So for example:
class A : MonoBehaviour{
public X MyX;
[Serializable]
class X{
public int XsIntField;
}
}
[CustomEditor(typeof(A)), CanEditMultipleObjects]
class AEditor : Editor{
public override void OnInspectorGUI() {
serializedObject.Update();
// is there any way to do this?
EditorGUILayout.PropertyField( serializedObject.FindProperty( "MyX.XsIntField" ) )
serializedObject.Apply...
}
}
So here FindProperty would get MyX, then get the XsIntField from MyX.
Or … is there some better way to approach this?