Interface IHexTerrainAPI
Example implementation of the IHexTerrainAPI interface. Used to be injected into places outside the ECS World. Contains examples of how to read and write data from the TerrainEntity. Abstracts user code from the TerrainData storage (usually the Entity World). Provides an API for working with a terrain. Usually uses in a UserTools (brushes, etc.).
Namespace: Fwt.HexTerrains
Assembly: fwt.hexterrains.dll
Syntax
public interface IHexTerrainAPI
Methods
CreateNewTerrainEntity(Entity)
Creates a new terrain terrainEntity by instantiating provided prefab.
Declaration
Entity CreateNewTerrainEntity(Entity terrainPrefab)
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | terrainPrefab | prefab of the terrainEntity to create |
Returns
| Type | Description |
|---|---|
| Entity | instance of the created terrainEntity |
CreateNewTerrain<TPrefabConfig>(TPrefabConfig, HexTerrainSettings)
Creates a new terrain entity with the specified settings. Destroys existing terrain
Declaration
Entity CreateNewTerrain<TPrefabConfig>(TPrefabConfig terrainPrefabConfig, HexTerrainSettings terrainSettings) where TPrefabConfig : IHexTerrainPrefabConfig
Parameters
| Type | Name | Description |
|---|---|---|
| TPrefabConfig | terrainPrefabConfig | prefab config of the terrainEntity to create |
| HexTerrainSettings | terrainSettings | terrain settings to overwrite |
Returns
| Type | Description |
|---|---|
| Entity | instance of the created terrainEntity |
Type Parameters
| Name | Description |
|---|---|
| TPrefabConfig |
CreateUIScreen<TScreen>()
Creates a new screen of the specified type.
Declaration
TScreen CreateUIScreen<TScreen>() where TScreen : UIScreen
Returns
| Type | Description |
|---|---|
| TScreen | screen instance |
Type Parameters
| Name | Description |
|---|---|
| TScreen | type of the screen to create |
DestroyTerrain(Entity)
Destroys a terrain entity provided.
Declaration
bool DestroyTerrain(Entity terrainEntity)
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | terrainEntity | terrain entity to destroy |
Returns
| Type | Description |
|---|---|
| bool | true if was destroyed, otherwise - false |
DestroyUIScreen(UIScreen)
Destroys the specified screen instance.
Declaration
bool DestroyUIScreen(UIScreen screen)
Parameters
| Type | Name | Description |
|---|---|---|
| UIScreen | screen | screen instance to destroy |
Returns
| Type | Description |
|---|---|
| bool | true if the screen was destroyed successfully; otherwise, false |
DestroyUIScreen<TScreen>()
Destroys the specified screen.
Declaration
bool DestroyUIScreen<TScreen>() where TScreen : UIScreen
Returns
| Type | Description |
|---|---|
| bool | true if the screen was destroyed successfully; otherwise, false |
Type Parameters
| Name | Description |
|---|---|
| TScreen | type of a screen to destroy |
GetBrushColor()
Returns the brush color from the TerrainEntity HexTerrainBrush.
Declaration
Color32? GetBrushColor()
Returns
| Type | Description |
|---|---|
| Color32? | brush color if found, otherwise - false |
GetBrushOpacity()
Returns the brush opacity from the TerrainEntity HexTerrainBrush.
Declaration
float? GetBrushOpacity()
Returns
| Type | Description |
|---|---|
| float? | brush opacity if brush is found, otherwise - null |
GetBrushSize()
Returns the brush size from the TerrainEntity HexTerrainBrush.
Declaration
int? GetBrushSize()
Returns
| Type | Description |
|---|---|
| int? | brush size if found, otherwise - null |
GetBrushView()
Returns the brush view from the TerrainEntity HexTerrainBrushView.
Declaration
HexTerrainBrushView GetBrushView()
Returns
| Type | Description |
|---|---|
| HexTerrainBrushView | brush view from the TerrainEntity if found, otherwise - null |
GetCellArea<TAreasLayer>(int)
Returns the CellArea from terrain cell at the specified index.
Declaration
byte? GetCellArea<TAreasLayer>(int cellIndex) where TAreasLayer : HexByteAreasLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | cellIndex | cell index to get value from |
Returns
| Type | Description |
|---|---|
| byte? | CellArea if found or null if not found |
Type Parameters
| Name | Description |
|---|---|
| TAreasLayer | type of areas data layer to get value from |
GetCellBiome<TSurfaceData>(int)
Returns the biomes map value (byte) of the cell at the specified index.
Declaration
byte? GetCellBiome<TSurfaceData>(int cellIndex) where TSurfaceData : HexSurfaceLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | cellIndex | cell index to get a biome from |
Returns
| Type | Description |
|---|---|
| byte? | biome value if found or null if not found |
Type Parameters
| Name | Description |
|---|---|
| TSurfaceData | type of surface data to get biome from |
GetCellCoordUnderCursor()
Returns the cell coordinate under the cursor.
Declaration
int2? GetCellCoordUnderCursor()
Returns
| Type | Description |
|---|---|
| int2? | cell coordinate if found and raycast hit the terrain, otherwise - false |
GetCellEntity<TCellEntityLayer>(int)
Returns the CellEntity from terrain cell at the specified index.
Declaration
CellEntity? GetCellEntity<TCellEntityLayer>(int cellIndex) where TCellEntityLayer : CellEntitiesLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | cellIndex | cell index to get a CellEntity from |
Returns
| Type | Description |
|---|---|
| CellEntity? | CellEntity value if found, otherwise null |
Type Parameters
| Name | Description |
|---|---|
| TCellEntityLayer |
GetCellHeight<TSurfaceData>(int)
Returns the height map value (byte) of the cell at the specified index.
Declaration
byte? GetCellHeight<TSurfaceData>(int cellIndex) where TSurfaceData : HexSurfaceLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | cellIndex | cell index to get a height from |
Returns
| Type | Description |
|---|---|
| byte? | heightmap value if found or null if not found |
Type Parameters
| Name | Description |
|---|---|
| TSurfaceData | type of surface data to get height from |
GetCellIndexUnderCursor()
Returns the cell index under the cursor.
Declaration
int? GetCellIndexUnderCursor()
Returns
| Type | Description |
|---|---|
| int? | cell index if found and raycast hit the terrain, otherwise - false |
GetCellItem<TItemsLayer>(int)
Returns the CellItem from terrain cell at the specified index.
Declaration
CellItem? GetCellItem<TItemsLayer>(int cellIndex) where TItemsLayer : CellItemsLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | cellIndex | cell index to get a CellItem from |
Returns
| Type | Description |
|---|---|
| CellItem? | CellItem value if found, otherwise null |
Type Parameters
| Name | Description |
|---|---|
| TItemsLayer | type of cell items layer to get data from |
GetDataLayer<TDataLayer>()
returns a data layer from the TerrainEntity GetTerrainEntity()
Declaration
TDataLayer GetDataLayer<TDataLayer>() where TDataLayer : class
Returns
| Type | Description |
|---|---|
| TDataLayer | data layer if found, otherwise - null |
Type Parameters
| Name | Description |
|---|---|
| TDataLayer |
GetHexTerrainPrefabConfigsBuffer<THexTerrainPrefabConfig>()
Returns a list of available HexTerrainPrefabConfigs from the UserToolEntity (if any)
Declaration
DynamicBuffer<THexTerrainPrefabConfig> GetHexTerrainPrefabConfigsBuffer<THexTerrainPrefabConfig>() where THexTerrainPrefabConfig : unmanaged, IBufferElementData, IHexTerrainPrefabConfig
Returns
| Type | Description |
|---|---|
| DynamicBuffer<THexTerrainPrefabConfig> |
Type Parameters
| Name | Description |
|---|---|
| THexTerrainPrefabConfig | type of HexTerrainPrefabConfig you have |
GetHexTerrainPrefabConfigsList()
Returns a list of available HexTerrainPrefabConfigs from the UserToolEntity (if any). This list can be sent to the UI to display available terrain prefabs for the user to select from.
Declaration
IList<IHexTerrainPrefabConfig> GetHexTerrainPrefabConfigsList()
Returns
| Type | Description |
|---|---|
| IList<IHexTerrainPrefabConfig> | collection of hex terrain prefab configs for user to select from |
GetIsResizableBrush()
Returns true if the brush on TerrainEntity is resizable.
Declaration
bool GetIsResizableBrush()
Returns
| Type | Description |
|---|---|
| bool | is brush found and resizable |
GetIsTerrainVisible()
Returns true if terrain is visible, false is invisible, null if no terrain with visibility foundHexTerrainVisibility.
Declaration
bool? GetIsTerrainVisible()
Returns
| Type | Description |
|---|---|
| bool? | true if terrain is visible, false is invisible, null if no terrain with visibility found |
GetIsVisibleBrush()
Returns true if the brush on TerrainEntity is visible.
Declaration
bool GetIsVisibleBrush()
Returns
| Type | Description |
|---|---|
| bool | true if brush is found and is visible, otherwise - false |
GetOrCreateUIScreen<TScreen>()
Gets an existing screen of the specified type, or creates a new one if it doesn't exist.
Declaration
TScreen GetOrCreateUIScreen<TScreen>() where TScreen : UIScreen
Returns
| Type | Description |
|---|---|
| TScreen | screen instance |
Type Parameters
| Name | Description |
|---|---|
| TScreen | type of the screen to get or create |
GetRaycastData()
Returns the Raycast data from the TerrainEntity HexTerrainRaycastData. this data contains information about the raycast from mouse to terrain result.
Declaration
HexTerrainRaycastData? GetRaycastData()
Returns
| Type | Description |
|---|---|
| HexTerrainRaycastData? | raycast data from the TerrainEntity |
GetTerrainEntity()
Get the TerainEntity this API is working with.
Declaration
Entity GetTerrainEntity()
Returns
| Type | Description |
|---|---|
| Entity | terrain terrainEntity this API works with |
GetTerrainSettings()
Returns a Terrain Settings if found.
Declaration
HexTerrainSettings? GetTerrainSettings()
Returns
| Type | Description |
|---|---|
| HexTerrainSettings? | terrain settings if found or null if not found |
GetUIScreen<TScreen>()
Gets an existing screen of the specified type if found.
Declaration
TScreen GetUIScreen<TScreen>() where TScreen : UIScreen
Returns
| Type | Description |
|---|---|
| TScreen |
Type Parameters
| Name | Description |
|---|---|
| TScreen | type of the screen to get |
GetViewMode()
Returns the view mode of the TerrainEntity HexTerrainViewMode.
Declaration
byte GetViewMode()
Returns
| Type | Description |
|---|---|
| byte | view mode if found, otherwise - false |
IsLayerSupported<TDataLayer>()
Checks if the data layer is supported by the terrain. Usually means if terrain has this data layer.
Declaration
bool IsLayerSupported<TDataLayer>() where TDataLayer : class
Returns
| Type | Description |
|---|---|
| bool | true if supports, otherwise - false |
Type Parameters
| Name | Description |
|---|---|
| TDataLayer | type of the TerrainLayer to check |
LoadTerrain(string)
Loads the TerrainEntity from a file.
Declaration
bool LoadTerrain(string filePath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filePath | file path to load a terrain from |
Returns
| Type | Description |
|---|---|
| bool | true if loaded, otherwise - false |
ResizeTerrain(int2)
Resizes the TerrainEntity TerrainSize.
Declaration
bool ResizeTerrain(int2 terrainSize)
Parameters
| Type | Name | Description |
|---|---|---|
| int2 | terrainSize | new terrain size |
Returns
| Type | Description |
|---|---|
| bool | true if was resized, otherwise - false |
SaveTerrain(string)
Saves the TerrainEntity to a file.
Declaration
bool SaveTerrain(string filePath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filePath | file path to save a terrain into |
Returns
| Type | Description |
|---|---|
| bool | true if terrain has been saved, otherwise - false |
SetBrushColor(Color32)
Sets the brush color on the TerrainEntity HexTerrainBrush.
Declaration
bool SetBrushColor(Color32 color)
Parameters
| Type | Name | Description |
|---|---|---|
| Color32 | color | new brush color |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
SetBrushOpacity(float)
Sets the brush opacity on the TerrainEntity HexTerrainBrush.
Declaration
bool SetBrushOpacity(float opacity)
Parameters
| Type | Name | Description |
|---|---|---|
| float | opacity | new opacity value (0..1) |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
SetBrushSize(int)
Sets the brush size on the TerrainEntity HexTerrainBrush.
Declaration
bool SetBrushSize(int brushSize)
Parameters
| Type | Name | Description |
|---|---|---|
| int | brushSize | new brush size |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
SetCellArea<TAreasLayer>(int, byte)
Sets the CellArea from terrain cell at the specified index.
Declaration
bool SetCellArea<TAreasLayer>(int cellIndex, byte area) where TAreasLayer : HexByteAreasLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | cellIndex | cell index to set value on |
| byte | area | area value to set |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
Type Parameters
| Name | Description |
|---|---|
| TAreasLayer | type of areas data layer to set value on |
SetCellBiome<TSurfaceData>(int, byte)
Sets the biomes map value (byte) of the cell at the specified index.
Declaration
bool SetCellBiome<TSurfaceData>(int cellIndex, byte biome) where TSurfaceData : HexSurfaceLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | cellIndex | cell index to set a biome for |
| byte | biome | biome value to set |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
Type Parameters
| Name | Description |
|---|---|
| TSurfaceData | type of surface data to set biome for |
SetCellEntity<TCellEntityLayer>(int, CellEntity)
Sets the CellEntity from terrain cell at the specified index.
Declaration
bool SetCellEntity<TCellEntityLayer>(int cellIndex, CellEntity entity) where TCellEntityLayer : CellEntitiesLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | cellIndex | cell index to set CellEntity on |
| CellEntity | entity |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
Type Parameters
| Name | Description |
|---|---|
| TCellEntityLayer |
SetCellHeight<TSurfaceData>(int, byte)
Sets the height map value (byte) of the cell at the specified index.
Declaration
bool SetCellHeight<TSurfaceData>(int cellIndex, byte height) where TSurfaceData : HexSurfaceLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | cellIndex | cell index to set a height for |
| byte | height |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
Type Parameters
| Name | Description |
|---|---|
| TSurfaceData | type of surface data to set height for |
SetCellItem<TItemsLayer>(int, CellItem)
Sets the CellItem from terrain cell at the specified index.
Declaration
bool SetCellItem<TItemsLayer>(int cellIndex, CellItem item) where TItemsLayer : CellItemsLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | cellIndex | cell index to set CellItem on |
| CellItem | item | CellItem value to set on provided cellIndex on provided ItemsData layer |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
Type Parameters
| Name | Description |
|---|---|
| TItemsLayer | type of cell items layer to set value on |
SetIsResizableBrush(bool)
Sets the IsResizable value of the brush on TerrainEntity HexTerrainBrush.
Declaration
bool SetIsResizableBrush(bool isResizableBrush)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isResizableBrush | new value for IsResizable |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
SetIsTerrainVisible(bool)
Sets terrain visibility. HexTerrainVisibility Returns true if value was set
Declaration
bool SetIsTerrainVisible(bool isVisible)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isVisible | New visibility value for terrain |
Returns
| Type | Description |
|---|---|
| bool | True if value was set, otherwise - false |
SetIsVisibleBrush(bool)
Sets the IsVisible value of the brush on TerrainEntity HexTerrainBrush.
Declaration
bool SetIsVisibleBrush(bool isVisibleBrush)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isVisibleBrush | new IsVisible value |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
SetViewMode(byte)
Sets the view mode on the TerrainEntity HexTerrainViewMode.
Declaration
bool SetViewMode(byte viewMode)
Parameters
| Type | Name | Description |
|---|---|---|
| byte | viewMode | new view mode |
Returns
| Type | Description |
|---|---|
| bool | true if value has been set, otherwise - false |
ToggleIsTerrainVisible()
Toggles the visibility of the terrain on the TerrainEntity HexTerrainVisibility.
Declaration
bool? ToggleIsTerrainVisible()
Returns
| Type | Description |
|---|---|
| bool? | True if terrain now visible, false is invisible, null if no terrain with visibility found |