Game.Debug.WindDebugSystem
Assembly: Assembly-CSharp
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary:
WindDebugSystem is a debug system used to visualize the game's wind simulation. It schedules a job (WindGizmoJob) that reads wind cells from WindSimulationSystem and draws debug gizmos (arrows and wire cubes) with a GizmosSystem's GizmoBatcher to indicate velocity vectors and pressure values at boundary cells of the wind grid. The system also queries TerrainSystem to map cell heights into world-space. By default the system is disabled in OnCreate; enable it to see the visualizations.
Fields
-
private WindSimulationSystem m_WindSimulationSystem
Holds a reference to the WindSimulationSystem used to retrieve the wind cell map and to register a reader dependency for the scheduled job. -
private TerrainSystem m_TerrainSystem
Used to obtain terrain height data (TerrainHeightData) so cell center heights can be mapped into world-space. -
private GizmosSystem m_GizmosSystem
Used to obtain the GizmoBatcher for drawing arrows and wire cubes, and for registering writer dependencies for the scheduled job. -
private struct WindGizmoJob : IJob
A nested private job struct that performs the actual per-cell iteration and drawing on a worker thread. See Methods -> WindGizmoJob.Execute for details.
Properties
- None (this class does not expose public properties).
Constructors
public WindDebugSystem()
Default constructor. The class relies on OnCreate to initialize its system references; constructor does not perform initialization.
Methods
protected override void OnCreate()
: System.Void
Initializes the required systems:- Retrieves or creates GizmosSystem, WindSimulationSystem and TerrainSystem via base.World.GetOrCreateSystemManaged
(). -
Disables the debug system by default (base.Enabled = false). Attributes: [Preserve]
-
protected override JobHandle OnUpdate(JobHandle inputDeps)
: Unity.Jobs.JobHandle
Builds and schedules a WindGizmoJob to draw wind debug gizmos. Behavior summary: - Gets terrain height data and computes a float2 terrainRange containing world-space min/max heights.
- Retrieves a NativeArray
via WindSimulationSystem.GetCells(out deps). - Retrieves a GizmoBatcher via m_GizmosSystem.GetGizmosBatcher(out dependencies).
- Schedules WindGizmoJob with combined dependencies (inputDeps, dependencies, deps).
-
Registers the returned JobHandle as a reader on the wind system (m_WindSimulationSystem.AddReader(jobHandle)) and as a writer for the gizmo batcher (m_GizmosSystem.AddGizmosBatcherWriter(jobHandle)). Returns the scheduled job handle. Attributes: [Preserve]
-
public void WindGizmoJob.Execute()
: System.Void
(Inside nested WindGizmoJob) Performs the drawing logic. Key details: - Iterates over all cells in the wind grid, but only processes boundary cells (i == 0 || j == 0 || k == 0 || i == maxX-1 || j == maxY-1), so only edges are visualized.
- For each processed cell:
- Computes a linear index: index = i + j * kResolution.x + k * kResolution.x * kResolution.y.
- Acquires the WindCell from the m_WindMap NativeArray and computes the cell center via WindSimulationSystem.GetCellCenter(index).
- Maps the cell center Y (height) using math.lerp between the terrainRange.x and terrainRange.y based on the cell's vertical index k.
- For each velocity component (m_Velocities.x, .y, .z) with absolute value > 0.001:
- Computes a start position offset from cell center (offset depends on axis and CellMapSystem
.kMapSize and resolution). - Draws an arrow from start to start + 50f * directionVector using m_GizmoBatcher.DrawArrow(...). The 50f factor scales the velocity for visualization.
- Axis mapping:
- m_Velocities.x → world X direction
- m_Velocities.y → world Z direction
- m_Velocities.z → world Y direction
- Computes a color for pressure: positive pressure uses a green ramp, negative pressure uses a red ramp:
- color = (pressure >= 0) ? Color(0, lerp(0,1, saturate(10 * pressure) ), 0) : Color( lerp(0,1, saturate(-10 * pressure)), 0, 0)
- Draws a wire cube centered on cellCenter with extents based on pressure (new float3(10f, 10f * pressure, 10f)) using m_GizmoBatcher.DrawWireCube(...).
- Uses WindSimulationSystem.kResolution and CellMapSystem
.kMapSize constants to compute offsets and iterate limits. Notes: - The job reads from the wind map (ReadOnly NativeArray) and writes to the gizmo batcher via its API; appropriate dependencies are combined prior to scheduling.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical OnCreate from WindDebugSystem:
m_GizmosSystem = base.World.GetOrCreateSystemManaged<GizmosSystem>();
m_WindSimulationSystem = base.World.GetOrCreateSystemManaged<WindSimulationSystem>();
m_TerrainSystem = base.World.GetOrCreateSystemManaged<TerrainSystem>();
// By default the system disables itself; enable it to see the visualization:
base.Enabled = true;
}
Notes and tips: - WindDebugSystem schedules a job that only reads wind data and draws gizmos. To avoid threading issues, the system registers the job as a reader (wind system) and as a writer for the gizmo batcher; do not modify those calls unless you understand the job dependency model. - The visualization scales (50f arrow length multiplier and 10f base cube size) are hardcoded in the job; modify them there if you need different visual scaling. - The job only draws the boundary cells to reduce visual clutter; you can adjust the condition to visualize interior cells if needed.