Skip to content

Game.Simulation.CollectedServiceBuildingBudgetData

Assembly: Game
Namespace: Game.Simulation

Type: struct

Base: ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary:
A compact ECS component/serializable struct used to store aggregated budget-related counts for service buildings. It holds three integer metrics: the number of buildings counted, the number of workers currently employed, and the total number of workplaces (capacity). The struct provides serialization support via the Colossal.Serialization interfaces so it can be written to and read from the game's binary streams.


Fields

  • public int m_Count
    Number of service buildings included in this aggregate.

  • public int m_Workers
    Total number of workers currently employed in the aggregated buildings.

  • public int m_Workplaces
    Total number of workplace slots (capacity) across the aggregated buildings.

Properties

  • (none)
    This struct exposes its data via public fields and does not define properties.

Constructors

  • public CollectedServiceBuildingBudgetData()
    Default parameterless struct constructor (value-type default). All integer fields default to 0. You can also initialize the fields directly when creating an instance:
var data = new CollectedServiceBuildingBudgetData { m_Count = 5, m_Workers = 20, m_Workplaces = 30 };

Methods

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads three consecutive integers from the provided reader into m_Count, m_Workers, and m_Workplaces (in that order). This implements the ISerializable read contract used by the game's serialization framework. The method uses ref locals to read directly into the struct fields.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the three integer fields (m_Count, m_Workers, m_Workplaces) to the provided writer in that order. This implements the ISerializable write contract so the struct can be persisted by the serialization system.

Notes: - The serialization/deserialization order must match to ensure correctness. - Generic constraints ensure the caller supplies an implementation of IReader/IWriter from the Colossal.Serialization API.

Usage Example

// Creating and populating the struct
var budgetData = new CollectedServiceBuildingBudgetData {
    m_Count = 12,
    m_Workers = 48,
    m_Workplaces = 60
};

// Example: adding as a component to an entity (using Entities API)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity e = entityManager.CreateEntity();
entityManager.AddComponentData(e, budgetData);

// Serialization example (pseudo-code; depends on actual IWriter implementation)
using (var writer = /* obtain IWriter from serialization system */)
{
    budgetData.Serialize(writer);
}

// Deserialization example (pseudo-code; depends on actual IReader implementation)
var readData = new CollectedServiceBuildingBudgetData();
using (var reader = /* obtain IReader from serialization system */)
{
    readData.Deserialize(reader);
}

Additional implementation notes: - This struct is designed to be small and copyable (value type), suitable for use as an ECS component. - It integrates with Colossal.Serialization for save/load and with Unity.Entities for queries and component storage.