Game.Debug.SoilWaterDebugSystem
Assembly: Game
Namespace: Game.Debug
Type: class
Base: GameSystemBase
Summary:
SoilWaterDebugSystem is a debug-only game system that visualizes soil water data using the gizmo batching system. It obtains the soil water map from SoilWaterSystem and a GizmoBatcher from GizmosSystem, schedules a job (SoilWaterGizmoJob) to draw wireframe cubes representing each cell's maximum capacity and current amount. The system is disabled by default (base.Enabled = false) and marked with [Preserve] on lifecycle methods to avoid stripping.
Fields
-
private SoilWaterSystem m_SoilWaterSystem
This field holds a reference to the game's SoilWaterSystem instance, used to obtain the soil water map and register read access when scheduling the job. It is initialized in OnCreate via World.GetOrCreateSystemManaged(). -
private GizmosSystem m_GizmosSystem
This field holds a reference to the GizmosSystem, used to obtain a GizmoBatcher for drawing debug geometry and to register write access for the batcher. It is initialized in OnCreate via World.GetOrCreateSystemManaged(). -
private struct SoilWaterGizmoJob : IJob
Nested job struct used to draw debug gizmos off the main thread. Fields: [ReadOnly] public NativeArray<SoilWater> m_SoilWaterMap
— read-only array of SoilWater entries for the map slice the job will visualize.public GizmoBatcher m_GizmoBatcher
— the batcher used to enqueue wire-cube gizmos.- Execute() — iterates a fixed cell range (i and j from 64 to 127), computes each cell index (i + j * 128), and if soilWater.m_Max > 0 draws two wire cubes: a grey cube sized by m_Max and a blue cube sized by m_Amount. Cell centers are obtained via SoilWaterSystem.GetCellCenter(index). Heights are scaled by dividing values by 400 (and extents by 200) to convert soil values into world-space heights.
Properties
- None.
Constructors
public SoilWaterDebugSystem()
Default constructor. No special initialization beyond what the base class provides; actual system references are acquired in OnCreate.
Methods
[Preserve] protected override void OnCreate()
: System.Void
Initializes the system references:- Calls base.OnCreate().
- Retrieves/creates GizmosSystem and SoilWaterSystem via World.GetOrCreateSystemManaged
(). -
Disables the system by setting base.Enabled = false so it does not run unless explicitly enabled (useful for debugging only).
-
[Preserve] protected override void OnUpdate()
: System.Void
Prepares and schedules the SoilWaterGizmoJob: - Calls m_SoilWaterSystem.GetMap(readOnly: true, out dependencies) to obtain a NativeArray
and its dependency JobHandle. - Calls m_GizmosSystem.GetGizmosBatcher(out dependencies2) to obtain a GizmoBatcher and its dependency JobHandle.
- Constructs SoilWaterGizmoJob with the map and batcher.
- Combines dependencies (base.Dependency, dependencies2, dependencies) and schedules the job via jobData.Schedule(...), storing the resulting JobHandle into base.Dependency.
-
Registers the scheduled dependency with the providing systems: m_SoilWaterSystem.AddReader(base.Dependency) and m_GizmosSystem.AddGizmosBatcherWriter(base.Dependency). This ensures correct reader/writer dependency tracking.
-
private struct SoilWaterGizmoJob.Execute()
: System.Void
Job execution logic (runs on a worker thread): - Loops i and j from 64 to 127 inclusive (grid range).
- Computes index = i + j * 128.
- Reads SoilWater entry; if m_Max > 0:
- Gets cell center via SoilWaterSystem.GetCellCenter(index).
- Computes two heights: one for m_Max and another for m_Amount (scaled by /400).
- Draws two wire cubes using the GizmoBatcher: a grey cube representing capacity (m_Max) and a blue cube representing current amount (m_Amount). Cubes use extents of 10 in X/Z and (value / 200) in Y.
Notes: - The hard-coded loop range (64..127) indicates this job only visualizes a central 64x64 region of a 128-wide map. Adjust if you need a different region. - [Preserve] attributes prevent the methods from being stripped by linkers/IL2CPP in release builds, ensuring debug functionality remains available when requested.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_GizmosSystem = base.World.GetOrCreateSystemManaged<GizmosSystem>();
m_SoilWaterSystem = base.World.GetOrCreateSystemManaged<SoilWaterSystem>();
base.Enabled = false; // Disabled by default; enable when you want to visualize soil water
}
[Preserve]
protected override void OnUpdate()
{
JobHandle dependencies;
JobHandle dependencies2;
SoilWaterGizmoJob jobData = new SoilWaterGizmoJob
{
m_SoilWaterMap = m_SoilWaterSystem.GetMap(readOnly: true, out dependencies),
m_GizmoBatcher = m_GizmosSystem.GetGizmosBatcher(out dependencies2)
};
base.Dependency = jobData.Schedule(JobHandle.CombineDependencies(base.Dependency, dependencies2, dependencies));
m_SoilWaterSystem.AddReader(base.Dependency);
m_GizmosSystem.AddGizmosBatcherWriter(base.Dependency);
}
Additional tips: - To enable visualization at runtime, set Enabled = true on this system instance (e.g., via a debug console or by toggling a debug option). - Be cautious passing complex managed objects into jobs; GizmoBatcher here is assumed to be job-compatible in this codebase. Ensure compatibility if you adapt this pattern.