using UnityEngine; public static class Vector2Extensions { public static Vector2 Rotate(this Vector2 vector, float angle) { float cosAngle = Mathf.Cos(angle); float sinAngle = Mathf.Sin(angle); float xNew = cosAngle * vector.x - sinAngle * vector.y; float yNew = sinAngle * vector.x + cosAngle * vector.y; return new Vector2(xNew, yNew); } } public static class Vector2IntExtensions { public static Vector2Int Rotate60About(this Vector2Int vector, Vector2Int other) { var x = other.x + other.y - vector.y; var y = vector.x + vector.y - other.x; return new Vector2Int(x, y); } public static Vector2Int RotateNeg60About(this Vector2Int vector, Vector2Int other) { var x = vector.x + vector.y - other.x; var y = other.x + other.y - vector.y; return new Vector2Int(x, y); } public static Vector2Int Rotate120(this Vector2Int vector, int m, int n) { var x = m - vector.x - vector.y; var y = n + vector.x; return new Vector2Int(x, y); } public static Vector2Int RotateNeg120(this Vector2Int vector, int m, int n) { var x = vector.y - n; var y = m + n - vector.x - vector.y; return new Vector2Int(x, y); } public static Vector3 ToCartesianOrigin(this Vector2Int vector, Vector2Int origin, float isoGridSize) { Vector3 point = Vector3.zero; point.x = origin.x + 2 * vector.x * isoGridSize + vector.y * isoGridSize; point.y = origin.y + Mathf.Sqrt(3) * vector.y * isoGridSize; return point; } }