Skip to content

Game.Citizens.Worker

Assembly: Game
Namespace: Game.Citizens

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Worker is an ECS component representing a citizen employed at a workplace. It stores the workplace entity, the last recorded commute time, the worker's level (as a byte), and the worker's assigned workshift. The struct implements ISerializable to persist/load the component data in the same order and types that the game expects.


Fields

  • public Unity.Entities.Entity m_Workplace
    Represents the Entity that is the worker's workplace (company/building). Serialized/deserialized as an Entity reference.

  • public float m_LastCommuteTime
    Stores the last commute time for the worker (float). Useful for timing logic related to commuting/arrival.

  • public byte m_Level
    A small integer level value for the worker (e.g., skill/experience tier). Serialized as a single byte.

  • public Workshift m_Shift
    The worker's assigned shift. Stored as the Workshift enum in memory but serialized/deserialized as a byte (cast to/from byte).

Properties

This type does not expose any C# properties; it only contains public fields and implements interface methods for serialization.

Constructors

  • public Worker()
    No explicit constructor is defined in the source — the default parameterless struct constructor is used. Initialize fields directly when creating an instance.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component data to the provided writer in the following order: m_Workplace (Entity), m_LastCommuteTime (float), m_Level (byte), and m_Shift as a byte. The Workshift enum is explicitly cast to byte for serialization.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads component data from the provided reader in the same order as serialization. It reads into the struct's fields and reconstructs the Workshift by reading a byte and casting it to Workshift.

Notes: - The order and types used during serialization/deserialization must match exactly — mismatches will break save/load compatibility. - The writer/reader generics are part of the game's Colossal.Serialization entities system; you generally don't call Serialize/Deserialize manually unless implementing custom save/load logic or tools.

Usage Example

// Example: creating and adding a Worker component to an entity
var worker = new Worker
{
    m_Workplace = workplaceEntity,      // an existing Entity representing the workplace
    m_LastCommuteTime = 0f,
    m_Level = 1,
    m_Shift = Workshift.Day             // Workshift is an enum defined elsewhere
};

entityManager.AddComponentData(citizenEntity, worker);

// Example: reading back the component
Worker existing = entityManager.GetComponentData<Worker>(citizenEntity);

// Note: serialization is handled by the game's save system via IWriter/IReader.
// If you implement custom writers/readers, Serialize/Deserialize will be invoked with
// a concrete IWriter/IReader implementation matching the serialization pipeline.