Game.ZoneAmbienceValueDebugSystem
Assembly: Assembly-CSharp
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary: A debug system that visualizes per-zone ambience values for each GroupAmbienceType by drawing gizmo lines above each ambience cell. It schedules a Burst-compiled IJob (ZoneAmbienceValueGizmoJob) to read the ambience map and issue draw commands to a GizmoBatcher. The system creates toggleable options for each ambience group so the user can enable visualization per-type. It also manages a persistent NativeArray of distinct colors used for rendering different ambience types.
Fields
-
private ZoneAmbienceSystem m_ZoneAmbienceSystem
Holds a reference to the ZoneAmbienceSystem (retrieved from the world) used to obtain the ambience map for reading. -
private GizmosSystem m_GizmosSystem
Holds a reference to the GizmosSystem (retrieved from the world) used to obtain a GizmoBatcher and register writers so scheduled jobs can emit gizmos safely. -
private Dictionary<GroupAmbienceType, Option> m_CoverageOptions
A dictionary mapping each GroupAmbienceType to an Option object created via AddOption. These options are used to enable/disable visualization per ambience type. The Option type has anenabled
flag checked in OnUpdate. -
private NativeArray<Color> m_DistinctColors
A persistent NativeArray (Allocator.Persistent) of 22 distinct Color values generated in OnCreate by sampling the HSV hue circle. Disposed in OnDestroy. Used by the job to color gizmo lines for each ambience type. -
private struct ZoneAmbienceValueGizmoJob
A private nested Burst-compiled IJob that performs the per-cell drawing: - Fields:
public GroupAmbienceType m_Type
— which ambience type to render.[ReadOnly] public NativeArray<ZoneAmbienceCell> m_AmbienceMap
— the ambience map read-only.[ReadOnly] public NativeArray<Color> m_DistinctColors
— color lookup array.public GizmoBatcher m_GizmoBatcher
— the batcher used to draw lines.
- Behavior:
- Iterates all cells in m_AmbienceMap, computes cell center via ZoneAmbienceSystem.GetCellCenter(i), applies a fixed Y offset (385.7151f) and a per-type X/Z offset to avoid overlap, reads ambience value via zoneAmbienceCell.m_Value.GetAmbience(m_Type), then draws a vertical line from the center up to the ambience value colored by the type.
Properties
- This type has no public properties.
Constructors
public ZoneAmbienceValueDebugSystem()
Default parameterless constructor. The system itself performs initialization in OnCreate rather than the constructor.
Methods
[Preserve] protected override void OnCreate()
Initializes references and state:- Calls base.OnCreate().
- Obtains ZoneAmbienceSystem and GizmosSystem from base.World.
- Creates m_CoverageOptions dictionary and populates it by iterating enum GroupAmbienceType (skipping GroupAmbienceType.Count). For each type it calls AddOption(name, i == 0) to create UI toggles (first type enabled by default).
- Allocates m_DistinctColors as a persistent NativeArray of length 22 and fills it with HSV-based distinct colors.
-
Disables the system by default (base.Enabled = false). Note: AddOption and Option come from BaseDebugSystem; options control which ambience types are visualized.
-
[Preserve] protected override void OnDestroy()
Cleans up resources: - Calls base.OnDestroy().
-
Disposes the m_DistinctColors NativeArray to avoid memory leaks.
-
[Preserve] protected override JobHandle OnUpdate(JobHandle inputDeps)
Schedules visualization jobs for all enabled ambience types: - Iterates m_CoverageOptions. For each enabled option:
- Requests the ambience map from m_ZoneAmbienceSystem.GetMap(readOnly: true, out dependencies).
- Requests a GizmoBatcher from m_GizmosSystem.GetGizmosBatcher(out dependencies2).
- Constructs and schedules a ZoneAmbienceValueGizmoJob with the combined dependencies (dependencies + dependencies2 + base.Dependency).
- Calls m_GizmosSystem.AddGizmosBatcherWriter(jobHandle2) to inform the gizmo system about the job writer.
- Combines each job's JobHandle into the returned JobHandle so the system waits for all scheduled jobs.
- Returns the combined job handle. Important details:
- The job uses read-only access to the ambience map and colors.
- Dependencies from GetMap and GetGizmosBatcher are combined with the system's base.Dependency before scheduling.
-
The method ensures proper dependency chaining between systems and jobs.
-
private void ZoneAmbienceValueGizmoJob.Execute()
The Burst-compiled job execution body: - Loops over every ambience cell index:
- Gets ZoneAmbienceCell from m_AmbienceMap[i].
- Computes cell center using ZoneAmbienceSystem.GetCellCenter(i); then offsets Y by 385.7151f.
- Reads the ambience value for m_Type via zoneAmbienceCell.m_Value.GetAmbience(m_Type).
- Applies a type-dependent X/Z offset so each type's lines are slightly separated.
- Draws a vertical line from the cell center up to the ambience value using m_GizmoBatcher.DrawLine with a color pulled from m_DistinctColors[(int)m_Type]. Notes:
- This job runs in Burst; avoid managed allocations inside it (all data passed is blittable or provided by GizmoBatcher).
- The Y offset and separation offset are hardcoded constants taken from the original system.
Usage Example
// Example: enable the system and enable visualization for a specific GroupAmbienceType
var debugSystem = world.GetOrCreateSystemManaged<Game.Debug.ZoneAmbienceValueDebugSystem>();
debugSystem.Enabled = true; // enable the debug system (it is disabled by default)
// To toggle a specific option you can access m_CoverageOptions if exposed, or
// rely on the built-in AddOption UI created in OnCreate. If you have access to the Option:
// debugSystem.m_CoverageOptions[GroupAmbienceType.Noise].enabled = true;
// The system will schedule a Burst job per enabled GroupAmbienceType each frame,
// request the ambience map and gizmo batcher, and draw vertical gizmo lines
// representing ambience values above each cell.
Notes and caveats: - The class allocates a NativeArray with Allocator.Persistent; OnDestroy disposes it — ensure the system lifecycle runs OnDestroy, otherwise the NativeArray will leak. - The ZoneAmbienceValueGizmoJob is Burst-compiled; all data passed to it must be compatible with Burst (which the code ensures by using NativeArray and blittable types). - This is a debug-only system intended for visualization and likely not suitable for release builds unless explicitly enabled.