Game.CurrentBuilding
Assembly: Assembly-CSharp
Namespace: Game.Citizens
Type: struct
Base: System.ValueType, IComponentData, IQueryTypeParameter, ISerializable
Summary: Represents the current building associated with a citizen (or other entity). This component is a lightweight container that stores a Unity.Entities.Entity reference pointing to the building currently relevant to the owner of this component. It supports Colossal.Serialization-based serialization so the entity reference can be written/read during save/load operations.
Fields
public Unity.Entities.Entity m_CurrentBuilding
Holds the Entity reference to the current building. Use this field to read or update which building is associated with the component's owner entity. The type is Unity.Entities.Entity (an ECS entity handle).
Properties
- None. This struct exposes a public field directly rather than properties.
Constructors
public CurrentBuilding(Unity.Entities.Entity building)
Constructs a CurrentBuilding component instance and initializes m_CurrentBuilding with the provided building entity.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_CurrentBuilding entity reference to the provided writer. Used by the Colossal.Serialization framework during saving/serialization. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an entity reference from the provided reader and stores it in m_CurrentBuilding. Used by the Colossal.Serialization framework during loading/deserialization.
Usage Example
// Example: assign a current building to a citizen entity
using Unity.Entities;
using Game.Citizens;
// Assume entityManager and entities already obtained
Entity citizenEntity = /* citizen entity */;
Entity buildingEntity = /* building entity */;
// Create and add the component to the citizen entity
var currentBuilding = new CurrentBuilding(buildingEntity);
entityManager.AddComponentData(citizenEntity, currentBuilding);
// Later you can read/update it:
var cb = entityManager.GetComponentData<CurrentBuilding>(citizenEntity);
Entity associatedBuilding = cb.m_CurrentBuilding;