Skip to content

Game.Debug.AreaDebugSystem

Assembly: Assembly-CSharp
Namespace: Game.Debug

Type: class

Base: BaseDebugSystem

Summary:
AreaDebugSystem is an ECS debug system used by the game to draw visual gizmos for Area entities (lots, districts, map tiles, spaces, and surfaces) in the editor/debug view. It schedules a parallel IJobChunk (AreaGizmoJob) that walks Area archetype chunks and uses a GizmoBatcher from the GizmosSystem to draw nodes, lines and triangle outlines. The system exposes toggleable options for which area types to render and respects Area flags (Complete, Temp, Error) to change drawing styles/colors.


Fields

  • private EntityQuery m_AreaGroup
    This EntityQuery targets entities that have Area, Node buffer and Triangle buffer components and excludes Deleted and Hidden components. It is used to drive updates / scheduling for the job.

  • private GizmosSystem m_GizmosSystem
    Reference to the GizmosSystem instance used to obtain a GizmoBatcher for drawing debug shapes in a job-friendly way.

  • private Option m_LotOption
    Option toggle (added via AddOption) that controls whether Lot-type areas are drawn. Defaults to enabled.

  • private Option m_DistrictOption
    Option toggle controlling District-type area rendering. Defaults to enabled.

  • private Option m_MapTileOption
    Option toggle controlling MapTile-type area rendering. Defaults to disabled.

  • private Option m_SpaceOption
    Option toggle controlling Space-type area rendering. Defaults to enabled.

  • private Option m_SurfaceOption
    Option toggle controlling Surface-type area rendering. Defaults to enabled.

  • private TypeHandle __TypeHandle
    Private container struct that caches ComponentTypeHandle/BufferTypeHandle instances used by jobs. Populated in OnCreateForCompiler / __AssignHandles.

Properties

  • None declared on this class. (Note: the system inherits functionality from BaseDebugSystem, including AddOption and other helper members.)

Constructors

  • public AreaDebugSystem()
    Default parameterless constructor. The system performs its initialization primarily in OnCreate / OnCreateForCompiler rather than the constructor.

Methods

  • protected override void OnCreate()
    Initializes the system:
  • Calls base.OnCreate().
  • Obtains or creates the GizmosSystem via base.World.GetOrCreateSystemManaged().
  • Builds the EntityQuery m_AreaGroup (Area + Node buffer + Triangle buffer, excluding Deleted/Hidden).
  • Adds UI/options toggles for Lots, Districts, Map Tiles, Spaces and Surfaces (with default enabled states as configured).
  • Calls RequireForUpdate(m_AreaGroup) so the system only runs when matching entities exist.
  • Disables the system by default (base.Enabled = false).

  • protected override JobHandle OnUpdate(JobHandle inputDeps)
    Schedules the AreaGizmoJob as a parallel IJobChunk:

  • Fills the AreaGizmoJob with enabled/disabled option flags and component/buffer handles obtained from InternalCompilerInterface via the cached __TypeHandle.
  • Requests a GizmosBatcher from m_GizmosSystem (this returns a dependencies JobHandle for safe access).
  • Schedules the job over m_AreaGroup with combined dependencies and registers the resulting job handle with m_GizmosSystem by calling AddGizmosBatcherWriter(jobHandle).
  • Returns the scheduled JobHandle.

  • private void __AssignQueries(ref SystemState state)
    Compiler helper used in OnCreateForCompiler. (In this compilation output it creates and disposes an EntityQueryBuilder; actual query handle population is done elsewhere or via __TypeHandle.)

  • protected override void OnCreateForCompiler()
    Compiler-time initialization helper that calls __AssignQueries and populates __TypeHandle by calling its __AssignHandles with the system state reference.

  • private struct TypeHandle
    Holds read-only ComponentTypeHandle and BufferTypeHandle fields for each component used by the job (Area, Lot, District, MapTile, Space, Surface, Temp, Error, Node buffer, Triangle buffer). Contains:

  • __AssignHandles(ref SystemState state) — fills all component and buffer type handles from the provided SystemState (calls state.GetComponentTypeHandle/GetBufferTypeHandle with isReadOnly: true).

  • private struct AreaGizmoJob : IJobChunk
    Burst-compiled job that performs the actual gizmo drawing for each chunk. Key behavior in Execute:

  • Reads per-job booleans (m_LotOption, m_DistrictOption, m_MapTileOption, m_SpaceOption, m_SurfaceOption) to decide whether to draw a given area type.
  • Uses the presence of marker components (Lot, District, MapTile, Space, Surface) on chunks to decide color and scale. Default mapping:
    • Lot → cyan
    • District → white
    • MapTile → yellow
    • Space → green
    • Surface → magenta
    • None/default → black
  • If chunk has Error component, color is forced red. If has Temp component, forced blue.
  • For each Area entity in the chunk:
    • Reads its Node dynamic buffer and Triangle buffer.
    • Draws a sphere or wire-node for each node (based on elevation being float.MinValue).
    • Draws lines between consecutive nodes, and closes the loop if AreaFlags.Complete is set.
    • For each triangle, computes slightly inset triangle edge points (using MathUtils.TryNormalize and a computed newLength) and draws their edges with a subdued gray color.
  • The job uses a GizmoBatcher (m_GizmoBatcher) provided by GizmosSystem to issue thread-safe draw calls.
  • Implements the explicit IJobChunk.Execute wrapper to call its Execute method.

Usage details (colors, scales): - Node draw size is derived from AreaUtils.GetMinNodeDistance(AreaType) * 0.5f and a small inset for triangle edges uses 0.2f of that radius. - Triangles are drawn as three lines per triangle with a dim gray color for internal triangle edges.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Typical initialization performed by the system:
    m_GizmosSystem = base.World.GetOrCreateSystemManaged<GizmosSystem>();
    m_AreaGroup = GetEntityQuery(
        ComponentType.ReadOnly<Area>(),
        ComponentType.ReadOnly<Node>(),
        ComponentType.ReadOnly<Triangle>(),
        ComponentType.Exclude<Deleted>(),
        ComponentType.Exclude<Hidden>());

    // Add debug toggle options (examples shown in the system)
    m_LotOption      = AddOption("Lots", defaultEnabled: true);
    m_DistrictOption = AddOption("Districts", defaultEnabled: true);
    m_MapTileOption  = AddOption("Map Tiles", defaultEnabled: false);
    m_SpaceOption    = AddOption("Spaces", defaultEnabled: true);
    m_SurfaceOption  = AddOption("Surfaces", defaultEnabled: true);

    RequireForUpdate(m_AreaGroup);
    base.Enabled = false; // disabled by default; enable from debug UI or code to see gizmos
}

Notes and tips: - Enable the system (set Enabled = true) or activate it from the in-game debug UI to visualize areas. - The job is Burst-compiled and runs as an IJobChunk; avoid accessing UnityEngine objects from inside the job — the job strictly uses the GizmoBatcher abstraction for thread-safe drawing. - If you add new area-related marker components, update AreaGizmoJob and TypeHandle to include them and the color/option logic.