Struct TileHandle
This struct is a utility struct that can be used as a pointer within the map grid. \n It holds a position and reference to the map and provides useful functions to interact with the underlying tile. \n User code should use this struct to interact with the underlying tile whenever possible.
Namespace: TycoonTerrain.Core
Assembly: TycoonTerrainAssembly.dll
Syntax
public struct TileHandle
Remarks
This struct is not intended to be stored in a member variable.
Fields
tilePosition
The tile position of the tile this handle refers to.
Declaration
public readonly int2 tilePosition
Field Value
| Type | Description |
|---|---|
| Unity. |
The tile position of the tile this handle refers to. |
Properties
BottomCenterPosition
Gets the bottom center position at the base of the tile in map space.
Declaration
public float3 BottomCenterPosition { get; }
Property Value
| Type | Description |
|---|---|
| Unity. |
The bottom center position at the base of the tile in map space. |
CenterSurfaceHeight
Gets the surface height of the tile center.
Declaration
public float CenterSurfaceHeight { get; }
Property Value
| Type | Description |
|---|---|
| Single | The surface height of the tile center. |
CenterSurfacePosition
Gets the center surface position of the tile in map space.
Declaration
public float3 CenterSurfacePosition { get; }
Property Value
| Type | Description |
|---|---|
| Unity. |
The center surface position of the tile in map space. |
IsCompletelySubmerged
Gets a value indicating whether the surface of this tile is completely submerged.
Declaration
public bool IsCompletelySubmerged { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
|
IsInBounds
Whether the current tile position lies within the map bounds.
Declaration
public bool IsInBounds { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
|
IsWaterLevelBelowSurface
Gets a value indicating whether the water level of this tile is below the tile surface.
Declaration
public bool IsWaterLevelBelowSurface { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
|
IsWaterLevelSurfaced
Gets a value indicating whether this instance is water level surfaced.
Declaration
public bool IsWaterLevelSurfaced { get; }
Property Value
| Type | Description |
|---|---|
| Boolean |
|
WaterLevel
Gets the water level.
Declaration
public ushort WaterLevel { get; }
Property Value
| Type | Description |
|---|---|
| UInt16 | The water level. |
Methods
FromCenter(float3)
Returns the position of the ray hit tile center with an optional offset.
Declaration
public float3 FromCenter(float3 offset = default(float3))
Parameters
| Type | Name | Description |
|---|---|---|
| Unity. |
offset | The offset from the center. |
Returns
| Type | Description |
|---|---|
| Unity. |
The map position that is offset from the tile center. |
GetClosestCorner(float2)
Returns the corner index closest to the local position.
Declaration
public CornerIndex GetClosestCorner(float2 localPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Unity. |
localPosition | The local tile position, where x and y are in the range [0,1]. |
Returns
| Type | Description |
|---|---|
| Corner |
The corner index closest to the local position. |
GetClosestEdge(float2)
Returns the edge direction closest to the local position.
Declaration
public CardinalDirection GetClosestEdge(float2 localPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Unity. |
localPosition | The local tile position, where x and y are in the range [0,1]. |
Returns
| Type | Description |
|---|---|
| Cardinal |
The direction of the closest edge. |
GetCorner(CornerIndex)
Gets the tile corner for the current tile.
Declaration
public TileCorner GetCorner(CornerIndex cornerIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| Corner |
cornerIndex | The corner index. |
Returns
| Type | Description |
|---|---|
| Tile |
The tile corner for the current tile at |
GetCornerPosition(CornerIndex)
Gets the corner position of the tile for a given corner index.
Declaration
public float3 GetCornerPosition(CornerIndex cornerIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| Corner |
cornerIndex | Index of the corner. |
Returns
| Type | Description |
|---|---|
| Unity. |
The corner position of the tile. |
GetData()
Gets the tile data.
Declaration
public LandTile GetData()
Returns
| Type | Description |
|---|---|
| Land |
The tile data. |
GetHeight(CornerIndex)
Gets the height of the specified tile corner.
Declaration
public byte GetHeight(CornerIndex cornerIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| Corner |
cornerIndex | The corner index. |
Returns
| Type | Description |
|---|---|
| Byte | The height of the corner. |
GetNeighbourOrDefault(CardinalDirection)
Gets the neighbour tile in a given direction if it exists or an invalid tile handle if the neighbouring tile does not exist.
Declaration
public TileHandle GetNeighbourOrDefault(CardinalDirection direction)
Parameters
| Type | Name | Description |
|---|---|---|
| Cardinal |
direction | The direction. |
Returns
| Type | Description |
|---|---|
| Tile |
The neighbour tile in |
GetSurfaceNormal(float2)
Sample the surface normal at the given local tile position.
Declaration
public float3 GetSurfaceNormal(float2 localPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Unity. |
localPosition | The local tile position, where x and y are in the range [0,1]. |
Returns
| Type | Description |
|---|---|
| Unity. |
GetSurfacePosition(float2)
Sample the surface position at the given local tile position.
Declaration
public float3 GetSurfacePosition(float2 localPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Unity. |
localPosition | The local tile position, where x and y are in the range [0,1]. |
Returns
| Type | Description |
|---|---|
| Unity. |
The map position of the surface on |
GetTilesInDirection(CardinalDirection, Int32)
Gets a specified number of tiles in a given direction, starting from the current tile.
Declaration
public IEnumerable<TileHandle> GetTilesInDirection(CardinalDirection direction, int length)
Parameters
| Type | Name | Description |
|---|---|---|
| Cardinal |
direction | The direction. |
| Int32 | length | The number of tiles to return. |
Returns
| Type | Description |
|---|---|
| IEnumerable<Tile |
The tiles in a given direction. |
IsEdgeFlush(CardinalDirection)
Returns true when the two corners of the neighbouring tile in the given direction are equal to the adjacent corners of this tile, false otherwise.
Declaration
public bool IsEdgeFlush(CardinalDirection direction)
Parameters
| Type | Name | Description |
|---|---|---|
| Cardinal |
direction | The direction to look for. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
IsWaterLevelAboveSurface(Int32)
Determines whether water level is above surface.
Declaration
public bool IsWaterLevelAboveSurface(int waterLevel)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | waterLevel | The water level. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
IsWithinCenter(float2, Single)
Gets whether the given local position is within the center of the tile considering the maximum distance from the center.
Declaration
public bool IsWithinCenter(float2 localPosition, float maxDistanceFromCenter)
Parameters
| Type | Name | Description |
|---|---|---|
| Unity. |
localPosition | The local tile position, where x and y are in the range [0,1]. |
| Single | maxDistanceFromCenter | The maximum distance to be considered within the tile center, in the range [0,1]. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Neighbours()
Gets the neighbouring tiles of this tile.
Declaration
public IEnumerable<TileHandle> Neighbours()
Returns
| Type | Description |
|---|---|
| IEnumerable<Tile |
A Tile |
SnapToCorners(float2)
Returns the local position snapped to the closest tile corner.
Declaration
public float3 SnapToCorners(float2 localPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Unity. |
localPosition | The local tile position, where x and y are in the range [0,1]. |
Returns
| Type | Description |
|---|---|
| Unity. |
The map position that is snapped to the nearest tile corner. |
SnapToEdge(float2, Single)
Returns the local position snapped to the closest tile edge. Optionally provide an horizontal offset.
Declaration
public float3 SnapToEdge(float2 localPosition, float offset = 0F)
Parameters
| Type | Name | Description |
|---|---|---|
| Unity. |
localPosition | The local tile position, where x and y are in the range [0,1]. |
| Single | offset | The horizontal offset. Negative offset moves the position further into the tile, a positive offset moves it further outwards. |
Returns
| Type | Description |
|---|---|
| Unity. |
The map position that is snapped to the nearest tile edge center. |
SnapToGrid(float2, Int32)
Returns the local position snapped to the center of the subgrid using the number of tile grid subdivisions.
Declaration
public float3 SnapToGrid(float2 localPosition, int numberOfSubdivisions)
Parameters
| Type | Name | Description |
|---|---|---|
| Unity. |
localPosition | The local tile position, where x and y are in the range [0,1]. |
| Int32 | numberOfSubdivisions | The number of sub divisions to snap to. |
Returns
| Type | Description |
|---|---|
| Unity. |
The map position that is snapped to the nearest subdivision. |
SnapToGrid(float2, Int32, float2)
Returns the local position snapped to the center of the subgrid using the number of tile grid subdivisions and a local offset.
Declaration
public float3 SnapToGrid(float2 localPosition, int numberOfSubdivisions, float2 localOffset)
Parameters
| Type | Name | Description |
|---|---|---|
| Unity. |
localPosition | The local tile position, where x and y are in the range [0,1]. |
| Int32 | numberOfSubdivisions | The number of sub divisions to snap to. |
| Unity. |
localOffset | The local offset within the sub grid in the range [0,1] for x and y. |
Returns
| Type | Description |
|---|---|
| Unity. |
The map position that is snapped to the nearest subdivision. |
TryGetNeighbour(CardinalDirection, out TileHandle)
Try to retrieve the neighbouring tile of the current tile. Will return true if there is a neighbour in that direction, false otherwise.
Declaration
public bool TryGetNeighbour(CardinalDirection direction, out TileHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| Cardinal |
direction | The direction to look for a neighbour relative to this tile. |
| Tile |
handle | The resulting tile handle if a neighbour exists. An invalid tile handle if no neighbour exists. |
Returns
| Type | Description |
|---|---|
| Boolean |
|