Skip to content

Game.Rendering.UndergroundViewSystem

Assembly:
Assembly-CSharp.dll

Namespace:
Game.Rendering

Type:
public class UndergroundViewSystem

Base:
GameSystemBase

Summary:
UndergroundViewSystem is a game system responsible for determining which underground-related visuals and overlays should be active each frame. It reads the currently active tool and infomode data (net geometry, net status, coverage) to set flags such as undergroundOn, tunnelsOn, pipelinesOn, subPipelinesOn, waterwaysOn, contourLinesOn and markersOn. The system also updates utility LODs via UtilityLodUpdateSystem when relevant utility types change, and toggles camera culling masks for Waterway and Marker layers. It handles initialization of required systems and an EntityQuery used to examine infoview components.


Fields

  • private ToolSystem m_ToolSystem
    Holds a reference to the ToolSystem used to inspect the currently active tool and its requirements (snap masks, required nets/pipelines).

  • private UtilityLodUpdateSystem m_UtilityLodUpdateSystem
    Reference to the system that updates utility LODs. Used to trigger LOD updates when utility types change.

  • private RenderingSystem m_RenderingSystem
    Reference to the rendering system used to check rendering-related flags (e.g., hideOverlay) that affect marker visibility.

  • private EntityQuery m_InfomodeQuery
    EntityQuery that matches entities with InfomodeActive plus any of InfoviewNetGeometryData, InfoviewNetStatusData or InfoviewCoverageData. Used to inspect current infomode state.

  • private bool m_LastWasWaterways
    Tracks previous frame state of waterwaysOn to detect changes and update camera culling mask only when needed.

  • private bool m_LastWasMarkers
    Tracks previous frame state of markersOn to detect changes and update camera culling mask only when needed.

  • private bool m_Loaded
    Set when OnGameLoaded is invoked; used to suppress an immediate UtilityLodUpdateSystem.Update on the first change after load.

  • private UtilityTypes m_LastUtilityTypes
    Stores the previously observed set of utility types so the system can detect changes and trigger LOD updates.

  • private TypeHandle __TypeHandle
    Instance of the nested TypeHandle struct that stores ComponentTypeHandle instances for infoview component types. Used to get component data safely in OnUpdate.

  • (Nested) private struct TypeHandle
    Contains read-only ComponentTypeHandle fields for InfoviewNetGeometryData, InfoviewNetStatusData and InfoviewCoverageData and a method __AssignHandles to initialize them from a SystemState.


Properties

  • public bool undergroundOn { get; private set }
    True if the current tool or infomode requires the underground view to be active.

  • public bool tunnelsOn { get; private set }
    True when tunnel-related visuals (roads, train, tram, subway, etc.) should be shown.

  • public bool pipelinesOn { get; private set }
    True when pipeline visuals (power, water, sewage, resource lines, or combination) should be shown.

  • public bool subPipelinesOn { get; private set }
    True when subpipeline (low/high voltage, water, sewage) visuals should be active.

  • public bool waterwaysOn { get; private set }
    True when waterway visuals should be shown (also used to update the camera culling mask for the Waterway layer).

  • public bool contourLinesOn { get; private set }
    True when contour line snap is active for the current tool.

  • public bool markersOn { get; private set }
    True when overlay markers are visible (driven by RenderingSystem.hideOverlay); also used to update the camera culling mask for Marker layer.

  • public UtilityTypes utilityTypes { get; private set }
    Bitmask describing which utility types are currently relevant (LowVoltageLine, HighVoltageLine, WaterPipe, SewagePipe, Resource). Changing this may trigger a utility LOD update.


Constructors

  • public UndergroundViewSystem()
    Default constructor. Marked with [Preserve] attribute in the source and relies on OnCreate for initialization of references to other systems and the EntityQuery.

Methods

  • protected override void OnCreate()
    Initializes references to required systems (ToolSystem, UtilityLodUpdateSystem, RenderingSystem) and constructs the EntityQuery (m_InfomodeQuery) that looks for InfomodeActive plus any InfoviewNetGeometryData, InfoviewNetStatusData, or InfoviewCoverageData.

  • protected override void OnGameLoaded(Context serializationContext)
    Sets an internal flag (m_Loaded) indicating that a game load occurred. This flag is used to avoid unnecessary immediate LOD updates when detecting utility type changes triggered by loading.

  • private bool GetLoaded()
    Checks and clears the m_Loaded flag. Returns true one time after a load (consumes the flag) and false otherwise.

  • protected override void OnUpdate()
    Core per-frame logic. Steps:

  • Reads m_ToolSystem.activeTool, and if present uses its required flags and selected snap to set undergroundOn, tunnelsOn, pipelinesOn, subPipelinesOn, waterwaysOn, contourLinesOn.
  • Sets markersOn based on RenderingSystem.hideOverlay.
  • Resets utilityTypes and, if any entities match m_InfomodeQuery, iterates chunks and their Infoview component arrays to update tunnelsOn/waterwaysOn/pipeline flags and the utilityTypes bitmask according to Infoview data (NetType, NetStatusType, and presence of coverage data).
  • If utilityTypes changed (compared to m_LastUtilityTypes), triggers m_UtilityLodUpdateSystem.Update() unless this is the first update after loading.
  • If waterwaysOn changed, adjusts Camera.main.cullingMask to include/exclude the "Waterway" layer.
  • If markersOn changed, adjusts Camera.main.cullingMask to include/exclude the "Marker" layer.

  • private void __AssignQueries(ref SystemState state)
    Called from OnCreateForCompiler; currently contains a placeholder EntityQueryBuilder call. Intended to allocate/assign queries required by the compiler-generated path.

  • protected override void OnCreateForCompiler()
    Compiler helper method: invokes __AssignQueries and calls __TypeHandle.__AssignHandles to prepare ComponentTypeHandles with the SystemState.

  • (Nested) public void TypeHandle.__AssignHandles(ref SystemState state)
    Initializes each ComponentTypeHandle (InfoviewNetGeometryData, InfoviewNetStatusData, InfoviewCoverageData) using state.GetComponentTypeHandle(isReadOnly: true).


Usage Example

// Example: check the UndergroundViewSystem flags from another system or MonoBehaviour
var world = World.DefaultGameObjectInjectionWorld;
if (world != null)
{
    var uds = world.GetExistingSystemManaged<Game.Rendering.UndergroundViewSystem>();
    if (uds != null)
    {
        if (uds.tunnelsOn)
        {
            // Perform logic when tunnel visuals are active (e.g., enable a custom overlay)
        }

        if (uds.utilityTypes.HasFlag(UtilityTypes.WaterPipe))
        {
            // React to presence of water pipes in the infoview
        }
    }
}

Additional notes: - The system uses ComponentTypeHandle in a DOTS-friendly way to read Infoview component arrays from archetype chunks. It relies on a temporary NativeArray allocation when iterating matching chunks in OnUpdate. - Camera culling mask updates use LayerMask.NameToLayer("Waterway") and LayerMask.NameToLayer("Marker"); ensure those layers exist in the project or culling adjustments will have no effect. - UtilityTypes is treated as a bitmask; changing observed utility types prompts a LOD update through UtilityLodUpdateSystem (unless suppressed right after load).