yasirkula / UnityRuntimeInspector

Runtime Inspector and Hierarchy solution for Unity for debugging and runtime editing purposes
MIT License
1.68k stars 135 forks source link

Members drawn out of order #19

Closed MitchellMarx closed 4 years ago

MitchellMarx commented 4 years ago

The Unity Inspector draws elements in the order they are declared. The runtime inspector draws elements based on their member type (variable, property, or method). Because the runtime inspector ignores the order that members are declared it is not possible to control the order that elements are drawn.

yasirkula commented 4 years ago

Yes, it's an issue I'm aware of. The fix would involve using Type.GetMembers or Type.FindMembers functions; I'd need to make a performance benchmark before using one of these functions.

yasirkula commented 4 years ago

Even when using GetMembers/FindMembers, the order of the fields/properties isn't preserved. For example, let's have the following variables:

public int field1;
public string Property1 { get; set; }
public bool field2;

It is not possible to preserve the order field1-Property1-field2. I've found the following SO entries in my research:

The second SO entry suggests a sort using MetadataToken. In my tests, I've observed that it sorts fields between themselves and properties between themselves; so it results in the order field1-field2-Property1, still not the correct order.

Please let me know if you find a working solution to this.

P.S. Even without using MetadataToken, my fields and properties were still sorted in the order they were declared. Was it not the case for you?

MitchellMarx commented 4 years ago

Unity seems to be using GetFields. https://github.com/Unity-Technologies/UnityCsReference/blob/e8c54a30091f27635429d92c320f70daaab9eacb/Editor/Mono/Inspector/MonoScriptInspector.cs#L99

I did see the fields getting sorted in the correct order.

yasirkula commented 4 years ago

RuntimeInspector also uses GetFields and GetProperties. Can you post a screenshot of your variables and how they look in RuntimeInspector?