Game.Debug.DensityDebugSystem
Assembly: Game
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary: DensityDebugSystem is an ECS debug system used to visualize "density" data on network edges. It schedules a Burst-compiled IJobChunk (DensityGizmoJob) that reads EdgeGeometry and Density components, then draws vertical gizmo lines (and connecting segments) along the edge centerline to show local density values. The system obtains a GizmoBatcher from GizmosSystem to submit drawing commands. It is disabled by default and requires an entity query for edges with Density and EdgeGeometry to run.
Fields
-
private Unity.Entities.EntityQuery m_EdgeGroup
Used to select entities that have Density and EdgeGeometry components and exclude Deleted and Temp. The query is set up in OnCreate and used to schedule the gizmo job only for relevant edge entities. -
private GizmosSystem m_GizmosSystem
Reference to the game's GizmosSystem retrieved from the World. Used to get a GizmoBatcher for drawing and to register a writer dependency. -
private TypeHandle __TypeHandle
Container for ComponentTypeHandle instances (read-only handles for EdgeGeometry and Density). Populated in OnCreateForCompiler via __AssignHandles and then converted to actual ComponentTypeHandles when scheduling the job.
Properties
- None.
This system does not expose public properties.
Constructors
public DensityDebugSystem()
Default constructor. Marked with [Preserve] on lifecycle methods; the system uses the standard ECS creation flow and initialization occurs in OnCreate/OnCreateForCompiler.
Methods
-
protected override void OnCreate()
: System.Void
Initializes the system: gets/creates the GizmosSystem, constructs the m_EdgeGroup EntityQuery (Density + EdgeGeometry, excluding Deleted and Temp), disables the system by default (base.Enabled = false) and calls RequireForUpdate(m_EdgeGroup) so the system only runs when matching entities exist. -
protected override JobHandle OnUpdate(JobHandle inputDeps)
: Unity.Jobs.JobHandle
Schedules the Burst-compiled DensityGizmoJob in parallel across the m_EdgeGroup. It sets up the ComponentTypeHandles for EdgeGeometry and Density from the stored TypeHandle, retrieves a GizmoBatcher from the GizmosSystem (receiving additional dependencies), schedules the job with combined dependencies, and registers the batcher writer dependency with the GizmosSystem. Returns the composed inputDeps. -
protected override void OnCreateForCompiler()
: System.Void
Compiler-time helper used by generated code paths: assigns queries and component handles via internal helper methods so the system's TypeHandle is prepared for execution. -
private void __AssignQueries(ref SystemState state)
: System.Void
Internal helper used by the compiler-generated initialization path. In this implementation it constructs (and immediately disposes) an EntityQueryBuilder; in practice, the relevant EntityQuery was built in OnCreate. -
(nested)
private struct DensityGizmoJob : IJobChunk
Burst-compiled chunk job that performs the actual gizmo drawing. Fields: ComponentTypeHandle<EdgeGeometry> m_EdgeGeometryType
(read-only)ComponentTypeHandle<Density> m_DensityType
(read-only)GizmoBatcher m_GizmoBatcher
Execute(in ArchetypeChunk, int, bool, in v128): For each entity in the chunk, reads EdgeGeometry and Density, computes a color from red -> green using saturate(5 * density), computes sample positions along the start and end middle sections (using ceil of middleLength halves), and draws vertical lines whose height is density * 100 and connecting lines between samples to visualize density along the edge.
- (nested)
private struct TypeHandle
Holds the ComponentTypeHandleand ComponentTypeHandle (both read-only) and an AggressivelyInlined method __AssignHandles(ref SystemState state) to acquire those handles from the SystemState.
Usage Example
// Example: enable the debug system so it draws in-editor/runtime
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// The system disables itself by default, enable it to see density gizmos:
this.Enabled = true;
}
Notes: - The visual height of each gizmo vertical line is density.m_Density * 100f. - Color mapping: Color.Lerp(Color.red, Color.green, saturate(5 * density)) so values near 0 are red, higher values go toward green. - The job is Burst-compiled and scheduled with ScheduleParallel for performance; ensure you handle job dependencies if interacting with other systems that also write gizmos or components used here.