Unity provides implicit casts between most of the Vector classes. This is nice in most situations, but is making debugging a nightmare for some of my code. I wrote conversion methods that accept an Axis parameter which allows the user to specify which values to use when converting between Vectors. Ex:
Vector2 myVec2 = new Vector3(1, 2);
Vector3 myVec3 = myVec2.ToVector3(Axis.Y, 0f); // myVec3 == [1, 0, 2]
Vector2 andBack = myVec3.ToVector2(Axis.Y); // now is [1, 2] again
Vector2 implCst = myVec3; // I'd like this to throw an exception
The trouble is that if I forget to cast, or incorrectly apply math between Vector3 and Vector2 (which is allowed because of implicit casting) variables I get incorrect values.
I'd like to disable implicit conversions for just the Vector classes. Is this possible?
↧