Skip to content

Game.UI.Tooltip.PollutionTooltipSystem

Assembly:
Assembly-CSharp

Namespace:
Game.UI.Tooltip

Type:
class

Base:
TooltipSystemBase

Summary:
PollutionTooltipSystem is an ECS-managed tooltip provider used by the Default Tool infoview in Cities: Skylines 2. It listens for active infoview heatmap or building-status modes and, when the default tool is active and the user is hovering over the world, performs a raycast to sample pollution / water / garbage values from various simulation systems and shows the appropriate IntTooltip over the mouse. The system queries different pollution maps (ground, air, noise, ground water, surface water) or building garbage accumulation depending on the active infoview type.


Fields

  • private PrefabSystem m_PrefabSystem
    Used to access prefab-related data. Initialized in OnCreate via World.GetOrCreateSystemManaged().

  • private ToolSystem m_ToolSystem
    Reference to the global ToolSystem (used to check the active tool and active infoview). Initialized in OnCreate.

  • private DefaultToolSystem m_DefaultTool
    Reference to the default tool system instance. The system only operates while this tool is active.

  • private RaycastSystem m_RaycastSystem
    Raycast provider used to perform raycasts from the camera into the world. Inputs are queued and results are read back to determine the hovered world position.

  • private CameraUpdateSystem m_CameraUpdateSystem
    Used to get the current viewer/camera for computing a raycast line.

  • private GroundPollutionSystem m_GroundPollutionSystem
    Provides ground pollution map access and queries.

  • private NoisePollutionSystem m_NoisePollutionSystem
    Provides noise pollution map access and queries.

  • private AirPollutionSystem m_AirPollutionSystem
    Provides air pollution map access and queries.

  • private GroundWaterSystem m_GroundWaterSystem
    Provides ground water (polluted groundwater) map access.

  • private WaterSystem m_WaterSystem
    Provides water surface data (depth, polluted fraction) for sampling surface water features.

  • private EntityQuery m_ActiveInfomodeQuery
    EntityQuery that matches active infomode entities. Used to iterate currently active infoviews / heatmaps. Built in OnCreate with required component criteria.

  • private IntTooltip m_Garbage
    Preconfigured IntTooltip instance for garbage accumulation (icon, label, unit, path).

  • private IntTooltip m_AirPollution
    Preconfigured IntTooltip instance for air pollution.

  • private IntTooltip m_GroundPollution
    Preconfigured IntTooltip instance for ground pollution.

  • private IntTooltip m_NoisePollution
    Preconfigured IntTooltip instance for noise pollution.

  • private IntTooltip m_WaterPollution
    Preconfigured IntTooltip instance for water pollution (used for both surface and ground water results).

  • private RaycastResult m_RaycastResult
    Cached last raycast result. Used by the private property raycastResult which lazily enqueues and reads raycasts when needed.

Properties

  • private RaycastResult raycastResult { get; set; }
    This private property wraps m_RaycastResult. The getter will perform a lazy raycast if m_RaycastResult.m_Owner is Entity.Null and a camera viewer is available. It builds a RaycastInput using the viewer camera, adds it to the RaycastSystem, then reads the first result (if any) from the RaycastSystem result NativeArray and caches it in m_RaycastResult. The setter simply stores the provided RaycastResult.

Notes: - The getter uses TypeMask.Terrain | TypeMask.StaticObjects and CollisionMask.OnGround | CollisionMask.Overground. - The lazy behavior means the system only performs a raycast when an infoview needs sampling.

Constructors

  • public PollutionTooltipSystem()
    Default parameterless constructor (annotated [Preserve] in the original source). No custom initialization outside of OnCreate.

Methods

  • protected override void OnCreate()
    Initializes references to several managed world systems (PrefabSystem, ToolSystem, DefaultToolSystem, RaycastSystem, CameraUpdateSystem, GroundPollutionSystem, NoisePollutionSystem, AirPollutionSystem, GroundWaterSystem, WaterSystem). It also constructs the EntityQuery m_ActiveInfomodeQuery used to detect active info modes and initializes several IntTooltip instances (m_Garbage, m_AirPollution, m_GroundPollution, m_NoisePollution, m_WaterPollution) with path, icon, label and unit. This sets up the tooltip content templates used later in OnUpdate.

Important details: - The EntityQuery looks for entities with PrefabData, InfomodeData and InfomodeActive, and requires at least one of InfoviewHeatmapData or InfoviewBuildingStatusData while excluding InfomodeGroup.

  • protected override void OnUpdate()
    Main runtime logic. Steps performed:
  • Early-out if the active tool is not the default tool, there is no active infoview, or the active infomode query is empty.
  • Clears cached raycastResult and iterates active infoview entities returned by the EntityQuery.
  • For InfoviewHeatmapData entries, it checks the heatmap type (GroundPollution, AirPollution, WaterPollution, GroundWaterPollution, Noise) and:
    • Ensures a valid raycast result exists (returns early if none).
    • Requests the appropriate simulation map or surface data via the corresponding system GetMap/GetSurfaceData call.
    • Completes the returned JobHandle before reading the NativeArray or WaterSurfaceData.
    • Samples the pollution/depth/polluted fraction at the raycast hit position and sets the corresponding IntTooltip.value.
    • Calls AddMouseTooltip(...) to queue that tooltip for display.
  • For InfoviewBuildingStatusData entries with BuildingStatusType.GarbageAccumulation:
    • Ensures a valid raycast result and that the raycast owner is a Building entity.
    • If the building has a GarbageProducer component, reads m_Garbage from it and calls AddMouseTooltip(m_Garbage).

Notes and safety: - This method intentionally calls dependencies.Complete() on JobHandles returned by map/surface queries to synchronously access NativeArray contents within the main thread. - The method uses Allocator.Temp when converting the EntityQuery to an entity array for iteration. - Raycast usage: the code performs a single raycast per frame per update when needed; if no raycast result is available, it will early return in many branches. - AddMouseTooltip is provided by the TooltipSystemBase (not shown) and is used to add the configured IntTooltip to the UI.

Usage Example

// Example showing how this system samples air pollution at the mouse hover position
// (This mirrors the logic inside PollutionTooltipSystem.OnUpdate)

[Preserve]
protected override void OnUpdate()
{
    // Only run when default tool and an active infoview exist (checks are present in the real system)
    raycastResult = default(RaycastResult); // reset cached raycast

    // Ensure a valid raycast result is available
    if (raycastResult.m_Owner == Entity.Null)
        return;

    // Get the air pollution map (read-only) and its JobHandle, then complete it to access data
    JobHandle deps;
    NativeArray<AirPollution> airMap = m_AirPollutionSystem.GetMap(readOnly: true, out deps);
    deps.Complete();

    // Sample the air pollution at the hit world position and show the tooltip
    AirPollution pollution = AirPollutionSystem.GetPollution(raycastResult.m_Hit.m_HitPosition, airMap);
    m_AirPollution.value = pollution.m_Pollution;
    AddMouseTooltip(m_AirPollution);
}

Additional notes for modders: - If you extend or query these systems yourself, be mindful to call Complete() on JobHandles before accessing NativeArray contents on the main thread, or use jobified access patterns. - The system assumes the DefaultTool is the only consumer for these mouse-based infoview tooltips; other tools/infoviews should guard similarly. - The IntTooltip instances are reused and updated each frame; do not keep references to their value fields expecting persistence across frames unless you manage copying them.