Game.Prefabs.BuildingModule
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: Unity.Entities.IBufferElementData
Summary:
A simple buffer element used to store a reference to another Entity representing a building "module". Designed to be used in a DynamicBuffer
Fields
public Unity.Entities.Entity m_Module
Holds the Entity reference for a single module. Each element in the DynamicBufferstores one module Entity.
Properties
- This type has no properties.
Constructors
public BuildingModule(Unity.Entities.Entity module)
Constructs a BuildingModule with the provided Entity reference and stores it in m_Module.
Methods
- This type defines no methods beyond the constructor (no instance or static methods).
Usage Example
// Example: adding modules to a building entity
using Unity.Entities;
using Game.Prefabs;
void AddModuleToBuilding(EntityManager entityManager, Entity buildingEntity, Entity moduleEntity)
{
// Ensure the buffer exists on the building entity
if (!entityManager.HasComponent<DynamicBuffer<BuildingModule>>(buildingEntity))
entityManager.AddBuffer<BuildingModule>(buildingEntity);
// Get the buffer and add the module
var buffer = entityManager.GetBuffer<BuildingModule>(buildingEntity);
buffer.Add(new BuildingModule(moduleEntity));
}
// Example: reading modules in a system
public partial struct ExampleSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
var em = state.EntityManager;
foreach (var (buffer, entity) in SystemAPI.Query<DynamicBuffer<BuildingModule>>().WithEntityAccess())
{
for (int i = 0; i < buffer.Length; i++)
{
Entity module = buffer[i].m_Module;
// operate on module entity...
}
}
}
}