Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Operand ambiguity occurs when referencing built-in Vector types via arithmetic and comparison operators

Đang mở
#177 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp, unity
Lĩnh vực
computer-graphics

Hướng nghiên cứu

Bắt đầu bằng cách xác định các định nghĩa kiểu VectorX và floatX cùng các triển khai chuyển đổi và toán tử hiện có của chúng. Tái hiện ví dụ về Input.mousePosition và float3, sau đó xác minh rằng các biểu thức số học và so sánh liên quan được phân giải không mơ hồ và tạo ra kiểu kết quả Unity.Mathematics mong muốn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Given the following code snip:

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;
Ngôn ngữ chính
C#
Star
1.4k
Fork
159
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Unity-Technologies/Unity.Mathematics

Tất cả issue của Unity-Technologies/Unity.Mathematics

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.