Skip to content

Game.Prefabs.PollutionData

Assembly: Assembly-CSharp (game assembly)
Namespace: Game.Prefabs

Type: public struct PollutionData : IComponentData, IQueryTypeParameter, ICombineData, ISerializable

Base: IComponentData, IQueryTypeParameter, ICombineData, ISerializable

Summary:
Stores pollution-related values for a building prefab. Holds separate values for ground, air and noise pollution and a flag that controls whether pollution scales with renters. Implements serialization with version-aware reading/writing to remain compatible across game version changes. Also implements combine semantics so multiple pollution sources can be accumulated (useful when aggregating prefab data into an archetype or combined component).


Fields

  • public float m_GroundPollution
    Represents ground pollution emitted by the prefab. Default (struct) value is 0.0f. Serialized (or deserialized) as a float in current versions; older versions used integer storage.

  • public float m_AirPollution
    Represents air pollution emitted by the prefab. Default (struct) value is 0.0f. Serialized/deserialized in the same order as ground and noise.

  • public float m_NoisePollution
    Represents noise pollution emitted by the prefab. Default (struct) value is 0.0f.

  • public bool m_ScaleWithRenters
    If true, pollution scales with the number of renters (or similar occupant-related scaling). Default (struct) value is false, but deserialization logic sets this to true for older data versions when the explicit value isn't present.

Properties

  • None (no explicit C# properties declared).
    This type exposes its values via public fields and by the GetValue method.

Constructors

  • public PollutionData()
    Default parameterless struct constructor (implicit). Default field values: m_GroundPollution = 0f, m_AirPollution = 0f, m_NoisePollution = 0f, m_ScaleWithRenters = false. Note: Deserialize will override defaults depending on saved data and version.

Methods

  • public float GetValue(BuildingStatusType statusType)
    Returns the appropriate pollution value based on the provided BuildingStatusType:
  • BuildingStatusType.GroundPollutionSource => m_GroundPollution
  • BuildingStatusType.AirPollutionSource => m_AirPollution
  • BuildingStatusType.NoisePollutionSource => m_NoisePollution
  • otherwise => 0f

  • public void AddArchetypeComponents(HashSet<ComponentType> components)
    Empty implementation in this type. Present to satisfy IQueryTypeParameter (or similar ECS usage) — intended to add required component types to an archetype when needed; this struct does not add additional components.

  • public void Combine(PollutionData otherData)
    Accumulates another PollutionData into this instance by summing each pollution channel:

  • m_GroundPollution += otherData.m_GroundPollution
  • m_AirPollution += otherData.m_AirPollution
  • m_NoisePollution += otherData.m_NoisePollution

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes data in this order: ground (float), air (float), noise (float), scaleWithRenters (bool). Intended for saving the prefab/component data.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads data with version-aware logic:

  • If reader.context.version > Version.pollutionMultiplierChange: reads the m_ScaleWithRenters bool from stream; otherwise sets m_ScaleWithRenters = true (compatibility behavior for older saves).
  • If reader.context.version < Version.pollutionFloatFix: older format stored pollution values as ints — reads three ints (ground, air, noise) and assigns them to the float fields.
  • Else: reads three floats (ground, air, noise) into the fields.
  • The read order matches the Serialize order for current versions.

Usage Example

// Create/assign pollution values for a prefab/component
var p = new PollutionData();
p.m_GroundPollution = 12.5f;
p.m_AirPollution = 3.0f;
p.m_NoisePollution = 0.75f;
p.m_ScaleWithRenters = false;

// Query a specific channel
float ground = p.GetValue(BuildingStatusType.GroundPollutionSource);

// Combine with another source
var other = new PollutionData { m_GroundPollution = 1.0f, m_AirPollution = 0.5f };
p.Combine(other); // ground becomes 13.5f, air becomes 3.5f

// Serialization (example sketch — actual writer comes from engine save code)
writer.Write(p.m_GroundPollution);
writer.Write(p.m_AirPollution);
writer.Write(p.m_NoisePollution);
writer.Write(p.m_ScaleWithRenters);

// Deserialization handles historical formats automatically based on reader.context.version

Notes: - BuildingStatusType and Version are enums defined elsewhere in the game's code; compatibility behavior depends on their values. - Because this is an IComponentData, instances are intended for storage on ECS entities or for prefab metadata; prefer using Combine when summing multiple prefab contributions.