static float3 lastMouseSpinViewPos;
var delta = Input.mousePosition - lastMouseSpinViewPos;
The following compiler error occurs:
Operator '-' is ambiguous on operands of type 'Vector3' and 'float3'
The reason is that the compiler doesn't know if it should implicitly convert the first operand to float3, or implicitly convert the second operand to Vector3.
Expected Behavior
My expectation is that Unity.Mathematics types should assume priority in this case: the first operand is converted to float3 and the result type is a float3. I'm not sure if there's a valid case for expecting behavior favoring Vector3, and if there were, it could be achieved by using explicit (Vector3) cast or type definition. Seeking a legacy Vector3 result is an edge case and is well-suited to be delegated to an explicit cast condition.
Cause of Problem
Input.mousePosition is a unity built-in property or field, so its type is Vector3
There are no explicit arithmetic operator implementations for VectorX types and floatX types.
Proposed solution
For the sake of streamlining interoperability with Unity built-in class Vector types, I think it makes sense to provide explicit implementations of arithmetic and comparison operators, like so:
public static float3 operator +(Vector3 l, float3 r) { return (float3)l + r; }
public static float3 operator -(Vector3 l, float3 r) { return (float3)l - r; }
public static float3 operator +(float3 l, Vector3 r) { return l + (float3)r; }
public static float3 operator -(float3 l, Vector3 r) { return l - (float3)r; }
Workaround
Add explicit typecast in all situations, like so:
static float3 lastMouseSpinViewPos;
var delta = (float3)Input.mousePosition - lastMouseSpinViewPos;
Given the following code snip:
The following compiler error occurs:
The reason is that the compiler doesn't know if it should implicitly convert the first operand to
float3
, or implicitly convert the second operand toVector3
.Expected Behavior
My expectation is that Unity.Mathematics types should assume priority in this case: the first operand is converted to
float3
and the result type is afloat3
. I'm not sure if there's a valid case for expecting behavior favoringVector3
, and if there were, it could be achieved by using explicit(Vector3)
cast or type definition. Seeking a legacyVector3
result is an edge case and is well-suited to be delegated to an explicit cast condition.Cause of Problem
Input.mousePosition
is a unity built-in property or field, so its type isVector3
VectorX
types andfloatX
types.Proposed solution
For the sake of streamlining interoperability with Unity built-in class Vector types, I think it makes sense to provide explicit implementations of arithmetic and comparison operators, like so:
Workaround
Add explicit typecast in all situations, like so: