Struct HexTerrainSettings
Struct for storing hex terrain settings like TerrainSize, ChunkSize, HexRotation, HexLayout, etc.
Has methods for converting between pixel and cell coordinates, getting cell index by coordinates, etc.
Assembly: fwt.hexterrains.dll
Syntax
[BurstCompile]
[Serializable]
public struct HexTerrainSettings : IEquatable<HexTerrainSettings>
Fields
ChunkSize
Size of the chunk in cells (usually it's 16x16, because the chunk has one mesh and the amount of vertexes must be under 64000)
Declaration
Field Value
HexHeight
Height of the hexagon in world space.
Cell Height is a byte value that is multiplied by this value to get the height of the cell in world space.
Declaration
Field Value
HexLayout
HexLayout of the hexagon the terrain is composed of.
Declaration
public HexLayouts HexLayout
Field Value
HexRadius
Radius of the hexagon in world space. The half of the distance between two opposite corners of the hexagon.
Declaration
Field Value
HexRotation
HexRotation of the hexagon the terrain is composed of.
Declaration
public HexRotations HexRotation
Field Value
IsConnectedHorizontally
If true, the top and bottom edges of the terrain are seamlessly connected
Declaration
public bool IsConnectedHorizontally
Field Value
IsConnectedVertically
If true, the right and left edges of the terrain are seamlessly connected
Declaration
public bool IsConnectedVertically
Field Value
SlopeSize
Value from 0 to 1 (part of the Hex are that slopes take)
Declaration
[Tooltip("Value from 0 to 1 (part of the Hex are that slopes take)")]
[Range(0, 1)]
public float SlopeSize
Field Value
TerrainSize
Size of the terrain in cells (width and height).
Declaration
Field Value
Properties
CellsCount
Total mount of cells on terrain.
Declaration
public int CellsCount { get; }
Property Value
CellsPerChunk
Max amount of cells in one chunk.
Some chunks (at the edges of the terrain) may have less cells than this value.
Declaration
public int CellsPerChunk { get; }
Property Value
ChunksCount
Total number of chunks in the terrain
Declaration
public int ChunksCount { get; }
Property Value
ChunksGridSize
Size of the chunks grid (one item = one chunk)
Declaration
public int2 ChunksGridSize { get; }
Property Value
Default
returns a default HexTerrainSettings
Declaration
public static HexTerrainSettings Default { get; }
Property Value
TerrainAreaSize
Size of the rectangle area that the whole terrain occupies in world space.
Declaration
public float2 TerrainAreaSize { get; }
Property Value
Methods
CellIndexToPixel(int)
Calculates a cell coordinate by cell index,
then converts a cell coord to the world point (assuming the terrain origin is 0:0:0).
Clamps the coordinate to the terrain size, meaning takes into account if terrain's edges are connected or not
Declaration
[BurstCompile]
public float3 CellIndexToPixel(int cellIndex)
Parameters
| Type |
Name |
Description |
| int |
cellIndex |
|
Returns
ClampCellIndex(int)
Clamps the cell index to the terrain size.
Takes into account if Terrain's edges are connected or not.
Declaration
[BurstCompile]
public int ClampCellIndex(int cellIndex)
Parameters
| Type |
Name |
Description |
| int |
cellIndex |
Raw cell index (can be outside of terrain)
|
Returns
| Type |
Description |
| int |
clamped cell index
|
ClampChunkCoordinate(int2)
Declaration
[BurstCompile]
public int2 ClampChunkCoordinate(int2 chunkCoord)
Parameters
| Type |
Name |
Description |
| int2 |
chunkCoord |
|
Returns
ClampCoordinate(int2)
Takes a cell coordinate and wraps it around the terrain size
taking into account if terrain's edges are connected or not.
So if IsConnectedHorizontally is true, the x coordinate will be wrapped around the terrain's width,
If IsConnectedVertically is true, the y coordinate will be wrapped around the terrain's height.
Negative cell coordinates are also wrapped around.
Declaration
[BurstCompile]
public int2 ClampCoordinate(int2 cellCoord)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
raw cell coordinate
|
Returns
| Type |
Description |
| int2 |
clamped cell coordinate
|
CoordToPixel(int2)
Converts a cell coordinate to the world point (assuming the terrain origin is 0:0:0).
Clamps the coordinate to the terrain size, meaning takes into account if terrain's edges are connected or not
ClampCoordinate(int2)
Declaration
[BurstCompile]
public float3 CoordToPixel(int2 coord)
Parameters
| Type |
Name |
Description |
| int2 |
coord |
cell coordinate
|
Returns
| Type |
Description |
| float3 |
world point
|
CoordToPixelRaw(int2)
Converts a cell coordinate to the world point (assuming the terrain origin is 0:0:0).
Declaration
[BurstCompile]
public float3 CoordToPixelRaw(int2 coord)
Parameters
| Type |
Name |
Description |
| int2 |
coord |
cell coordinate
|
Returns
| Type |
Description |
| float3 |
world point
|
Equals(HexTerrainSettings)
Declaration
public bool Equals(HexTerrainSettings other)
Parameters
Returns
GetCellCoord(int)
Converts a cell index into a cell coordinate
Declaration
[BurstCompile]
public int2 GetCellCoord(int cellIndex)
Parameters
| Type |
Name |
Description |
| int |
cellIndex |
|
Returns
GetCellHeightInMeters(float)
Calculates a cell height in meters from the heightmap value
Declaration
[BurstCompile]
public float GetCellHeightInMeters(float cellHeight)
Parameters
| Type |
Name |
Description |
| float |
cellHeight |
heightmap value of the cell
|
Returns
| Type |
Description |
| float |
cell height in meters
|
GetCellIndex(int2)
Converts a cell coordinate to the cell index.
Takes into account if terrain's edges are connected or not
Declaration
[BurstCompile]
public int GetCellIndex(int2 cellCoord)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
cell coordinate
|
Returns
| Type |
Description |
| int |
cell index
|
GetCellIndexRaw(int2)
Converts a cell coordinate to the cell index.
Does NOT take into account if terrain's edges are connected or not
Declaration
[BurstCompile]
public int GetCellIndexRaw(int2 cellCoord)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
cell coordinate
|
Returns
| Type |
Description |
| int |
cell index
|
GetChunkCoord(int)
Converts a chunk index into a chunk coordinate (in chunks grid, not cells grid)
Declaration
[BurstCompile]
public int2 GetChunkCoord(int chunkIndex)
Parameters
| Type |
Name |
Description |
| int |
chunkIndex |
chunk index
|
Returns
| Type |
Description |
| int2 |
chunk coordinate in a chunks grid
|
GetChunkCoordByCellCoord(int2)
Returns chunk coordinate (in chunks grid) by cell coordinate (in cells grid)
Declaration
[BurstCompile]
public int2 GetChunkCoordByCellCoord(int2 cellCoord)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
|
Returns
GetChunkCoordByCellCoordRaw(int2)
Returns chunk coordinate for cell with a giving coord
Declaration
[BurstCompile]
public int2 GetChunkCoordByCellCoordRaw(int2 cellCoord)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
|
Returns
GetChunkIndex(int2)
Returns a chunk index of giving chunk coordinate (in chunks grid, not cells grid)
Declaration
[BurstCompile]
public int GetChunkIndex(int2 chunkCoord)
Parameters
| Type |
Name |
Description |
| int2 |
chunkCoord |
chunk coordinate in a chunks grid
|
Returns
| Type |
Description |
| int |
chunk index
|
GetChunkIndexByCellCoord(int2)
Returns a chunk index for cell at provided cell coordinate (not chunk coordinate)
Declaration
[BurstCompile]
public int GetChunkIndexByCellCoord(int2 cellCoord)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
|
Returns
GetChunkIndexByCellCoordRaw(int2)
Returns a chunk index for cell with a giving coordinate
Declaration
[BurstCompile]
public int GetChunkIndexByCellCoordRaw(int2 cellCoord)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
|
Returns
GetChunkIndexByCellIndex(int)
Returns a chunk index for giving cell index
Declaration
[BurstCompile]
public int GetChunkIndexByCellIndex(int cellIndex)
Parameters
| Type |
Name |
Description |
| int |
cellIndex |
|
Returns
GetChunksAdjacentToCell(int, out FixedArray8<int>, out int)
Declaration
[BurstCompile]
public bool GetChunksAdjacentToCell(int cellIndex, out FixedArray8<int> chunkIndexes, out int chunksCount)
Parameters
Returns
HasNeighbour(in int, in int)
Declaration
[BurstCompile]
public bool HasNeighbour(in int cellIndex, in int direction)
Parameters
| Type |
Name |
Description |
| int |
cellIndex |
|
| int |
direction |
|
Returns
HasNeighbour(in int2, in int)
Declaration
[BurstCompile]
public bool HasNeighbour(in int2 cellCoord, in int direction)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
|
| int |
direction |
|
Returns
IsCellInsideTheTerrain(int)
Checks if the cell index is inside the terrain.
Takes into account if terrain's edges are connected or not
Declaration
[BurstCompile]
public bool IsCellInsideTheTerrain(int cellIndex)
Parameters
| Type |
Name |
Description |
| int |
cellIndex |
|
Returns
IsCellInsideTheTerrain(int2)
Checks if the cell coordinate is inside the terrain.
Takes into account if terrain's edges are connected or not
Declaration
[BurstCompile]
public bool IsCellInsideTheTerrain(int2 cellCoord)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
|
Returns
PixelToCoord(float2)
Converts a world point to a cell coordinate (assuming the terrain origin is 0:0:0).
Declaration
[BurstCompile]
public int2 PixelToCoord(float2 pixel)
Parameters
| Type |
Name |
Description |
| float2 |
pixel |
world point
|
Returns
| Type |
Description |
| int2 |
cell coordinate
|
PixelToCoordRaw(float2)
Converts a world 2D point (without height) to a cell coordinate (assuming the terrain origin is 0:0:0).
Declaration
[BurstCompile]
public int2 PixelToCoordRaw(float2 pixel)
Parameters
| Type |
Name |
Description |
| float2 |
pixel |
world point
|
Returns
| Type |
Description |
| int2 |
cell coordinate
|
PixelToCoordRaw(float3)
Converts a world point to a cell coordinate (assuming the terrain origin is 0:0:0).
Declaration
[BurstCompile]
public int2 PixelToCoordRaw(float3 pixel)
Parameters
| Type |
Name |
Description |
| float3 |
pixel |
world point
|
Returns
| Type |
Description |
| int2 |
cell coordinate
|
ToString()
Declaration
public override string ToString()
Returns
Overrides
TryGetNeighbourCellCoord(int, int, out int2)
Declaration
[BurstCompile]
public bool TryGetNeighbourCellCoord(int cellIndex, int direction, out int2 neighbourCoordinate)
Parameters
| Type |
Name |
Description |
| int |
cellIndex |
|
| int |
direction |
|
| int2 |
neighbourCoordinate |
|
Returns
TryGetNeighbourCellCoord(in int2, in int, out int2)
Declaration
[BurstCompile]
public bool TryGetNeighbourCellCoord(in int2 cellCoord, in int direction, out int2 neighbourCoordinate)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
|
| int |
direction |
|
| int2 |
neighbourCoordinate |
|
Returns
TryGetNeighbourCellIndex(int, int, out int)
Declaration
[BurstCompile]
public bool TryGetNeighbourCellIndex(int cellIndex, int direction, out int neighbourCellIndex)
Parameters
| Type |
Name |
Description |
| int |
cellIndex |
|
| int |
direction |
|
| int |
neighbourCellIndex |
|
Returns
TryGetNeighbourCellIndex(int2, int, out int)
Declaration
[BurstCompile]
public bool TryGetNeighbourCellIndex(int2 cellCoord, int direction, out int neighbourCellIndex)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
|
| int |
direction |
|
| int |
neighbourCellIndex |
|
Returns
TryGetNeighbourChunkCoord(int2, int, out int2)
Declaration
[BurstCompile]
public bool TryGetNeighbourChunkCoord(int2 cellCoord, int direction, out int2 neighbourChunkCoord)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
|
| int |
direction |
|
| int2 |
neighbourChunkCoord |
|
Returns
TryGetNeighbourChunkIndex(int2, int, out int)
Declaration
[BurstCompile]
public bool TryGetNeighbourChunkIndex(int2 cellCoord, int direction, out int neighbourChunkIndex)
Parameters
| Type |
Name |
Description |
| int2 |
cellCoord |
|
| int |
direction |
|
| int |
neighbourChunkIndex |
|
Returns
WorldPosToPixelRaw(float3)
Converts a world position to its corresponding pixel coordinates in the hex grid layout.
Returns a raw coordinate, meaning it can be outside of the terrain size or negative.
Declaration
[BurstCompile]
public float3 WorldPosToPixelRaw(float3 worldPos)
Parameters
| Type |
Name |
Description |
| float3 |
worldPos |
The world position to convert, where the X and Z components represent the horizontal plane.
|
Returns
| Type |
Description |
| float3 |
A Unity.Mathematics.float3 representing the pixel coordinates corresponding to the specified world position. The
Y component is set to 0.
|
Implements
Extension Methods