Version: 2022.3

Vector2Int

struct in UnityEngine

切换到手册

描述

使用整数的 2D 向量和点表示形式。

此结构用于在某些情况下表示不需要浮点精度的 2D 位置和向量。

静态变量

downShorthand for writing Vector2Int(0, -1).
leftShorthand for writing Vector2Int(-1, 0).
oneShorthand for writing Vector2Int(1, 1).
rightShorthand for writing Vector2Int(1, 0).
upShorthand for writing Vector2Int(0, 1).
zeroShorthand for writing Vector2Int(0, 0).

变量

magnitude返回该向量的长度。(只读)
sqrMagnitude返回该向量的平方长度。(只读)
this[int]分别使用 [0] 或 [1] 访问 x 或 y 分量。
x向量的 X 分量。
y向量的 Y 分量。

公共函数

Clamp将 Vector2Int 限制在 min 和 max 给定的边界内。
Equals如果对象相等,则返回 true。
GetHashCode获取 Vector2Int 的哈希代码。
Set设置现有 Vector2Int 的 x 和 y 分量。
ToStringReturns a formatted string for this vector.

静态函数

CeilToInt通过对每个值执行 Ceiling 操作将 Vector2 转换为 Vector2Int。
Distance返回 a 与 b 之间的距离。
FloorToInt通过对每个值执行 Floor 操作将 Vector2 转换为 Vector2Int。
Max返回由两个向量的最大分量组成的向量。
Min返回由两个向量的最小分量组成的向量。
RoundToInt通过对每个值执行 Round 操作将 Vector2 转换为 Vector2Int。
Scale将两个向量的分量相乘。

运算符

operator -将一个向量减去另一个向量。
operator !=如果向量不同,则返回 true。
operator *将向量乘以一个数值。
operator /将向量除以一个数值。
operator +将两个向量相加。
operator ==如果向量相等,则返回 true。
Vector2将 Vector2Int 转换为 Vector2。
Vector3Int将 Vector2Int 转换为 Vector3Int。