Class TycoonTileMap
Main component for the terrain. This is responsible for storing the internal map state, executing terrain operations and converting between world space and map coordinates.
Inheritance
Namespace: TycoonTerrain.Core
Assembly: TycoonTerrainAssembly.dll
Syntax
[AddComponentMenu("Tycoon Tile/Tycoon Tile Map")]
[DisallowMultipleComponent]
public class TycoonTileMap : MonoBehaviour
Fields
ChunkSize
The number of tiles in both directions represented by a chunk.
Declaration
[Tooltip("The number of tiles in both directions represented by a chunk.")]
public int ChunkSize
Field Value
Type | Description |
---|---|
Int32 | The number of tiles in both directions represented by a chunk. |
Length
The number of tiles in the z direction.
Declaration
[Tooltip("The number of tiles in the z direction")]
public int Length
Field Value
Type | Description |
---|---|
Int32 | The number of tiles in the z direction. |
MaxHeight
The maximum number of steps tiles are allowed to be high.
Declaration
[Tooltip("The maximum number of steps tiles are allowed to be high.")]
public byte MaxHeight
Field Value
Type | Description |
---|---|
Byte | The maximum number of steps tiles are allowed to be high. |
WaterHeightStepsPerTileHeight
The number of water height steps there are within one tile height step.
Declaration
[Tooltip("The number of water height steps there are within one tile height step.")]
public int WaterHeightStepsPerTileHeight
Field Value
Type | Description |
---|---|
Int32 | The number of water height steps there are within one tile height step. |
Width
The number of tiles in the x direction.
Declaration
[Tooltip("The number of tiles in the x direction")]
public int Width
Field Value
Type | Description |
---|---|
Int32 | The number of tiles in the x direction. |
WorldHeightStep
The world height that is represented by a single height step.
Declaration
[Tooltip("The world height that is represented by a single height step.")]
public float WorldHeightStep
Field Value
Type | Description |
---|---|
Single | The world height that is represented by a single height step. |
Properties
Bounds
The bounds of the entire terrain.
Declaration
public IntBound Bounds { get; }
Property Value
Type | Description |
---|---|
IntBound | The tile bounds of the map. |
TypeTable
Gets the tile type table.
Declaration
public TerrainTypeTable TypeTable { get; }
Property Value
Type | Description |
---|---|
TerrainTypeTable | The tile type table. |
WaterHeightStep
The world height of a single water height step. This depends on the world height of a tile height step and the number of water height steps per tile height.
Declaration
public float WaterHeightStep { get; }
Property Value
Type | Description |
---|---|
Single | The height per water level in map space. |
Methods
Deserialize(BinaryReader)
Deserializes this Tycoon Tile component from the specified reader. All chunks will be marked dirty after deserialization.
Declaration
public void Deserialize(BinaryReader reader)
Parameters
Type | Name | Description |
---|---|---|
BinaryReader | reader | The binary reader from which to read the data. |
GetMapPosition(Vector3)
Returns the position within the terrain grid from a given world position.
Declaration
public float3 GetMapPosition(Vector3 worldPosition)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Vector3 | worldPosition | The world position. |
Returns
Type | Description |
---|---|
Unity.Mathematics.float3 | The position in map space for the given |
IsInBounds(int2)
Check if a certain position is within the map bounds.
Declaration
public bool IsInBounds(int2 pos)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.int2 | pos | The position. |
Returns
Type | Description |
---|---|
Boolean | True if the position is within the map bounds, false otherwise. |
MapToWorldPosition(float3)
Converts the given map position to the corresponding world position. The position will be scaled according to the map WorldHeightStep and the map transform.
Declaration
public float3 MapToWorldPosition(float3 mapPosition)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.float3 | mapPosition | The position in map space. |
Returns
Type | Description |
---|---|
Unity.Mathematics.float3 | The corresponding position in world space. |
RegisterDirtyChunkListener(IChunkListener)
Register a listener that will receive callbacks when chunks are marked dirty.
Declaration
public void RegisterDirtyChunkListener(IChunkListener listener)
Parameters
Type | Name | Description |
---|---|---|
IChunkListener | listener | The chunk listener. |
RegisterTileListener(IntBound, OnBoundsChangeCallback)
Adds the given callback handler to the collection.
Declaration
public CallbackHandle RegisterTileListener(IntBound bounds, OnBoundsChangeCallback callback)
Parameters
Type | Name | Description |
---|---|---|
IntBound | bounds | The bounds. |
OnBoundsChangeCallback | callback | The callback. |
Returns
Type | Description |
---|---|
CallbackHandle | A callback handle that can be used to UnregisterTileListener(CallbackHandle). |
RegisterTileListener(int2, OnBoundsChangeCallback)
Adds the given callback handler to the collection.
Declaration
public CallbackHandle RegisterTileListener(int2 tilePosition, OnBoundsChangeCallback callback)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.int2 | tilePosition | The tile position. |
OnBoundsChangeCallback | callback | The callback. |
Returns
Type | Description |
---|---|
CallbackHandle | A callback handle that can be used to UnregisterTileListener(CallbackHandle). |
ScaleMapHeight(float3)
Scales the given map position. The position will be scaled according to the map WorldHeightStep.
Declaration
public float3 ScaleMapHeight(float3 mapPosition)
Parameters
Type | Name | Description |
---|---|---|
Unity.Mathematics.float3 | mapPosition | The position in map space. |
Returns
Type | Description |
---|---|
Unity.Mathematics.float3 | The corresponding position in world space. |
ScheduleOperation<T>(T)
Schedule a terrain operation to this Tycoon Tile terrain instance.
Declaration
public void ScheduleOperation<T>(T operation)
where T : ITerrainOperation
Parameters
Type | Name | Description |
---|---|---|
T | operation | The terrain operation instance. |
Type Parameters
Name | Description |
---|---|
T | The operation type. |
Serialize(BinaryWriter)
Serializes this Tycoon Tile to the specified writer.
Declaration
public void Serialize(BinaryWriter writer)
Parameters
Type | Name | Description |
---|---|---|
BinaryWriter | writer | The writer to save the data to. |
UnregisterTileListener(CallbackHandle)
Removes the callback and its bounds from the collection.
Declaration
public void UnregisterTileListener(CallbackHandle handle)
Parameters
Type | Name | Description |
---|---|---|
CallbackHandle | handle | The callback handle for which to unsubscribe. |
WorldToTilePosition(Vector3)
Returns the tile position within this terrain of the given world position.
Declaration
public int2 WorldToTilePosition(Vector3 worldPosition)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.Vector3 | worldPosition | The world position. |
Returns
Type | Description |
---|---|
Unity.Mathematics.int2 | The tile position for the given |