Skip to content

Game.UI.Tooltip.TerrainToolTooltipSystem

Assembly: Game
Namespace: Game.UI.Tooltip

Type: class (CompilerGenerated)

Base: TooltipSystemBase

Summary:
Provides the in-game tooltip logic for the Terrain (terraforming) tool when that tool targets groundwater. The system: - Monitors whether the active tool is the TerrainTool and if it targets GroundWater. - Raycasts to the terrain to find the target cell. - Schedules a job (TempWaterPumpingTooltipSystem.GroundWaterReservoirJob) to compute reachable groundwater reservoir information for the targeted cell. - Converts the computed reservoir volume into a displayed groundwater volume tooltip value using WaterPipeParameterData parameters. - Manages a NativeReference to receive job results and ensures disposal on system destruction.


Fields

  • private ToolSystem m_ToolSystem
    Handles access to the game's tool management system. Used to check the active tool.

  • private TerrainToolSystem m_TerrainTool
    Reference to the terrain/terraforming tool system; used to detect whether the player is using the terrain tool and to read the currently selected prefab/target type.

  • private ToolRaycastSystem m_ToolRaycastSystem
    Used to get raycast results for the cursor / tool target to determine the world position/cell the player is pointing at.

  • private GroundWaterSystem m_GroundWaterSystem
    Access to the groundwater map and readers; used to fetch the groundwater map and register job-reading dependencies.

  • private EntityQuery m_ParameterQuery
    EntityQuery that requires WaterPipeParameterData to be present. The system uses this to obtain parameters needed for converting reservoir volume to gameplay units.

  • private IntTooltip m_GroundwaterVolume
    An IntTooltip instance configured with path "groundWaterCapacity", an icon, localized label, and unit "volume". This is the tooltip element populated and shown to the player when groundwater volume > 0.

  • private NativeReference<TempWaterPumpingTooltipSystem.GroundWaterReservoirResult> m_ReservoirResult
    A persistent NativeReference used to store the job's result (GroundWaterReservoirResult). Allocated with Allocator.Persistent and disposed in OnDestroy.

Properties

  • None declared in this class.
    {{ This system does not expose public properties. It uses private fields and overrides standard system lifecycle methods. }}

Constructors

  • public TerrainToolTooltipSystem()
    {{ Default parameterless constructor. Marked CompilerGenerated and Preserve attributes are present on the type and lifecycle methods to control code stripping. The actual initialization of state happens in OnCreate. }}

Methods

  • protected override void OnCreate()
    {{ Initializes the system:
  • Calls base.OnCreate().
  • Retrieves required systems from the World: ToolSystem, TerrainToolSystem, ToolRaycastSystem, GroundWaterSystem.
  • Creates an EntityQuery for WaterPipeParameterData and calls RequireForUpdate to ensure the query exists before updates.
  • Configures the m_GroundwaterVolume IntTooltip (path, icon, label, unit).
  • Allocates m_ReservoirResult as a persistent NativeReference for passing job results back to the main thread. This method prepares the system to run only when the required parameter data is present and ensures necessary resources are allocated. }}

  • protected override void OnDestroy()
    {{ Disposes the persistent NativeReference (m_ReservoirResult.Dispose()) and calls base.OnDestroy(). Ensures no native memory leaks. }}

  • protected override void OnUpdate()
    {{ Main update logic executed each frame:

  • Checks if the active tool is the TerrainTool, that the TerrainTool has a prefab targeting GroundWater, and that a raycast result is available.
  • If so, resets m_ReservoirResult to default, attempts to get the groundwater cell at the hit position, and if found:
    • Acquires a read-only NativeArray map and its job dependency.
    • Constructs a temporary NativeList containing the cell, creates a NativeParallelHashMap (empty) for pump capacities, and a NativeQueue to be used by the job.
    • Fills a TempWaterPumpingTooltipSystem.GroundWaterReservoirJob struct with the map, pump capacity map, temp pump cell list, queue, and the m_ReservoirResult reference.
    • Schedules the job combining the system's current dependency and the groundwater map dependency.
    • Disposes the temporary native collections with the scheduled dependency to ensure disposal happens after the job completes.
    • Calls m_GroundWaterSystem.AddReader(base.Dependency) to mark the system as a reader of the groundwater map for the duration of the job.
  • If conditions are not met, ensures m_ReservoirResult is reset to default. This method is careful to manage job dependencies and native-memory lifetimes, scheduling a job to compute reservoir data off the main thread and wiring its result back via the NativeReference. }}

  • private void ProcessResults()
    {{ Reads the value from m_ReservoirResult. If the computed reservoir volume (m_Volume) is greater than zero:

  • Retrieves the WaterPipeParameterData singleton through m_ParameterQuery.
  • Converts the computed reservoir volume to game groundwater volume using the formula: volumeDisplayed = Mathf.RoundToInt(singleton.m_GroundwaterReplenish / singleton.m_GroundwaterUsageMultiplier * reservoirVolume)
  • Sets m_GroundwaterVolume.value and, if > 0, adds the tooltip via AddMouseTooltip(m_GroundwaterVolume). This method handles converting job results into a user-visible tooltip value. }}

Usage Example

// This system is a World/System implementation and is created by the ECS world.
// Example: what the system already does in OnCreate (simplified)
[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_ToolSystem = World.GetOrCreateSystemManaged<ToolSystem>();
    m_TerrainTool = World.GetOrCreateSystemManaged<TerrainToolSystem>();
    m_ToolRaycastSystem = World.GetOrCreateSystemManaged<ToolRaycastSystem>();
    m_GroundWaterSystem = World.GetOrCreateSystemManaged<GroundWaterSystem>();
    m_ParameterQuery = GetEntityQuery(ComponentType.ReadOnly<WaterPipeParameterData>());
    RequireForUpdate(m_ParameterQuery);

    m_GroundwaterVolume = new IntTooltip
    {
        path = "groundWaterCapacity",
        icon = "Media/Game/Icons/Water.svg",
        label = LocalizedString.Id("Tools.GROUNDWATER_VOLUME"),
        unit = "volume"
    };

    // Allocate the native reference that will receive job results
    m_ReservoirResult = new NativeReference<TempWaterPumpingTooltipSystem.GroundWaterReservoirResult>(Allocator.Persistent);
}

Notes and implementation tips: - The system depends on WaterPipeParameterData being present (RequireForUpdate ensures the system won't run otherwise). - NativeReference is allocated with Allocator.Persistent — remember to keep the Dispose call in OnDestroy to avoid leaks. - The scheduled job uses temporary native containers allocated with Allocator.TempJob and disposes them using the job dependency to ensure they are cleaned up after the job finishes. - The system registers itself as a reader of the GroundWaterSystem map with AddReader, so concurrency and lifetime are handled correctly.