Class GridUtility
Static utility class providing Grid coordinate conversions. All methods are Burst-compatible and can be used in Unity Jobs.
Inherited Members
Namespace: Unity.Tilemaps.Experimental
Assembly: Unity.2D.Tilemap.Experimental.dll
Syntax
[BurstCompile]
public static class GridUtility
Fields
kGridEpsilon
Epsilon value for near-zero comparisons in grid calculations.
Declaration
public const float kGridEpsilon = 1E-05
Field Value
| Type | Description |
|---|---|
| float |
Methods
CellSwizzle(Swizzle, in float3, out float3)
Applies a swizzle transformation to reorder the components of a position.
Declaration
[BurstCompile]
public static void CellSwizzle(GridData.Swizzle swizzle, in float3 position, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData.Swizzle | swizzle | The swizzle mode to apply. |
| float3 | position | The position to swizzle. |
| float3 | result | The swizzled position. |
CellToLocal(in GridData, in int3, out float3)
Converts an integer cell position to local space.
Declaration
[BurstCompile]
public static void CellToLocal(in GridData gridData, in int3 cellPosition, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| int3 | cellPosition | The integer cell position. |
| float3 | result | The local space position. |
CellToLocalInterpolated(in GridData, in float3, out float3)
Converts a floating-point cell position to local space.
Declaration
[BurstCompile]
public static void CellToLocalInterpolated(in GridData gridData, in float3 cellPosition, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| float3 | cellPosition | The floating-point cell position. |
| float3 | result | The local space position. |
CellToWorld(in GridData, ref TransformHandle, in int3, out float3)
Converts an integer cell position to world space.
Declaration
public static void CellToWorld(in GridData gridData, ref TransformHandle transformHandle, in int3 cellPosition, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| TransformHandle | transformHandle | The TransformHandle for the Grid. |
| int3 | cellPosition | The integer cell position. |
| float3 | result | The world space position. |
GetBoundsLocal(in GridData, in float3, in float3, out float3, out float3)
Gets the local-space bounds for a region defined by origin and size.
Declaration
[BurstCompile]
public static void GetBoundsLocal(in GridData gridData, in float3 origin, in float3 size, out float3 center, out float3 extents)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| float3 | origin | The origin of the region in cell space. |
| float3 | size | The size of the region in cells. |
| float3 | center | Output bounds center. |
| float3 | extents | Output bounds extents (half-size). |
GetBoundsLocal(in GridData, in int3, out float3, out float3)
Gets the local-space bounds for a cell position.
Declaration
[BurstCompile]
public static void GetBoundsLocal(in GridData gridData, in int3 cellPosition, out float3 center, out float3 extents)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| int3 | cellPosition | The cell position. |
| float3 | center | Output bounds center. |
| float3 | extents | Output bounds extents (half-size). |
GetCellCenterLocal(in GridData, in int3, out float3)
Gets the cell center position in local space for an integer cell position.
Declaration
[BurstCompile]
public static void GetCellCenterLocal(in GridData gridData, in int3 position, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| int3 | position | The integer cell position. |
| float3 | result | The cell center in local space. |
GetCellStride(in GridData, out float3)
Gets the stride between cells (cellSize + cellGap).
Declaration
[BurstCompile]
public static void GetCellStride(in GridData gridData, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| float3 | result | The cell stride. |
GetInvCellStride(in GridData, out float3)
Gets the inverse of the cell stride with epsilon-guarded reciprocal. Returns zero for components where the stride is near zero.
Declaration
[BurstCompile]
public static void GetInvCellStride(in GridData gridData, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| float3 | result | The inverse cell stride. |
GetLayoutCellCenter(in GridData, out float3)
Gets the cell center offset in cell space for the current layout. Rectangle/Isometric/IsometricZAsY: (0.5, 0.5, 0.5). Hexagon: (0, 0, 0).
Declaration
[BurstCompile]
public static void GetLayoutCellCenter(in GridData gridData, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| float3 | result | The cell center in cell space. |
GetPointCount(in GridData)
Gets the number of vertices that define a cell outline. Hexagon: 6. All others: 4.
Declaration
[BurstCompile]
public static int GetPointCount(in GridData gridData)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
Returns
| Type | Description |
|---|---|
| int | The number of cell outline points. |
InverseCellSwizzle(Swizzle, in float3, out float3)
Applies the inverse swizzle transformation. Note: YZX and ZXY are inverses of each other; all others are self-inverse.
Declaration
[BurstCompile]
public static void InverseCellSwizzle(GridData.Swizzle swizzle, in float3 position, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData.Swizzle | swizzle | The swizzle mode to invert. |
| float3 | position | The position to inverse-swizzle. |
| float3 | result | The inverse-swizzled position. |
LocalToCell(in GridData, in float3, out int3)
Converts a local space position to an integer cell position.
Declaration
[BurstCompile]
public static void LocalToCell(in GridData gridData, in float3 localPosition, out int3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| float3 | localPosition | The local space position. |
| int3 | result | The integer cell position. |
LocalToCellInterpolated(in GridData, in float3, out float3)
Converts a local space position to a floating-point cell position.
Declaration
[BurstCompile]
public static void LocalToCellInterpolated(in GridData gridData, in float3 localPosition, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| float3 | localPosition | The local space position. |
| float3 | result | The floating-point cell position. |
LocalToWorld(ref TransformHandle, in float3, out float3)
Transforms a position from local space to world space.
Declaration
public static void LocalToWorld(ref TransformHandle transformHandle, in float3 localPosition, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| TransformHandle | transformHandle | The TransformHandle for the Grid. |
| float3 | localPosition | The local space position. |
| float3 | result | The world space position. |
WorldToCell(in GridData, ref TransformHandle, in float3, out int3)
Converts a world space position to an integer cell position.
Declaration
public static void WorldToCell(in GridData gridData, ref TransformHandle transformHandle, in float3 worldPosition, out int3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| GridData | gridData | Grid configuration data. |
| TransformHandle | transformHandle | The TransformHandle for the Grid. |
| float3 | worldPosition | The world space position. |
| int3 | result | The integer cell position. |
WorldToLocal(ref TransformHandle, in float3, out float3)
Transforms a position from world space to local space.
Declaration
public static void WorldToLocal(ref TransformHandle transformHandle, in float3 worldPosition, out float3 result)
Parameters
| Type | Name | Description |
|---|---|---|
| TransformHandle | transformHandle | The TransformHandle for the Grid. |
| float3 | worldPosition | The world space position. |
| float3 | result | The local space position. |