Initial Commit

This commit is contained in:
Simeon Radivoev 2022-02-12 12:53:50 +02:00
commit ee5c2f922d
Signed by: simeonradivoev
GPG key ID: 7611A451D2A5D37A
2255 changed files with 547750 additions and 0 deletions

View file

@ -0,0 +1,39 @@
using UnityEngine;
namespace DefaultNamespace
{
public static class Vector2Extension
{
public static Vector2 Rotate(this Vector2 v, float degrees)
{
var sin = Mathf.Sin(degrees * Mathf.Deg2Rad);
var cos = Mathf.Cos(degrees * Mathf.Deg2Rad);
var tx = v.x;
var ty = v.y;
v.x = cos * tx - sin * ty;
v.y = sin * tx + cos * ty;
return v;
}
public static bool InRange(this Vector2Int pos, Vector2Int size)
{
return pos.x >= 0 && pos.x < size.x && pos.y >= 0 && pos.y < size.y;
}
public static Vector2Int Translate(this Vector2Int pos, int x, int y)
{
return new Vector2Int(pos.x + x, pos.y + y);
}
public static Vector2Int To2DIndex(this int value, int width)
{
return new Vector2Int(value % width, Mathf.FloorToInt(value / (float)width));
}
public static int ToIndex(this Vector2Int value, int width)
{
return value.y * width + value.x;
}
}
}