What do you call a map coordinate or 2D array index pair?
I'm looking for a better name than the lengthy "coordinate" to use when dealing with 2D arrays and the composite of the indices like so:
public class Map
{
public int x; // x coordinate
public int y; // y coordinate
byte[,] data;
public static Vector2 CoordinateToWorldPosition(IntVector2 mapCoordinate)
{
return Vector3.zero;
}
public static IntVector2 WorldPositionToCoordinate(Vector2 worldPosition)
{
return new IntVector2();
}
}
I basically only need this when returning both indices from a function at once, but that made me think that my naming is not yet perfect.
Answer by Jeshira · Jan 25, 2018 at 09:47 PM
C# naming convention advice against using abbreviation unless widely accepted, but a common accepted abbreviation used for coordinate is coord. There isn't any word it can be confused for.
public static Vector2 CoordToWorldPosition(Vector2Int _coord) {}
public static Vector2Int WorldPositionToCoord(Vector2 _position) {}
N.B. Vector2Int is an int-based Vector2 that is now part of Unity.
How to use [Vector2Int][1] ? Vector2 gridXY = new Vector2(0, 0) : O$$anonymous$$ Vector2Int gridXY = new Vector2Int(0, 0) : Visual Studio does not recognise it and Unity complain "The type or namespace name `Vector2Int' could not be found" Thanks [1]: https://docs.unity3d.com/ScriptReference/Vector2Int.html
Which Unity version of Unity do you use? This struct is available since Unity 2017.2 only.