Game.ElectricityProducer
Assembly: Assembly-CSharp.dll
Namespace: Game.Buildings
Type: struct (public)
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents an ECS component for an electricity-producing building. Stores the producer's capacity and the last recorded production value. Implements ISerializable to allow reading/writing by the game's custom serialization system with version-aware deserialization logic to maintain compatibility across save/game versions.
Fields
-
public int m_Capacity
Holds the production capacity (integer) for the electricity producer. Used by game logic to determine how much power the building can supply. -
public int m_LastProduction
Stores the last recorded production value (integer). May be absent in older save versions; the Deserialize implementation conditionally reads this field depending on the save version.
Properties
- This type does not declare any C# properties. It exposes public fields and implements component/serialization interfaces.
Constructors
public ElectricityProducer()
Default value-type (struct) constructor. Fields are initialized to their default values (m_Capacity = 0, m_LastProduction = 0) when created without explicit initializer. Use object/field initializer or assignment to set actual values before use.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component state to the provided writer. The implementation writes m_Capacity followed by m_LastProduction in that order. This method is called by the game's serialization pipeline when saving component data. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component state from the provided reader with version-aware handling: - Reads m_Capacity unconditionally.
- For reader.context.version in the range [Version.powerPlantConsumption, Version.serviceConsumption) an extra int is read and discarded. This preserves compatibility with older serialized formats that included an additional field.
- If reader.context.version >= Version.powerPlantLastFlow, reads m_LastProduction. For older versions where this field did not exist, m_LastProduction remains at its default value (0).
This conditional logic ensures the component can be deserialized correctly across multiple save/game versions.
Usage Example
// Example: creating and adding the component to an entity
var producer = new Game.Buildings.ElectricityProducer
{
m_Capacity = 1200,
m_LastProduction = 900
};
entityManager.AddComponentData(entity, producer);
// Example: serializing the component (invoked by the game's serializer)
IWriter writer = /* provided by serialization system */;
producer.Serialize(writer);
// Example: deserializing the component (invoked by the game's deserializer)
IReader reader = /* provided by serialization system */;
var loadedProducer = new Game.Buildings.ElectricityProducer();
loadedProducer.Deserialize(reader);
entityManager.SetComponentData(entity, loadedProducer);
Notes: - The Serialize/Deserialize methods are generic over IWriter/IReader types used by the Colossal/City serialization system. - Be mindful of the Version checks in Deserialize (Version.powerPlantConsumption, Version.serviceConsumption, Version.powerPlantLastFlow) when modifying serialization format — preserve compatibility or update version constants accordingly.