Skip to content

Game.Simulation.ServiceBudgetData

Assembly: Assembly-CSharp
Namespace: Game.Simulation

Type: struct

Base: IBufferElementData, ISerializable

Summary:
Buffer element used by the simulation to store a service Entity reference together with its budget value. Implements the Colossal serialization contract (ISerializable) so individual entries can be read from / written to save data streams. The Deserialize implementation includes backward-compatibility handling for older save versions (it discards an extra int if the save version is older than Version.serviceImportBudgets).


Fields

  • public Entity m_Service
    Holds the Entity that represents the service. This is the reference used by simulation systems to identify which service the budget applies to.

  • public int m_Budget
    Integer budget value for the corresponding service. Written and read during serialization.

Properties

  • (none)

Constructors

  • public ServiceBudgetData()
    Default value-type constructor (implicit). Create instances by assigning m_Service and m_Budget.

Methods

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the stored data from the provided reader. Reads m_Service followed by m_Budget. For backward compatibility, if reader.context.version < Version.serviceImportBudgets the method reads and discards an extra int from the stream (to match older save layout).

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Service and m_Budget values into the provided writer in that order.

Usage Example

// create and populate an element
ServiceBudgetData entry = new ServiceBudgetData {
    m_Service = serviceEntity,
    m_Budget = 75
};

// add to an entity's dynamic buffer (using Unity.Entities EntityManager)
var buffer = entityManager.GetBuffer<ServiceBudgetData>(someEntity);
buffer.Add(entry);

// The serializer methods are used by the game's save/load systems.
// Example (conceptual): Serialize writes the fields in order.