Class CellEntityLayer
Represents a terrain layer that manages cell entities, providing functionality for initializing, updating, and cleaning up entity data associated with each cell. Supports asynchronous operations and integrates with Unity's Entity Component System (ECS) for efficient entity lifecycle management.
Inherited Members
Namespace: Fwt.HexTerrains.CellEntities.Data
Assembly: fwt.hexterrains.dll
Syntax
public class CellEntityLayer : CellItemLayer, IDisposable, ISerializableTerrainLayer
Remarks
CellEntityLayer is responsible for the creation, destruction, and state management of cell entities within a terrain layer. It utilizes an EntityManager to handle entity instances and supports job-based operations for performance optimization. This layer is typically used in scenarios where each terrain cell requires an associated entity, such as for gameplay logic, rendering, or interaction. Thread safety and job dependencies are managed internally to ensure correct operation when used in multithreaded environments.
Fields
CellEntityConfigs
List of configs for every possible CellEntity index
Declaration
public NativeList<CellEntityStateConfig> CellEntityConfigs
Field Value
| Type | Description |
|---|---|
| NativeList<CellEntityStateConfig> |
CellEntityViews
Data layer for storing a CellEntityView (Entity instances) per cell
Declaration
public CellEntityViewDataLayer CellEntityViews
Field Value
| Type | Description |
|---|---|
| CellEntityViewDataLayer |
EntityManager
Cached EntityManager used to destroy CellEntity instances when the terrain is destroyed or resized
Declaration
public EntityManager EntityManager
Field Value
| Type | Description |
|---|---|
| EntityManager |
SetChunkIndexCommandBuffer
CommandBuffer that holds commands for updating the CellEntity instances (entities)
Declaration
public EntityCommandBuffer? SetChunkIndexCommandBuffer
Field Value
| Type | Description |
|---|---|
| EntityCommandBuffer? |
SetChunkIndexCommandBufferDependency
Job handle for the job that updates chunk index of every CellEntity instance
Declaration
public JobHandle SetChunkIndexCommandBufferDependency
Field Value
| Type | Description |
|---|---|
| JobHandle |
Properties
ColorMapTextureIndex
Index of the texture in the list of ColorMapTextures. Used externally in systems. Systems read this value to know which texture to fill with colors from EntitiesColorMap data layer EntitiesColorMap. That texture is expected to be used in materials or/and UI like minimap.
Declaration
public int ColorMapTextureIndex { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
StatesCountPerEntityIndex
Declaration
public int StatesCountPerEntityIndex { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
CalculateEntities(JobHandle)
Calculates which cell should contain an Entity and from which prefab should that Entity be instantiated. Caches changes in the CellEntityViews data layer.
Declaration
public virtual JobHandle CalculateEntities(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency |
Returns
| Type | Description |
|---|---|
| JobHandle |
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
Dispose()
Disposes all allocated native memory.
Declaration
public override void Dispose()
Overrides
Init(HexTerrainSettings)
Initializes/Reinitializes the CellEntities data.
Declaration
public override void Init(HexTerrainSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainSettings | settings | new terrain settings |
Overrides
Init(HexTerrainSettings, ICellEntityLayerConfig, NativeSlice<CellEntityStateConfig>)
Declaration
public virtual void Init(HexTerrainSettings settings, ICellEntityLayerConfig args, NativeSlice<CellEntityStateConfig> cellEntityConfigs)
Parameters
| Type | Name | Description |
|---|---|---|
| HexTerrainSettings | settings | |
| ICellEntityLayerConfig | args | |
| NativeSlice<CellEntityStateConfig> | cellEntityConfigs |
InitCellEntitiesConfigs(NativeSlice<CellEntityStateConfig>)
Copies an ItemConfigs from the given array. Does not change or cache the array, so it is safe to dispose it after this call. copyFrom array is expected to have the CellEntity indexes length, so there is one config per possible CellEntity index. CellEntity.Index == index in copyFrom array.
Declaration
public void InitCellEntitiesConfigs(NativeSlice<CellEntityStateConfig> copyFrom)
Parameters
| Type | Name | Description |
|---|---|---|
| NativeSlice<CellEntityStateConfig> | copyFrom | array of configs to copy into the ItemConfigs |
PlaybackSetChunkIndexCommandBuffer()
Declaration
public virtual void PlaybackSetChunkIndexCommandBuffer()
SetAllDirty(bool)
Sets the dirty flag for all the data layers. If isDirty is true, all data layers will be marked as dirty and will be recalculated. If isDirty is false, all data layers will be marked as clean and will not be recalculated.
Declaration
public override void SetAllDirty(bool isDirty)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isDirty |
Overrides
UpdateEntities(Entity, int, JobHandle)
Declaration
public virtual JobHandle UpdateEntities(Entity layerEntity, int layerIndex, JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| Entity | layerEntity | |
| int | layerIndex | |
| JobHandle | dependency |
Returns
| Type | Description |
|---|---|
| JobHandle |