Unity-Technologies / Unity.Mathematics

The C# math library used in Unity providing vector types and math functions with a shader like syntax
Other
1.38k stars 156 forks source link

DOTS-5107: Fix vector drawing in the inspector. #199

Closed unpacklo closed 2 years ago

unpacklo commented 2 years ago

It was possible for a vector to be marked as hidden in the inspector but still manually draw it in a custom drawer. When this happened, the property drawing was not correct because it would show some unrelated visible fields in place of the YZW fields of a vector.

Here is an example without the fix (see the YZ and YZW components of "Hidden int 3" and "Hidden Quaternion" respectively):

image

Here is the same example, but with the fix:

image

unpacklo commented 2 years ago

@amechtley I chatted with @pcosgrave regarding this fix and the duplicated code. Basically, we agreed that duplicating is a better fix than to expose a new MultiPropertyField with the property visibility as a parameter.

If we add a new API (or make the internals visible to Mathematics) the issue will be ensuring Mathematics has the correct version of the editor to call into that method. Since Mathematics supports all the way back to 2018.3, @pcosgrave and I agreed that it's far simpler to duplicate the code here in Mathematics than to add the new method and backport the fix to every editor version and ifdef the Mathematics code to handle both cases of where the editor has the API and when it doesnt.

unpacklo commented 2 years ago

The first commit of this PR fixed the issue with showing the wrong fields for the YZW components of a vector, but it didn't handle wide mode:

https://user-images.githubusercontent.com/3121968/136476245-0acdb356-f15c-4f05-bab7-49e12cbf19f7.mov

In order to handle wide mode and reduce the effort necessary to correspond the duplicated EditorGUI code here with the original, I've copied that code as faithfully as possible to make diffing easier. Now, I can handle wide mode:

https://user-images.githubusercontent.com/3121968/136476351-10ffeb1c-087e-45e0-aa25-1fd0ce4f3a9b.mov

There is a lot more duplicated code but it is all contained within EditorGUICopy that's internal to the Unity.Mathematics.Editor assembly.

unpacklo commented 2 years ago

Please raise any other concerns ASAP since I plan to merge this PR as soon as my trunk PR lands (not yet in merge queue at the time of this writing).