Skip to content

Game.Prefabs.SolarPoweredData

Assembly:
Assembly-CSharp

Namespace: Game.Prefabs

Type:
struct

Base:
System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Unity.Entities.ICombineData, Colossal.Serialization.Entities.ISerializable

Summary:
Represents simple component data for solar-powered prefabs. Holds an integer production value (m_Production), supports combining with another SolarPoweredData instance (summing production), and provides serialization/deserialization hooks for save/load or network transfer via the Colossal.Serialization IWriter/IReader pattern. Intended for use with Unity.Entities (ECS) systems in the Cities: Skylines 2 modding environment.


Fields

  • public int m_Production
    Holds the production amount contributed by this solar-powered prefab. Default value is 0 for the implicit struct initializer. Used by Combine to aggregate production and written/read by Serialize/Deserialize.

Properties

  • This type defines no properties.

Constructors

  • public SolarPoweredData()
    Implicit parameterless struct constructor provided by C#. Initializes m_Production to 0. You can also initialize using object initializer syntax: new SolarPoweredData { m_Production = 10 }.

Methods

  • public void Combine(SolarPoweredData otherData)
    Adds the production from otherData to this instance (m_Production += otherData.m_Production). Implemented as part of ICombineData to allow aggregation of component data when merging or batching.

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Production value to the provided writer. Used for saving or serializing the component's state. Writer is expected to implement Colossal.Serialization.Entities.IWriter.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads an int value from the provided reader into m_Production. Used for loading or deserializing the component's state. Reader is expected to implement Colossal.Serialization.Entities.IReader.

Usage Example

// Create and combine two data instances
var dataA = new SolarPoweredData { m_Production = 10 };
var dataB = new SolarPoweredData { m_Production = 5 };
dataA.Combine(dataB); // dataA.m_Production == 15

// Serialize to a writer (IWriter implementation provided by the serialization system)
void Save<TWriter>(TWriter writer, SolarPoweredData data) where TWriter : Colossal.Serialization.Entities.IWriter
{
    data.Serialize(writer);
}

// Deserialize from a reader (IReader implementation provided by the serialization system)
SolarPoweredData Load<TReader>(TReader reader) where TReader : Colossal.Serialization.Entities.IReader
{
    var data = new SolarPoweredData();
    data.Deserialize(reader);
    return data;
}