Game.Simulation.CollectedCityServiceFeeData
Assembly:
Namespace: Game.Simulation
Type: struct CollectedCityServiceFeeData
Base: IBufferElementData, ISerializable
Summary:
Represents a single buffer element that stores collected city service fee totals and counts for a specific player/resource. This struct is designed to be used as a Unity.Entities dynamic buffer element and supports custom serialization/deserialization via the Colossal.Serialization.IWriter/IReader interfaces. The Deserialize implementation handles backward compatibility for older save versions where counts were stored as integers.
Fields
-
public int m_PlayerResource
Holds the player resource ID (or index) that these fee totals belong to. -
public float m_Export
Total exported fees (monetary amount) collected for this player/resource. -
public float m_Import
Total imported fees (monetary amount) collected for this player/resource. -
public float m_Internal
Total internal fees (monetary amount) collected (between same-player entities). -
public float m_ExportCount
Count (as float) of export events used to compute/track exported fees. Note: older save versions stored this as an int. -
public float m_ImportCount
Count (as float) of import events. Also previously serialized as an int in older versions. -
public float m_InternalCount
Count (as float) of internal events. Previously serialized as an int in older versions.
Properties
- (none)
This struct exposes only public fields and no properties.
Constructors
- (default)
No explicit constructors are defined. The default struct constructor initializes numeric fields to 0. Use object initializer syntax or assign fields directly after creation.
Methods
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the struct state from the provided reader in the same field order used by Serialize. The method first reads m_PlayerResource, m_Export, m_Import and m_Internal. It then checks reader.context.version against Version.serviceFeeFix to support older save formats:- If reader.context.version < Version.serviceFeeFix, counts are read from the stream as ints and converted/assigned to the float count fields.
-
Otherwise, counts are read directly as floats. This preserves compatibility with older saves where counts were serialized as integers.
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the struct fields to the provided writer in this exact order: m_PlayerResource, m_Export, m_Import, m_Internal, m_ExportCount, m_ImportCount, m_InternalCount. All counts are written as floats (current format).
Usage Example
// Create and initialize a buffer element
var feeData = new CollectedCityServiceFeeData
{
m_PlayerResource = 0, // player or resource id
m_Export = 1200.5f,
m_Import = 300.0f,
m_Internal = 50.0f,
m_ExportCount = 12f,
m_ImportCount = 3f,
m_InternalCount = 1f
};
// Add to an entity's dynamic buffer (inside a system with access to EntityManager)
var buffer = entityManager.AddBuffer<CollectedCityServiceFeeData>(entity);
buffer.Add(feeData);
// Serialization is handled by the game's save system using IWriter/IReader.
// Example (conceptual):
// writer.Write(feeData); // if the writer supports writing the buffer/element via ISerializable