Skip to main content

HexUtils

static

HexUtils is a static class, which returns grid positions instead of CellData for hexagonal 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
OffsetEvenNeighboursVector3Int[]Array holding neighbour directions in an even row
OffsetOddNeighboursVector3Int[]Array holding neighbour directions in an odd row
CubeDirectionalVectorsVector3Int[]Array holding neighbour directions in cube coordinates

Public static methods

OffsetToCube

public static Vector3Int OffsetToCube(Vector3Int offsetPosition)

Converts offset grid coordinates to cube coordinates.

Parameters

  • offsetPosition: The grid position in offset coordinates (how Unity stores/accesses tiles).

CubeToOffset

public static Vector3Int CubeToOffset(Vector3Int cubePosition)

Converts cube coordinates to offset coordinates.

Parameters

  • cubePosition: The grid position in cube coordinates.

GetNeighbourPositions

public static Vector3Int[] GetNeighbourPositions(Vector3Int center)

Returns an array containing 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.

RoundToNearestPosition

public static Vector3Int RoundToNearestPosition(Vector3 position)

Returns to the nearest grid position from a given Vector3.