Skip to content

Game.Debug.PollutionDebugSystem

Assembly: Assembly-CSharp (game)
Namespace: Game.Debug

Type: class

Base: BaseDebugSystem

Summary: Provides an in-game debug visualization for pollution in Cities: Skylines 2. PollutionDebugSystem reads ground, air and noise pollution maps from their respective simulation systems and schedules a job (PollutionGizmoJob) to draw gizmos (wire cubes and cones) that represent pollution intensity. The system exposes toggleable options for Ground, Air and Noise visualization and uses the Unity Job System and native arrays to perform drawing work off the main thread (the actual drawing is batched through a GizmoBatcher). The system is disabled by default after creation.


Fields

  • private struct PollutionGizmoJob : IJob This is a private nested job type used to iterate over the pollution maps and issue gizmo draw calls via a GizmoBatcher. It reads NativeArray maps for ground, air and noise pollution, and uses boolean flags (options) and a base height from the climate system to position and color gizmos based on pollution values.

Inner fields: - [ReadOnly] public NativeArray<GroundPollution> m_PollutionMap
Ground pollution map (read-only). - [ReadOnly] public NativeArray<AirPollution> m_AirPollutionMap
Air pollution map (read-only). - [ReadOnly] public NativeArray<NoisePollution> m_NoisePollutionMap
Noise pollution map (read-only). - public GizmoBatcher m_GizmoBatcher
Batcher used to issue gizmo draw calls in a thread-safe/batched manner. - public bool m_GroundOption
Whether ground pollution gizmos should be drawn. - public bool m_AirOption
Whether air pollution gizmos should be drawn. - public bool m_NoiseOption
Whether noise pollution gizmos should be drawn. - public float m_BaseHeight
Base height offset (from ClimateSystem) applied to gizmo positions.

Execute behavior (summary): - Adds a base vertical offset using m_BaseHeight. - If ground option enabled, iterates ground cells and draws wire cubes at cell centers; cube height and vertical offset are proportional to pollution; color is interpolated green → yellow → red with threshold at 8000. - If air option enabled, iterates air pollution cells and draws wire cones positioned higher above ground; cone height relates to pollution and color interpolates similarly. - If noise option enabled, iterates noise pollution cells and draws wire cubes with heights and positions based on noise; color interpolates similarly. - Uses GroundPollutionSystem.GetCellCenter, AirPollutionSystem.GetCellCenter and NoisePollutionSystem.GetCellCenter to compute positions.

  • private GroundPollutionSystem m_GroundPollutionSystem
    Reference to the ground pollution simulation system used to obtain the ground pollution map and to register a read dependency for the scheduled job.

  • private AirPollutionSystem m_AirPollutionSystem
    Reference to the air pollution simulation system used to obtain the air pollution map and to register a read dependency.

  • private NoisePollutionSystem m_NoisePollutionSystem
    Reference to the noise pollution simulation system used to obtain the noise pollution map and to register a read dependency.

  • private ClimateSystem m_ClimateSystem
    Used to read temperatureBaseHeight which is applied as a base vertical offset for gizmos.

  • private GizmosSystem m_GizmosSystem
    Used to obtain a GizmoBatcher for drawing and to register the batcher write dependency.

  • private Option m_GroundOption
    UI option toggle for ground pollution visualization.

  • private Option m_AirOption
    UI option toggle for air pollution visualization.

  • private Option m_NoiseOption
    UI option toggle for noise pollution visualization.

Properties

  • This system exposes no public properties. All configuration is via AddOption toggles returned as Option instances which hold their own enabled states.

Constructors

  • public PollutionDebugSystem()
    Default constructor. The system's OnCreate handles initialization and the system is disabled by default after creation.

Methods

  • [Preserve] protected override void OnCreate() : System.Void
    Initializes references and UI options. Called when the system is created. Behavior:
  • Calls base.OnCreate().
  • Retrieves or creates required systems from base.World: GizmosSystem, GroundPollutionSystem, AirPollutionSystem, NoisePollutionSystem, ClimateSystem.
  • Registers three options via AddOption: "Ground pollution", "Air pollution", "Noise pollution" — all enabled by default.
  • Sets base.Enabled = false so the debug system is off by default until explicitly enabled.

  • [Preserve] protected override JobHandle OnUpdate(JobHandle inputDeps) : Unity.Jobs.JobHandle
    Schedules the PollutionGizmoJob and wires up dependencies. Behavior:

  • Obtains read-only NativeArray maps from each pollution system (GetMap(readOnly: true, out dependenciesX)).
  • Obtains a GizmoBatcher from the GizmosSystem (GetGizmosBatcher(out dependencies4)).
  • Fills a PollutionGizmoJob struct with the obtained arrays, batcher, option flags and climate base height.
  • Schedules the job using JobHandle.CombineDependencies to combine the inputDeps and the returned map/batcher dependencies.
  • Adds the batcher writer job handle via m_GizmosSystem.AddGizmosBatcherWriter(jobHandle).
  • Calls AddReader(jobHandle) on each pollution system to register the read dependency.
  • Returns the scheduled job handle.
  • Note: The job uses read-only NativeArrays and the GizmoBatcher to batch draw calls; job scheduling ensures correct ordering with simulation systems.

  • private void PollutionGizmoJob.Execute() : System.Void
    (Described above under the nested struct.) Iterates the provided pollution maps and issues gizmo draw calls scaled and colored by pollution intensity.

Usage Example

// Enable the debug system and toggle options at runtime:
var pollutionDebug = World.Instance.GetOrCreateSystemManaged<Game.Debug.PollutionDebugSystem>();
pollutionDebug.Enabled = true;

// To toggle options you can access the Option instances (example pseudocode):
// Note: Option is an internal UI wrapper; actual usage depends on available API exposure.
pollutionDebug.m_GroundOption.enabled = true;
pollutionDebug.m_AirOption.enabled = false;
pollutionDebug.m_NoiseOption.enabled = true;

// The system will then schedule jobs each frame to draw gizmos for the enabled pollution maps.

Notes and tips: - The visualization uses thresholds at 8000 pollution to interpolate colors from green → yellow → red. - The job-based approach keeps the main thread free; ensure you respect Unity's job and native container rules when integrating with other systems. - The system is disabled by default (OnCreate sets Enabled = false); enable it explicitly to see visuals.