Game.Debug.CoverageDebugSystem
Assembly: Assembly-CSharp
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary:
CoverageDebugSystem is a debug visualization system used to draw per-edge service coverage gizmos in the editor/game view. It queries entities that have EdgeGeometry and a ServiceCoverage dynamic buffer and, for each enabled CoverageService option, schedules a Burst-compiled IJobChunk (CoverageGizmoJob) that iterates chunks, reads edge geometry and service coverage, and produces lines via a GizmoBatcher from the GizmosSystem. The system creates an Option entry per CoverageService (except the Count sentinel) so each service's coverage can be toggled on/off. The system is created disabled by default and requires the coverage entity query to be present for updates.
Fields
-
private EntityQuery m_CoverageGroup
Stores the EntityQuery used to select entities that have a ServiceCoverage buffer and EdgeGeometry component (and that are not Deleted or Temp). This query is used as the input for scheduling the CoverageGizmoJob. -
private GizmosSystem m_GizmosSystem
Reference to the GizmosSystem (retrieved from the World) used to obtain a GizmoBatcher for drawing lines and to register writers for scheduled jobs. -
private Dictionary<CoverageService, Option> m_CoverageOptions
Holds an Option object per CoverageService value (except CoverageService.Count). These options appear in the debug UI and determine which CoverageService(s) should be visualized during OnUpdate. -
private TypeHandle __TypeHandle
Holds ComponentTypeHandle/BufferTypeHandle instances for EdgeGeometry and ServiceCoverage respectively. These handles are assigned in OnCreateForCompiler and used when scheduling the Burst job to access component and buffer data inside jobs. -
private struct CoverageGizmoJob
(nested, Burst-compiled)
IJobChunk implementing the gizmo drawing logic. It reads a CoverageService index, an EdgeGeometry ComponentTypeHandle, a ServiceCoverage BufferTypeHandle, and a GizmoBatcher. For each entity in a chunk that has non-empty ServiceCoverage buffer, it samples coverage values, interpolates positions along edge geometry, computes colors between red and green, and draws vertical lines and connecting segments representing service coverage along the edge. -
private struct TypeHandle
(nested)
Compiler helper struct containing read-only handles: - ComponentTypeHandle
__Game_Net_EdgeGeometry_RO_ComponentTypeHandle - BufferTypeHandle
__Game_Net_ServiceCoverage_RO_BufferTypeHandle
It provides __AssignHandles(ref SystemState) to fill those handles from the SystemState (used by the generated/OnCreateForCompiler path).
Properties
- (none exposed)
The system does not expose public properties. Internally it uses type handles and options fields to manage state.
Constructors
public CoverageDebugSystem()
Default constructor. Marked with [Preserve] at the OnCreate method level; standard ECS system construction. No special runtime work is performed in the constructor itself — initialization occurs in OnCreate.
Methods
protected override void OnCreate()
Initializes the system:- Retrieves the GizmosSystem from the World.
- Builds the EntityQuery for ServiceCoverage + EdgeGeometry and excludes Deleted and Temp.
- Initializes m_CoverageOptions and populates an Option entry for each CoverageService enum name (skipping CoverageService.Count). The first enum name is added as the default enabled option.
- Calls RequireForUpdate(m_CoverageGroup) so the system only runs when the query has matching entities.
-
Sets base.Enabled = false so the system is initially disabled.
-
protected override JobHandle OnUpdate(JobHandle inputDeps)
Called each frame when the system updates. For each CoverageService option that is enabled, it: - Prepares and schedules a CoverageGizmoJob via JobChunkExtensions.ScheduleParallel, supplying the service enum value, the component and buffer type handles (via InternalCompilerInterface.GetComponentTypeHandle/GetBufferTypeHandle), and a GizmoBatcher obtained from m_GizmosSystem.GetGizmosBatcher(out dependencies).
- Adds the returned job handle as a gizmos batcher writer via m_GizmosSystem.AddGizmosBatcherWriter(jobHandle2).
-
Combines all scheduled job handles into the returned JobHandle so the system's dependencies are tracked correctly.
-
protected override void OnCreateForCompiler()
Called by generated/compiled code paths to set up query and type handles when using the compiled/IL2CPP/optimized pipeline. It calls __AssignQueries to initialize any generated queries and assigns component/buffer handles by calling __TypeHandle.__AssignHandles(ref base.CheckedStateRef). -
private void __AssignQueries(ref SystemState state)
Generated helper that ensures any compiled-time queries exist. The implementation in the source creates and disposes an empty EntityQueryBuilder (placeholder in this file). -
void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
(nested CoverageGizmoJob)
The explicit interface implementation forwards to the typed Execute method that performs the chunk iteration and gizmo drawing (described above).
Notes on the drawing algorithm inside CoverageGizmoJob.Execute: - Reads EdgeGeometry per entity and the ServiceCoverage dynamic buffer. - For a given CoverageService index (m_Service) it reads serviceCoverage.m_Coverage (float2) representing coverage at start/end. - Interpolates positions across the start and end edge sides, draws vertical segments scaled by coverage * 10f, and interpolates colors between red and green based on coverage values. - Connects successive vertical segments with lines so the coverage is visualized continuously along the edge.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Get the GizmosSystem and set up the coverage query/options as in the original implementation.
m_GizmosSystem = base.World.GetOrCreateSystemManaged<GizmosSystem>();
m_CoverageGroup = GetEntityQuery(ComponentType.ReadOnly<ServiceCoverage>(),
ComponentType.ReadOnly<EdgeGeometry>(),
ComponentType.Exclude<Deleted>(),
ComponentType.Exclude<Temp>());
// Add debug options for each CoverageService (done by the system).
m_CoverageOptions = new Dictionary<CoverageService, Option>();
string[] names = Enum.GetNames(typeof(CoverageService));
Array values = Enum.GetValues(typeof(CoverageService));
for (int i = 0; i < names.Length; i++)
{
CoverageService coverageService = (CoverageService)values.GetValue(i);
if (coverageService != CoverageService.Count)
{
// AddOption is provided by BaseDebugSystem and returns an Option representing a toggle in the UI.
m_CoverageOptions.Add(coverageService, AddOption(names[i], i == 0));
}
}
RequireForUpdate(m_CoverageGroup);
base.Enabled = false; // start disabled; user can enable the system via the debug UI
}
Additional notes: - The job uses Burst and parallel scheduling; the system must supply correct component and buffer type handles via the TypeHandle assignment performed in OnCreateForCompiler. - CoverageService is an enum key into the ServiceCoverage dynamic buffer; coverage values are stored in a float2 (m_Coverage.x/m_Coverage.y) and used to interpolate visualizations.