Game.StatisticParameter
Assembly: Assembly-CSharp
Namespace: Game.City
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
A lightweight ECS component that holds a single integer statistic value. Implements Colossal.Serialization's ISerializable so the value can be written to/read from the game's custom serialization stream. Also implements IQueryTypeParameter to be usable as a query parameter type in ECS queries.
Fields
public int m_Value
Holds the integer statistic value. Default is 0. This field is the sole payload of this component and is what gets serialized/deserialized by the implemented ISerializable methods.
Properties
- This type does not declare any properties.
Constructors
- implicit default constructor
As a struct, it has the default parameterless constructor which initializes m_Value to 0. You can also initialize it with an object initializer: new StatisticParameter { m_Value = 42 }
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component's m_Value into the provided writer. Intended for saving this component's state to the game's serialization stream. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an integer from the provided reader into m_Value. Intended for restoring this component's state from the game's serialization stream.
Both methods are generic to accept the Colossal.Serialization entity writer/reader implementations used by the game.
Usage Example
// Adding the component to an entity (Unity.Entities / DOTS style)
var entity = entityManager.CreateEntity();
entityManager.AddComponentData(entity, new StatisticParameter { m_Value = 100 });
// Serializing / deserializing using Colossal.Serialization-style reader/writer:
StatisticParameter stat = new StatisticParameter { m_Value = 250 };
// When saving:
stat.Serialize(writer); // writer implements IWriter and writes the int
// When loading:
stat.Deserialize(reader); // reader implements IReader and reads the int into m_Value