Skip to content

Game.Net.Pollution

Assembly: Game
Namespace: Game.Net

Type: struct

Base: System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents pollution data for an entity in the game's ECS. Holds the current pollution vector (m_Pollution) and a secondary accumulation vector (m_Accumulation). Provides serialization and version-aware deserialization so save/network formats remain compatible across game versions. The deserialization path falls back to a computed accumulation (m_Pollution * 2f) for older versions that did not store accumulation explicitly.


Fields

  • public Unity.Mathematics.float2 m_Pollution Holds the current pollution values as a 2D vector (float2). Used to represent pollution magnitude/direction or two pollution channels, depending on game usage.

  • public Unity.Mathematics.float2 m_Accumulation Holds accumulated pollution values as a float2. Persisted starting with the version that introduced netPollutionAccumulation; for older data this field is reconstructed in Deserialize.

Properties

  • None (struct has no declared properties)

Constructors

  • Implicit parameterless constructor (default struct constructor) The struct defines no explicit constructors; use object initializer syntax or default initialization.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes both m_Pollution and m_Accumulation to the provided writer. Uses writer.Write(float2) for each vector.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Reads m_Pollution from the reader. If the reader.context.version is at least Version.netPollutionAccumulation, it also reads m_Accumulation. Otherwise, for backward compatibility, it sets m_Accumulation = m_Pollution * 2f to approximate the older implicit behavior.

Notes: - TWriter and TReader are generic constraints for types implementing IWriter/IReader used by the game's serialization system. - The code depends on a version constant Version.netPollutionAccumulation to determine whether accumulation data exists in the serialized data.

Usage Example

// Create and set Pollution as a component on an entity (Unity.Entities / DOTS)
using Unity.Entities;
using Unity.Mathematics;
using Game.Net;

// assume entityManager is available and 'entity' has been created
var pollution = new Pollution {
    m_Pollution = new float2(10f, 5f),
    m_Accumulation = new float2(20f, 10f)
};

entityManager.AddComponentData(entity, pollution);

// Read it back
Pollution p = entityManager.GetComponentData<Pollution>(entity);
float2 current = p.m_Pollution;
float2 accumulated = p.m_Accumulation;

Additional modding notes: - If you extend this struct with new serialized fields, add a new version constant and update Deserialize to preserve backward compatibility. - This component is an ECS component (IComponentData) — use EntityManager/Systems to add, read, or update it in your mods.