I am currently doing a lot of 2D texture based work, for which I am currently using Vector2 to store x,y coordinates. However, due to Vector2's x and y being floats, I have to typecast a lot in my source. There is no use for the floating point because all of these all pixel based coordinates, and therefore whole numbers. I just use Vector2 because it is handy to store an x and y :)
Is there a class for this, or do I have to write my own struct for this?
There is no such class or struct built into Unity.
Easy to implement though (C#) ...
public struct IntVector2
{
int x;
int y;
int sqrMagnitude
{
get { return x * x + y * y; }
}
}
You would probably want to follow the example of Vector2 and implement as many of its methods as make sense for your application. I've shown sqrMagnitude as an example.
UPDATE: There has since been a Unity update where they added Vector2Int, Vector3Int, and Vector4Int classes with this type of functionality.
I was halfway through making my own structs when I updated unity and noticed Vector3Int autocompleting in intellisense, lol. Better late than never.
You may also use the handy Tuple class. While it may be better to implement the way others have suggested in many (perhaps all) circumstances, this way is still worth a mention.
Tuple<int, int> position = new Tuple<int,int>(5, 8);