Game.Prefabs.PrisonData
Assembly:
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, ICombineData
Summary:
Represents prison-related prefab data used by the ECS prefabs system. Holds capacities and prisoner status modifiers (wellbeing and health). Implements serialization/deserialization with version-aware reading for the wellbeing/health fields, and supports combining (aggregation) of data from multiple sources via ICombineData
Fields
-
public int m_PrisonVanCapacity
Holds the capacity of the prison transport (van) for this prefab. Aggregated by Combine and written/read by Serialize/Deserialize. -
public int m_PrisonerCapacity
Maximum number of prisoners the prison prefab can hold. Aggregated by Combine and written/read by Serialize/Deserialize. -
public sbyte m_PrisonerWellbeing
Small signed value representing how the prefab affects prisoner wellbeing. This value is conditionally deserialized depending on the saved data version (see Deserialize details). -
public sbyte m_PrisonerHealth
Small signed value representing how the prefab affects prisoner health. Also conditionally deserialized depending on the saved data version.
Properties
- (none)
Constructors
public PrisonData()
Default value-type constructor (compiler-provided). All fields default to 0.
Methods
public void Combine(PrisonData otherData) : System.Void
Adds the corresponding fields from otherData into this instance. Used to aggregate prefab data when multiple sources contribute to a final value:- m_PrisonVanCapacity += otherData.m_PrisonVanCapacity
- m_PrisonerCapacity += otherData.m_PrisonerCapacity
- m_PrisonerWellbeing += otherData.m_PrisonerWellbeing
-
m_PrisonerHealth += otherData.m_PrisonerHealth
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes fields to the provided writer in the following order: - m_PrisonVanCapacity (int)
- m_PrisonerCapacity (int)
- m_PrisonerWellbeing (sbyte)
- m_PrisonerHealth (sbyte)
The serialized order must be preserved to be compatible with Deserialize.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes fields from the provided reader. The first two fields (m_PrisonVanCapacity and m_PrisonerCapacity) are always read. The two sbyte fields (m_PrisonerWellbeing and m_PrisonerHealth) are read only if the reader.context.version is >= Version.happinessAdjustRefactoring. This implements backward compatibility with older saved data formats that did not include wellbeing/health fields.
Usage Example
// Create and combine data from two sources
var baseData = new PrisonData { m_PrisonVanCapacity = 2, m_PrisonerCapacity = 50, m_PrisonerWellbeing = 1, m_PrisonerHealth = 0 };
var addedData = new PrisonData { m_PrisonVanCapacity = 1, m_PrisonerCapacity = 20, m_PrisonerWellbeing = -1, m_PrisonerHealth = 1 };
baseData.Combine(addedData);
// baseData now: m_PrisonVanCapacity = 3, m_PrisonerCapacity = 70, m_PrisonerWellbeing = 0, m_PrisonerHealth = 1
// Serialize
// (Assumes `writer` implements IWriter)
baseData.Serialize(writer);
// Deserialize
// (Assumes `reader` implements IReader and has a context.version)
// var loaded = new PrisonData();
// loaded.Deserialize(reader);
Notes and implementation details: - The struct is intended for use with Unity ECS-style prefab/component systems in Cities: Skylines 2 modding pipelines. - The Serialize/Deserialize methods use generic writer/reader interfaces (IWriter/IReader) from the game's serialization framework; ensure you use matching writer/reader implementations when reading/writing saved prefab data. - The conditional reading of m_PrisonerWellbeing and m_PrisonerHealth ensures compatibility with saves created prior to the Version.happinessAdjustRefactoring change — if you need to write code that manipulates saved data versions, consult the game's Version enum/definitions.