Class HexTerrainAPI
Example implementation of the IHexTerrainAPI interface. Used to be injected into places without access to the EntityManager. 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.).
Implements
Inherited Members
Namespace: Fwt.HexTerrains
Assembly: fwt.hexterrains.dll
Syntax
public class HexTerrainAPI : IHexTerrainAPI
Fields
_terrainPrefabConfigs
List of terrain prefab configs to be sent on UI, so user can choose from when creating a new terrain.
Declaration
protected IList<IHexTerrainPrefabConfig> _terrainPrefabConfigs
Field Value
| Type | Description |
|---|---|
| IList<IHexTerrainPrefabConfig> |
Properties
EntityManager
Cached EntityManager. Used to access the Entity World. Performs operations on the TerrainEntity TerrainEntity
Declaration
public EntityManager EntityManager { get; set; }
Property Value
| Type | Description |
|---|---|
| EntityManager |
TerrainEntity
Cached terrain terrainEntity. Feel free to replace it's value, as everything is extracted from Entity World using this terrainEntity for every API function call. So if this terrainEntity is changed, the API will work with a new terrainEntity. If this terrainEntity does not exist, the API calls will not work, but will not throw an exception.
Declaration
public Entity TerrainEntity { get; set; }
Property Value
| Type | Description |
|---|---|
| Entity |
UISystemAPI
Cached UISystemAPI. Used to access the UI system.
Declaration
public IUISystemAPI UISystemAPI { get; set; }
Property Value
| Type | Description |
|---|---|
| IUISystemAPI |
UserToolEntity
Cached UserToolEntity this user tool is controlled by
Declaration
public Entity UserToolEntity { get; set; }
Property Value
| Type | Description |
|---|---|
| Entity |
Methods
CreateNewTerrainEntity(Entity)
Creates a new terrain terrainEntity by instantiating provided prefab.
Declaration
public virtual 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
public virtual 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
public virtual 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
public virtual 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
public virtual 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
public virtual 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
public virtual Color32? GetBrushColor()
Returns
| Type | Description |
|---|---|
| Color32? | brush color if found, otherwise - false |
GetBrushOpacity()
Returns the brush opacity from the TerrainEntity HexTerrainBrush.
Declaration
public virtual float? GetBrushOpacity()
Returns
| Type | Description |
|---|---|
| float? | brush opacity if brush is found, otherwise - null |
GetBrushSize()
Returns the brush size from the TerrainEntity HexTerrainBrush.
Declaration
public virtual int? GetBrushSize()
Returns
| Type | Description |
|---|---|
| int? | brush size if found, otherwise - null |
GetBrushView()
Returns the brush view from the TerrainEntity HexTerrainBrushView.
Declaration
public virtual 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
public virtual 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 terrain layer to get value from |
GetCellBiome<TSurfaceData>(int)
Returns the biomes map value (byte) of the cell at the specified index.
Declaration
public virtual 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
public virtual int2? GetCellCoordUnderCursor()
Returns
| Type | Description |
|---|---|
| int2? | cell coordinate if found and raycast hit the terrain, otherwise - false |
GetCellEntity<TEntitiesLayer>(int)
Returns the CellEntity from terrain cell at the specified index.
Declaration
public virtual CellEntity? GetCellEntity<TEntitiesLayer>(int cellIndex) where TEntitiesLayer : 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 |
|---|---|
| TEntitiesLayer | type of cell terrainEntity layer to get data from |
GetCellHeight<TSurfaceData>(int)
Returns the height map value (byte) of the cell at the specified index.
Declaration
public virtual 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
public virtual 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
public virtual 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 TerrainEntity
Declaration
public virtual TDataLayer GetDataLayer<TDataLayer>() where TDataLayer : class
Returns
| Type | Description |
|---|---|
| TDataLayer |
Type Parameters
| Name | Description |
|---|---|
| TDataLayer |
GetHexTerrainPrefabConfigsBuffer<THexTerrainPrefabConfig>()
Returns a list of available HexTerrainPrefabConfigs from the UserToolEntity (if any)
Declaration
public virtual 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
public virtual 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
public virtual 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
public 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
public virtual 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
public virtual 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
public virtual HexTerrainRaycastData? GetRaycastData()
Returns
| Type | Description |
|---|---|
| HexTerrainRaycastData? | raycast data from the TerrainEntity |
GetTerrainEntity()
Returns the TerrainEntity this API is working with.
Declaration
public Entity GetTerrainEntity()
Returns
| Type | Description |
|---|---|
| Entity | terrain terrainEntity this API works with |
GetTerrainSettings()
Returns a Terrain Settings if found.
Declaration
public virtual 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
public virtual 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
public virtual byte GetViewMode()
Returns
| Type | Description |
|---|---|
| byte | view mode if found, otherwise - false |
Init(Entity, Entity, EntityManager, IUISystemAPI)
Initializes the HexTerrainAPI with the terrain terrainEntity, terrainEntity manager and UI system API.
Declaration
public virtual void Init(Entity userToolsEntity, Entity terrainEntity, EntityManager entityManager, IUISystemAPI uiSystemAPI)
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | userToolsEntity | |
| Entity | terrainEntity | |
| EntityManager | entityManager | |
| IUISystemAPI | uiSystemAPI |
IsLayerSupported<TDataLayer>()
Checks if the data layer is supported by the terrain. Meaning if terrain has this data layer.
Declaration
public virtual 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
public virtual 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
public virtual 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
public virtual 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
public virtual 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
public virtual 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
public virtual 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
public virtual 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 terrain layer to set value on |
SetCellBiome<TSurfaceData>(int, byte)
Sets the biomes map value (byte) of the cell at the specified index.
Declaration
public virtual 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<TEntitiesLayer>(int, CellEntity)
Sets the CellEntity from terrain cell at the specified index.
Declaration
public virtual bool SetCellEntity<TEntitiesLayer>(int cellIndex, CellEntity entity) where TEntitiesLayer : 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 |
|---|---|
| TEntitiesLayer | type of cell terrainEntity layer to set value on |
SetCellHeight<TSurfaceData>(int, byte)
Sets the height map value (byte) of the cell at the specified index.
Declaration
public virtual 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
public virtual 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
public virtual 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
public 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
public virtual 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
public virtual 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()
Destroys the specified screen instance.
Declaration
public bool? ToggleIsTerrainVisible()
Returns
| Type | Description |
|---|---|
| bool? | true if the screen was destroyed successfully; otherwise, false |