Hi, I’m from a small team that are developing a Reverse Tower Defense / RTS.
This is going to be hard to explain… So I’ll use an example to help:
Let’s say we have the following class:
public class AClass
{
public float fExample1;
}
Somewhere along editor scripts, we will do something like this (the GetName() instruction is my goal what I’d like, it’s just to help understanding):
AClass a = (AClass) target;
FieldInfo field = GetType().GetField(**a.fExample1.GetName()**);
SerializedProperty serProp = serializedObject.FindProperty(field.name);
We want to get a FieldInfo by using an instance of the same field in order to avoid hardcoding.
This way if we rename the field per say to fExample2 my code will refactor to this:
AClass a = (AClass) target;
FieldInfo field = GetType().GetField( a.fExample2.GetName() );
SerializedProperty serProp = serializedObject.FindProperty(field.name);
Why avoid the hardcoding if this is already kinda hardcoded?
In my development team we mainly use this for selective attributes. We have a structure for all units and as such, our Towers are also units.
We have several fields in [HideInInspector] and in the Inspector/Drawer, fields like the units they will spawn or the positions from which each tower throws bombs/arrows to you are only shown if the Unit represents a tower.