If you have
public class Test : MonoBehaviour
{
public int x, y;
public Transform t;
public GameObject go;
}
In the inspector, you’ll see these fields in this exact order! My question is how?
doing a: typeof(Test).GetMembers()
isn’t guaranteed to return members the order they’re declared in (src)
My stab is that they either use MonoCecil somehow to get them in that order, or convert the class code to string, parse the code, use regex to get the fields’ names and then do type.GetField(name)
Edit: So in case of fields it seems that GetMembers
or GetFields
do indeed return the members/fields in the correct order. However; changing one of the fields to be a property will yield different results, i.e. a Transform t { get; set; } instead of
Transform t;
I asked in MonoCecil’s google group here if it could help or not, seems the only is via parsing the source code.