Support tuple conversion and deconstruction of vector

Please add implicit conversion and deconstruct between tuple and vector

int3 i3 = (1,2,3);
var (a,b,c) = i3; // (int,int,int)
float3 f3 = (1,2,3);
var (x,y,z) = f3; // (float,float,float)

(x,z) = f3.normalized.xz;

var location = new float2(a,c) + (x,z); // implicit conversion from (float,float) to float2
1 Like

It could be kinda nice, but also kinda confusing. I thought about patching them into unity.mathematics but decided I don’t care enough to maintain a modified package.

Annoyingly, there’s already two ways to construct math structs - new float3(x, y, z), math.float3(x, y, z) - apparently to make porting of shaders easier. With C#9 target-typed expressions, now there’s a third syntax - float3 x = new(x, y, z). Not sure if we need more.

You can use them like this, they could be useful:

As for deconstructors, you can implement them yourself for any type using extension methods. These are nice but not very IDE friendly (at least in Rider it’s hard/impossible to navigate to the implementation).

1 Like