RectUtils
static
RectUtils is a static class, which returns grid positions instead of CellData for rectangular grids. It can be used if you don't wish to store your data with TilemapExtended but still want access to most utility methods.
Properties
Public
Name | Type | Description |
---|---|---|
NeighbourPositions | Vector3Int[] | Array holding all neighbour directions |
NeighbourNonDiagonalPositions | Vector3Int[] | Array holding neighbour directions without diagonals |
Public static methods
GetNeighbourPositions
public static Vector3Int[] GetNeighbourPositions(Vector3Int center)
Returns an array containing the north, south, east and west neighbour positions of the given grid position.
Parameters
center
: The grid position the fetch the neighbours from.
GetAllNeighbourPositions
public static Vector3Int[] GetAllNeighbourPositions(Vector3Int center)
Returns an array containing all eight neighbour positions, including diagonals, of the given grid position.
Parameters
center
: The grid position the fetch the neighbours from.
GetNeighbourPositionsInRadius
public static List<Vector3Int> GetNeighbourPositionsInRadius(Vector3Int center, int radius)
Returns a list containing all neighbour position of the given grid position within a given radius. This includes diagonals.
Parameters
center
: The grid position the fetch the neighbours from.radius
: The radius of the circle from the center.
GetRing
public static List<Vector3Int> GetRing(Vector3Int center, int radius)
Returns a list of positions on a ring around a given center with a given radius.
Parameters
center
: The center position of the ring.radius
: The radius of the ring from the center position.
GetDistance
public static int GetDistance(Vector3Int start, Vector3Int destination)
Returns the distance in the grid between two grid positions.
Parameters
start
: The starting grid position.destination
: The target grid position.
GetEuclideanDistance
public static float GetEuclideanDistance(Vector3Int start, Vector3Int destination)
Returns the euclidean distance between two grid positions. This method is useful when more exact distances are needed (for example in pathfinding). Keep in mind, that this method is computationally more expensive than GetDistance().
Parameters
start
: The starting grid position.destination
: The target grid position.
GetLine
public static List<Vector3Int> GetLine(Vector3Int start, Vector3Int destination)
Returns a list of positions under a direct line between two grid positions. The line includes both start and end points.
Parameters
start
: The starting grid position.destination
: The target grid position.
GetLineNoDiagonals
public static List<Vector3Int> GetLineNoDiagonals(Vector3Int start, Vector3Int destination)
Returns a list of positions of one horizontal and one vertical line between two grid positions. The line includes both start and end points.
Parameters
start
: The starting grid position.destination
: The target grid position.
RoundToNearestPosition
public static Vector3Int RoundToNearestPosition(Vector3 position)
Returns to the nearest grid position from a given Vector3.
Parameters
position
: The position to round.