Skip to content

Game.Debug.GroundWaterDebugSystem

Assembly: Assembly-CSharp.dll
Namespace: Game.Debug

Type: class

Base: GameSystemBase

Summary: GroundWaterDebugSystem is a debug-only game system that visualizes the ground-water map as wireframe cubes (max capacity, current amount, and polluted amount) using the game's gizmo batching system. It schedules a Unity Job (GroundWaterGizmoJob) to iterate the ground-water map and submit draw calls to a GizmoBatcher, sampling terrain height for correct vertical placement. The system is created disabled by default and intended for debugging and visualization purposes only.


Fields

  • private struct GroundWaterGizmoJob : IJob
    GroundWaterGizmoJob is a private nested job type that performs the per-cell visualization work on a worker thread. Its Execute method iterates the ground-water map and issues gizmo draw calls via a GizmoBatcher.

  • public NativeArray<GroundWater> m_GroundWaterMap (ReadOnly)
    The ground-water map to read from. Provided by GroundWaterSystem.GetMap(readOnly: true, out dependencies). The job reads each GroundWater entry (m_Max, m_Amount, m_Polluted).

  • public TerrainHeightData m_TerrainHeightData (ReadOnly)
    Height data used to sample terrain elevation so gizmo cubes sit on the ground surface.

  • public GizmoBatcher m_GizmoBatcher
    A batcher used to submit wireframe cube draw calls. Provided by GizmosSystem.GetGizmosBatcher(out dependencies).

  • Execute() (IJob.Execute)
    For each map cell with m_Max > 0, the job:

    • computes the cell center (GroundWaterSystem.GetCellCenter),
    • samples terrain height to position cubes on surface,
    • computes heights for max, amount and polluted bars,
    • chooses a color for the amount bar based on pollution ratio,
    • draws three wire cubes (max = grey, amount = color, polluted = red if >0).
  • private GroundWaterSystem m_GroundWaterSystem
    Reference to the GroundWaterSystem used to obtain the ground-water map and to register readers for the scheduled job.

  • private GizmosSystem m_GizmosSystem
    Reference to the GizmosSystem used to obtain a GizmoBatcher for submitting debug draw calls.

  • private TerrainSystem m_TerrainSystem
    Reference to the TerrainSystem used to get TerrainHeightData for sampling surface heights.

Properties

  • This class does not define any public properties.
    (All relevant data is handled via fields and the scheduled job. The GameSystemBase provides the base Dependency and Enabled members.)

Constructors

  • public GroundWaterDebugSystem()
    Default constructor (marked with [Preserve] in source). The system's initialization logic runs in OnCreate; constructor does no additional work.

Methods

  • protected override void OnCreate() : System.Void
    Called when the system is created. Obtains and caches the required systems:

    • m_GizmosSystem = World.GetOrCreateSystemManaged()
    • m_GroundWaterSystem = World.GetOrCreateSystemManaged()
    • m_TerrainSystem = World.GetOrCreateSystemManaged() The method also sets base.Enabled = false so the debug visualization is off by default.
  • protected override void OnUpdate() : System.Void
    Called each frame while the system is enabled. It:

    • Retrieves the ground-water map as a read-only NativeArray and obtains its dependency handle.
    • Retrieves terrain height data.
    • Retrieves a GizmoBatcher and its dependency handle.
    • Constructs a GroundWaterGizmoJob with those inputs.
    • Schedules the job while combining dependencies (base.Dependency, gizmo and map dependencies).
    • Stores the resulting handle in base.Dependency.
    • Registers readers/writers with the respective systems:
    • m_GroundWaterSystem.AddReader(base.Dependency)
    • m_TerrainSystem.AddCPUHeightReader(base.Dependency)
    • m_GizmosSystem.AddGizmosBatcherWriter(base.Dependency) This ensures correct synchronization between the job and the main/other systems.
  • private void GroundWaterGizmoJob.Execute() : System.Void
    (See nested job description above.) Performs the actual per-cell drawing logic on a worker thread.

Usage Example

Enable the system (it's disabled by default) to visualize ground water. You can enable it from your mod initialization or a debug toggle:

// Turn on the debug visualization at runtime
var debugSystem = World.GetOrCreateSystemManaged<Game.Debug.GroundWaterDebugSystem>();
debugSystem.Enabled = true;

// Optionally, ensure it was created and initialized (OnCreate will cache required systems)

Or, if you want to modify OnCreate to enable immediately (not recommended for release builds):

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_GizmosSystem = base.World.GetOrCreateSystemManaged<GizmosSystem>();
    m_GroundWaterSystem = base.World.GetOrCreateSystemManaged<GroundWaterSystem>();
    m_TerrainSystem = base.World.GetOrCreateSystemManaged<TerrainSystem>();
    base.Enabled = true; // enable to start drawing groundwater gizmos
}

Notes and tips: - Because the visualization uses jobs and native arrays, the system registers readers/writers to ensure safe multithreaded access. - The gizmo boxes are sized to the ground-water grid cell (10×10 in X,Z) and scaled vertically relative to stored integer values: division by 200/400 is used to convert stored units into scene heights. - Keep this system disabled in release/production builds to avoid the overhead of iterating the entire ground-water map each frame.