Skip to content

Game.Prefabs.ParkData

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs

Type:
struct

Base:
IComponentData, IQueryTypeParameter, ICombineData, ISerializable

Summary:
Represents small, serializable data for park prefabs used by the ECS and save/load systems. Contains a maintenance pool value and a flag controlling whether homeless are allowed in the park. Implements combining logic used when merging component data and implements serialization/deserialization with version-aware reading for backwards compatibility.


Fields

  • public short m_MaintenancePool
    Holds the maintenance budget/pool for the park. Used to accumulate maintenance amounts when combining ParkData instances. Default value is 0.

  • public bool m_AllowHomeless
    Flag indicating whether homeless citizens are allowed in this park. Default value is false. Presence in serialized data depends on the save format version (see Deserialize).

Properties

  • (none)
    This struct exposes no C# properties; it uses public fields.

Constructors

  • public ParkData()
    The default parameterless constructor (compiler-generated) initializes fields to default values: m_MaintenancePool = 0, m_AllowHomeless = false.

Methods

  • public void Combine(ParkData otherData)
    Adds another ParkData's maintenance pool into this instance: m_MaintenancePool += otherData.m_MaintenancePool. Used by ICombineData to merge data (for example when aggregating components).

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the struct to the provided writer. Serialization order:

  • Writes m_MaintenancePool (short)
  • Writes m_AllowHomeless (bool) This ensures saved data contains the maintenance pool and the homeless flag. Writer must implement IWriter.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads data from the provided reader into the struct fields. Deserialization logic:

  • Reads m_MaintenancePool (short).
  • If reader.context.version >= Version.homelessPark, reads m_AllowHomeless (bool).
    The version check ensures compatibility with older saves that predate the homelessPark version flag — in those older saves the m_AllowHomeless field is not present.

Usage Example

// Create two ParkData instances and combine them
var parkA = new ParkData { m_MaintenancePool = 100, m_AllowHomeless = true };
var parkB = new ParkData { m_MaintenancePool = 50 };

// Combine parkB into parkA -> parkA.m_MaintenancePool becomes 150
parkA.Combine(parkB);

// Serialize (pseudocode — actual writer depends on engine's serialization API)
IWriter writer = GetWriterSomehow();
parkA.Serialize(writer);

// Deserialize (pseudocode)
IReader reader = GetReaderSomehow();
var loadedPark = new ParkData();
loadedPark.Deserialize(reader);
// loadedPark.m_AllowHomeless will only be read if reader.context.version >= Version.homelessPark

{{ Additional notes for modders: - This struct is used as an ECS component (IComponentData). When creating or modifying ParkData at runtime, remember it is plain data (no behavior) and should be updated via the appropriate ECS/system patterns. - The Combine implementation is simple addition on the maintenance pool; if you change semantics (e.g., clamping or overflow handling), ensure other systems that rely on Combine are compatible. - The Deserialize method relies on reader.context.version and Version.homelessPark. If you add new fields in future versions, follow the same pattern (version-gated reading) to preserve backward compatibility with older saves. }}