Class HexTerrainLayerGroup<TTerrainLayer>
Base class for HexTerrain layer that holds a list of Terrain layers inside. Each nested layer must be derived from TTerrainLayer type.
Inheritance
Inherited Members
Namespace: Fwt.HexTerrains.Data
Assembly: fwt.hexterrains.dll
Syntax
public abstract class HexTerrainLayerGroup<TTerrainLayer> : HexTerrainLayerGroup, IDisposable, ISerializableTerrainLayer where TTerrainLayer : HexTerrainLayer
Type Parameters
| Name | Description |
|---|---|
| TTerrainLayer | Type of terrain layer this |
Properties
LayerIndexByInstance
Gets or sets the mapping of terrain layer instances to their corresponding layer indices.
Declaration
public virtual Dictionary<TTerrainLayer, int> LayerIndexByInstance { get; set; }
Property Value
| Type | Description |
|---|---|
| Dictionary<TTerrainLayer, int> |
Remarks
Each key in the dictionary represents a terrain layer instance, and its associated value specifies the index assigned to that layer. Modifying this collection affects how terrain layers are referenced by index within the containing object.
LayerIndexByName
Gets or sets a mapping of layer names to their corresponding index values.
Declaration
public virtual Dictionary<string, int> LayerIndexByName { get; set; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, int> |
Remarks
Each key in the dictionary represents a unique layer name, and its associated value is the index of that layer. Modifying this property allows customization of layer ordering or lookup by name. Layer names must be unique within the dictionary.
Layers
Gets or sets the collection of terrain layers associated with this instance.
Declaration
public virtual List<TTerrainLayer> Layers { get; set; }
Property Value
| Type | Description |
|---|---|
| List<TTerrainLayer> |
Remarks
Modifying the collection directly affects the terrain configuration. Changes to the layers may impact rendering or behavior depending on how terrain layers are used in the application.
LayersByName
Gets or sets the collection of terrain layers, indexed by their unique names.
Declaration
public virtual Dictionary<string, TTerrainLayer> LayersByName { get; set; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, TTerrainLayer> |
Remarks
Each key in the dictionary represents the name of a terrain layer, and the corresponding value is the associated layer object. Modifying this collection affects the set of available terrain layers for the instance. The property is read-write; changes to the dictionary are reflected immediately.
LayersCount
Gets the number of layers contained in the collection.
Declaration
public virtual int LayersCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
AddLayer(TTerrainLayer)
Adds a new layer to the end of the layers list.
Declaration
public virtual int AddLayer(TTerrainLayer layer)
Parameters
| Type | Name | Description |
|---|---|---|
| TTerrainLayer | layer | nested layer to add to the Layers list |
Returns
| Type | Description |
|---|---|
| int | Index under which the layer was added |
CalculateColorMap(JobHandle)
Schedules the calculation of the color map, ensuring it is executed after the specified job dependency completes.
Declaration
public override JobHandle CalculateColorMap(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | A job handle representing the dependency that must be completed before the color map calculation begins. |
Returns
| Type | Description |
|---|---|
| JobHandle | A job handle that can be used to track the completion of the color map calculation job. |
Overrides
Cleanup()
Every frame there is a cleanup stage. This function is called. Usually used to clean the dirty flags.
Declaration
public override void Cleanup()
Overrides
CleanupAsync(JobHandle)
Async version of Cleanup() Cleanup() Difference between regular Cleanup() is that it schedules jobs that clean up data layers, so you don't have to wait for the results and can continue working. Every frame there is a cleanup stage. This function is called. Usually used to clean the dirty flags.
Declaration
public override JobHandle CleanupAsync(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency |
Returns
| Type | Description |
|---|---|
| JobHandle |
Overrides
CreateTerrainLayer<TInitArgs>(TInitArgs)
This function is called to create a new terrain layer of type TTerrainLayer. Default implementation uses an Activator to create a new instance of TTerrainLayer, expecting that the TTerrainLayer has a parameterless constructor. Override this function in your derived class to have a custom way of creating a terrain layer.
Declaration
public virtual TTerrainLayer CreateTerrainLayer<TInitArgs>(TInitArgs initArgs)
Parameters
| Type | Name | Description |
|---|---|---|
| TInitArgs | initArgs | Initialization arguments for creating a layer |
Returns
| Type | Description |
|---|---|
| TTerrainLayer | Returns a created instance of the terrain layer of type (inherited from) TTerrainLayer |
Type Parameters
| Name | Description |
|---|---|
| TInitArgs | Init terrain layer arguments object that is used in create layer process. Default implementation ignores this parameter, but in your overrided implementation it may be needed |
DeserializeLayer(BinaryReader, HexTerrainSettings)
Requests a deserialization of the layer data. Returns false if the layer does not support deserialization.
Declaration
public override bool DeserializeLayer(BinaryReader reader, HexTerrainSettings terrainSettings)
Parameters
| Type | Name | Description |
|---|---|---|
| BinaryReader | reader | binary reader to deserialize data from |
| HexTerrainSettings | terrainSettings | deserialized terrain settings (layer was serialized with this settings) |
Returns
| Type | Description |
|---|---|
| bool |
Overrides
Dispose()
Disposes all allocated native memory.
Declaration
public override void Dispose()
Overrides
GetLayer(int)
Returns the layer at the specified index.
Declaration
public virtual TTerrainLayer GetLayer(int layerIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerIndex | Index in a list of all layers to get a layer at |
Returns
| Type | Description |
|---|---|
| TTerrainLayer | layer at index layerIndex |
GetLayer(string)
Returns the first found layer with specified name
Declaration
public TTerrainLayer GetLayer(string layerName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | layerName | Name of the layer to find |
Returns
| Type | Description |
|---|---|
| TTerrainLayer | layer with specified name. If not found, returns null |
GetLayer<TTargetLayer>()
Returns the first layer of type TTargetLayer.
Declaration
public override TTargetLayer GetLayer<TTargetLayer>()
Returns
| Type | Description |
|---|---|
| TTargetLayer | first found layer of TTargetLayer type. If not found, returns null |
Type Parameters
| Name | Description |
|---|---|
| TTargetLayer | type of layer to find |
Overrides
GetLayer<TTargetLayer>(HexTerrainLayerReference)
Returns the layer of type TTargetLayer from the list of layers according to the provided arguments.
Declaration
public override TTargetLayer GetLayer<TTargetLayer>(HexTerrainLayerReference args) where TTargetLayer : HexTerrainLayer
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainLayerReference | args | args to get layer according to |
Returns
| Type | Description |
|---|---|
| TTargetLayer | layer of TTargetType according to provided arguments |
Type Parameters
| Name | Description |
|---|---|
| TTargetLayer | casts result to this type |
Overrides
GetLayer<TTargetLayer>(int)
Returns the layer of type TTargetLayer at the specified index.
Declaration
public override TTargetLayer GetLayer<TTargetLayer>(int layerIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerIndex | index at which to get a layer |
Returns
| Type | Description |
|---|---|
| TTargetLayer | layer of TTargetType at the requested index (if found) or null (if not found) |
Type Parameters
| Name | Description |
|---|---|
| TTargetLayer | casts result to this type |
Overrides
GetLayer<TTargetLayer>(int, bool, string, bool)
Retrieves a terrain layer of the specified type using either its index or name, depending on the provided search options.
Declaration
public override TTargetLayer GetLayer<TTargetLayer>(int layerIndex, bool isSearchByIndex, string layerName, bool isSearchByName) where TTargetLayer : HexTerrainLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerIndex | The zero-based index of the layer to retrieve. Used if |
| bool | isSearchByIndex | Indicates whether to search for the layer by its index. If true, |
| string | layerName | The name of the layer to retrieve. Used if |
| bool | isSearchByName | Indicates whether to search for the layer by its name. If true, |
Returns
| Type | Description |
|---|---|
| TTargetLayer | The terrain layer of type |
Type Parameters
| Name | Description |
|---|---|
| TTargetLayer | The type of terrain layer to retrieve. Must derive from HexTerrainLayer. |
Overrides
Remarks
If both isSearchByIndex and isSearchByName are
true, the method may prioritize one search method over the other depending on the
implementation. Ensure that the provided index and name correspond to an existing layer to avoid a null result.
GetLayer<TTargetLayer>(int, string)
Returns the layer of type TTargetLayer at the specified index and with the specified name.
Declaration
public override TTargetLayer GetLayer<TTargetLayer>(int layerIndex, string layerName) where TTargetLayer : HexTerrainLayer
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerIndex | index at which to get a layer |
| string | layerName | name of the layer that should be found |
Returns
| Type | Description |
|---|---|
| TTargetLayer | layer of TTargetType at the requested index (if found) if it has the provided name |
Type Parameters
| Name | Description |
|---|---|
| TTargetLayer | casts result to this type |
Overrides
GetLayer<TTargetLayer>(string)
Returns the layer of type TTargetLayer at the specified index.
Declaration
public override TTargetLayer GetLayer<TTargetLayer>(string layerName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | layerName | name of the layer that should be found |
Returns
| Type | Description |
|---|---|
| TTargetLayer | layer of TTargetType at the requested index (if found) or null (if not found) |
Type Parameters
| Name | Description |
|---|---|
| TTargetLayer | casts result to this type |
Overrides
Init(HexTerrainSettings)
Initializes/Reinitializes the area data.
Declaration
public override void Init(HexTerrainSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainSettings | settings | new terrain settings |
Overrides
InitLayers(HexTerrainSettings)
Usually called from other Init functions. Initializes the nested layers without any arguments. This function is called from Init(HexTerrainSettings). Even if you have the initialization with init args, this one may be called when the terrain is resized or when the layers list is created without any arguments.
Declaration
public virtual void InitLayers(HexTerrainSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainSettings | settings | HexTerrainSettings of the terrain this layers list is attached to |
InitLayers<TInitLayerArgs>(HexTerrainSettings, IEnumerable<TInitLayerArgs>)
Usually called from other Init functions. Initializes the nested layers using provided initialization arguments.
Declaration
public virtual void InitLayers<TInitLayerArgs>(HexTerrainSettings settings, IEnumerable<TInitLayerArgs> initLayersArgs)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainSettings | settings | HexTerrainSettings of the terrain this layers list is attached to |
| IEnumerable<TInitLayerArgs> | initLayersArgs |
Type Parameters
| Name | Description |
|---|---|
| TInitLayerArgs | Init arguments to initialize child layers with |
InitTerrainLayer<TInitArgs>(TTerrainLayer, HexTerrainSettings, TInitArgs)
Initializes the terrain layer with the specified settings and initialization arguments.
Declaration
public virtual void InitTerrainLayer<TInitArgs>(TTerrainLayer layer, HexTerrainSettings settings, TInitArgs initArgs)
Parameters
| Type | Name | Description |
|---|---|---|
| TTerrainLayer | layer | nested terrain layer to be initialized with provided init args |
| HexTerrainSettings | settings | HexTerrainSettings of the terrain this layers list is attached to |
| TInitArgs | initArgs | Initialization arguments for provided nested terrain layer |
Type Parameters
| Name | Description |
|---|---|
| TInitArgs | Initialization arguments for a nested terrain layer |
Init<TInitLayerArgs>(HexTerrainSettings, IEnumerable<TInitLayerArgs>)
Initializes a layers list with the specified settings and initialization arguments for each layer.
Declaration
public virtual void Init<TInitLayerArgs>(HexTerrainSettings settings, IEnumerable<TInitLayerArgs> initLayerArgs)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainSettings | settings | HexTerrainSettings of the terrain this layers list is attached to |
| IEnumerable<TInitLayerArgs> | initLayerArgs | Collection of init layer arguments to create/init nested layers with |
Type Parameters
| Name | Description |
|---|---|
| TInitLayerArgs | Enumerable with initialization arguments for each layer to be created/initialized |
RegisterLayer(TTerrainLayer, int)
Registers the specified terrain layer and associates it with the given index.
Declaration
protected virtual void RegisterLayer(TTerrainLayer layer, int layerIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| TTerrainLayer | layer | The terrain layer to register. If |
| int | layerIndex | The index to associate with the specified terrain layer. |
Remarks
If the layer has a non-empty name, it is also registered by name for lookup. This method can be overridden in derived classes to customize layer registration behavior.
RemoveLayer(int, bool)
Removes a layer at the specified index.
Declaration
public virtual bool RemoveLayer(int layerIndex, bool isDispose)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerIndex | Index of the layer to remove |
| bool | isDispose | If true, disposes the removed layer instance (if any) |
Returns
| Type | Description |
|---|---|
| bool | True if success, otherwise - false |
RemoveLayer(string, bool)
Removes the layer with the specified name from the collection.
Declaration
public virtual bool RemoveLayer(string layerName, bool isDispose)
Parameters
| Type | Name | Description |
|---|---|---|
| string | layerName | The name of the layer to remove. Cannot be null or empty. |
| bool | isDispose | Indicates whether the layer should be disposed after removal. Specify true to dispose the layer; otherwise, false. |
Returns
| Type | Description |
|---|---|
| bool | true if the layer was found and removed; otherwise, false. |
RemoveLayer(TTerrainLayer, bool)
Removes the specified terrain layer from the collection.
Declaration
public virtual bool RemoveLayer(TTerrainLayer terrainLayer, bool isDispose)
Parameters
| Type | Name | Description |
|---|---|---|
| TTerrainLayer | terrainLayer | The terrain layer to remove. If |
| bool | isDispose | Indicates whether the terrain layer should be disposed after removal. Set to true to dispose the layer; otherwise, false. |
Returns
| Type | Description |
|---|---|
| bool | true if the terrain layer was found and removed; otherwise, false. |
SerializeLayer(BinaryWriter)
Requests a serialization of the layer data. Returns false if the layer does not support serialization.
Declaration
public override bool SerializeLayer(BinaryWriter writer)
Parameters
| Type | Name | Description |
|---|---|---|
| BinaryWriter | writer | binary writer to serialize data by |
Returns
| Type | Description |
|---|---|
| bool | True if serialized, false if not serialized/not supported/not implemented |
Overrides
SetAllDirty(bool)
Sets all data layers dirty value. If isDirty is true, all data layers will be marked as dirty and will be recalculated on the next frame. If isDirty is false, all data layers will be marked as clean and will not be recalculated on the next frame.
Declaration
public override void SetAllDirty(bool isDirty)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isDirty |
Overrides
SetLayer(int, TTerrainLayer, bool, bool)
Sets a layer at the specified index. If Layers list is smaller than the provided index, does nothing and returns false.
Declaration
public virtual bool SetLayer(int layerIndex, TTerrainLayer value, bool overrideExisting, bool disposeExisting)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerIndex | Index to set a layer at |
| TTerrainLayer | value | nested layer to set at the specified layerIndex |
| bool | overrideExisting | if true, overrides the layer that is already at the specified index (if any) |
| bool | disposeExisting | if true, in case when there is already a layer at the specified index, disposes the existing layer before setting a new one. Ignored if the existing layer is the same object as the provided new one |
Returns
| Type | Description |
|---|---|
| bool | true if success, otherwise - false |
SetOrAddLayer(int, TTerrainLayer, bool, bool)
Sets or adds a layer at the specified index. If Layers list is smaller than the provided index, the new empty slots will be added to the list until it reaches the capacity so there is a slot with layerIndex.
Declaration
public virtual bool SetOrAddLayer(int layerIndex, TTerrainLayer value, bool overrideExisting = true, bool disposeExisting = true)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerIndex | Index of the terrain layer to set |
| TTerrainLayer | value | terrain layer to set at the specified layerIndex |
| bool | overrideExisting | if true, overrides the layer that is already at the specified index (if any) |
| bool | disposeExisting | if true, in case when there is already a layer at the specified index, disposes the existing layer before setting a new one. Ignored if the existing layer is the same object as the provided new one |
Returns
| Type | Description |
|---|---|
| bool | true if success, otherwise - false |
UnregisterLayer(TTerrainLayer, int)
Removes the specified terrain layer and its associated indices from internal collections.
Declaration
protected virtual void UnregisterLayer(TTerrainLayer layer, int layerIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| TTerrainLayer | layer | The terrain layer to unregister. If |
| int | layerIndex | The index of the terrain layer to unregister. This value is used to identify the layer within internal structures. |
Remarks
After calling this method, the specified layer and its name will no longer be tracked by the internal collections. This method is virtual and can be overridden to customize layer unregistration behavior in derived classes.