Files
match3-unity/Assets/Scripts/Utils/Vector2IntUtils.cs
2025-12-17 06:34:57 +08:00

23 lines
753 B
C#

using UnityEngine;
namespace Utils {
public static class Vector2IntUtils {
public static bool Compare(this Vector2Int a, Vector2 b) {
Vector2 aVector2 = new Vector2(a.x, a.y);
return Vector2.Distance(aVector2, b) < 0.01f;
}
public static Vector2 ToVector2(this Vector2Int v) {
return new Vector2(v.x, v.y);
}
public static Vector2Int ToVector2Int(this Vector2 v) {
return new Vector2Int((int)v.x, (int)v.y);
}
public static bool IsAdjacent(this Vector2Int a, Vector2Int b) {
Vector2Int d = b - a;
return (Mathf.Abs(d.x) == 1 && d.y == 0) || (Mathf.Abs(d.y) == 1 && d.x == 0);
}
}
}