Game.UI.Tooltip.LandValueTooltipSystem
Assembly: Assembly-CSharp
Namespace: Game.UI.Tooltip
Type: class
Base: TooltipSystemBase
Summary:
Handles showing mouse-over tooltips for land value and related terrain metrics (terrain attractiveness and pollution values). It uses a Burst-compiled IJob (LandValueTooltipJob) to read various native maps (land value, attractiveness, ground/air/noise pollution) for the current raycast hit position and places the results into NativeValue
Fields
-
private RaycastSystem m_RaycastSystem
Reference to the RaycastSystem used to perform mouse-to-world raycasts. -
private CameraUpdateSystem m_CameraUpdateSystem
Used to get the current viewer/camera for calculating the raycast line. -
private ToolRaycastSystem m_ToolRaycastSystem
Used to calculate raycast lines based on the active camera. -
private ToolSystem m_ToolSystem
Used to check which infoview/tool is currently active (to determine if land value info mode is enabled). -
private TerrainToolSystem m_TerrainToolSystem
Reference to terrain tool system (not used directly in the shown code but acquired on create). -
private LandValueSystem m_LandValueSystem
Provides access to the land value map. -
private LandValueDebugSystem m_LandValueDebugSystem
Debug system toggle that causes additional debug tooltips to be shown when enabled. -
private TerrainAttractivenessSystem m_TerrainAttractivenessSystem
Provides the terrain attractiveness map and evaluation methods. -
private TerrainSystem m_TerrainSystem
Provides terrain height data used to sample terrain height at the raycast hit. -
private PrefabSystem m_PrefabSystem
Used to query infoview prefabs for comparing active infoviews. -
private GroundPollutionSystem m_GroundPollutionSystem
Provides ground pollution map. -
private AirPollutionSystem m_AirPollutionSystem
Provides air pollution map. -
private NoisePollutionSystem m_NoisePollutionSystem
Provides noise pollution map. -
private EntityQuery m_AttractivenessParameterQuery
Entity query used to obtain AttractivenessParameterData required by attractiveness evaluation. -
private EntityQuery m_LandValueParameterQuery
Entity query used to obtain LandValueParameterData (used to find the infoview prefab). -
private FloatTooltip m_LandValueTooltip
Template/config for the land value tooltip (icon, label, unit, and value set at runtime). -
private FloatTooltip m_TerrainAttractiveTooltip
Template/config for the terrain attractiveness (debug) tooltip. -
private FloatTooltip m_AirPollutionTooltip
Template/config for the air pollution (debug) tooltip. -
private FloatTooltip m_GroundPollutionTooltip
Template/config for the ground pollution (debug) tooltip. -
private FloatTooltip m_NoisePollutionTooltip
Template/config for the noise pollution (debug) tooltip. -
private NativeValue<float> m_LandValueResult
Persistent NativeValue used to receive the land value result from the scheduled job. -
private NativeValue<float> m_TerrainAttractiveResult
Persistent NativeValue used to receive the terrain attractiveness result from the scheduled job. -
private NativeValue<float> m_AirPollutionResult
Persistent NativeValue used to receive the air pollution result from the scheduled job. -
private NativeValue<float> m_NoisePollutionResult
Persistent NativeValue used to receive the noise pollution result from the scheduled job. -
private NativeValue<float> m_GroundPollutionResult
Persistent NativeValue used to receive the ground pollution result from the scheduled job. -
private struct LandValueTooltipJob
Burst-compiled IJob that reads native maps and parameter data and writes results into the NativeValuecontainers. (See Methods -> Execute for behavior.)
Properties
- None (no public properties exposed by this system)
Constructors
public LandValueTooltipSystem()
Default constructor. Marked with [Preserve] attribute so the system is kept by Unity's code stripping. Initialization of dependencies and NativeValues occurs in OnCreate, not here.
Methods
[Preserve] protected override void OnCreate()
: System.Void
Initializes references to other systems (RaycastSystem, CameraUpdateSystem, ToolSystem, various data systems), sets up EntityQuery objects for required parameter components (AttractivenessParameterData and LandValueParameterData), marks those queries as required for the system to update, creates FloatTooltip templates for land value and debug metrics, and allocates persistent NativeValueinstances used to receive job results.
Important notes:
- Allocates NativeValue
-
[Preserve] protected override void OnDestroy()
: System.Void
Disposes the persistent NativeValueinstances created in OnCreate and then calls base.OnDestroy(). -
private bool IsInfomodeActivated()
: System.Boolean
Checks whether the currently active infoview (m_ToolSystem.activeInfoview) matches the land value infoview prefab referenced by LandValueParameterData. Returns true when the land value infoview is active. Uses PrefabSystem.TryGetPrefab to obtain the prefab for comparison. -
[Preserve] protected override void OnUpdate()
: System.Void
Core per-frame logic: - If the land value infoview is active (IsInfomodeActivated) or the LandValueDebugSystem is enabled:
- Calls CompleteDependency() to ensure any previously scheduled job has finished and result NativeValue
values are safe to read. - Sets up FloatTooltip values from the NativeValue results and uses AddMouseTooltip to queue them for display.
- Resets the NativeValue results to 0 to avoid showing stale values.
- Uses CameraUpdateSystem.TryGetViewer to obtain the viewer camera and builds a RaycastInput for terrain/water hit detection.
- Adds the raycast input to RaycastSystem, gets results, samples terrain height, obtains read-only native maps from several systems, and prepares a LandValueTooltipJob with those maps, parameter data and NativeValue output containers.
- Schedules the job using JobHandle.CombineDependencies to combine read dependencies from the maps and the system's existing Dependency. The resulting JobHandle is stored in base.Dependency to be completed next update.
- Calls AddReader on each source system with the new base.Dependency so those systems know this system reads their data.
- Calls CompleteDependency() to ensure any previously scheduled job has finished and result NativeValue
- Else: ensures result NativeValue values are zeroed.
Important threading points: - Results are read only after calling CompleteDependency() so the main thread sees job results safely. - Reads of native maps are requested via GetMap(readOnly: true, out dependencies) which returns both the NativeArray and a JobHandle for the map resource; these are combined into the scheduled job dependencies.
private void LandValueTooltipJob.Execute()
: System.Void
(IJob implementation inside the nested struct)- Computes LandValueSystem.GetCellIndex from the raycast position and loads the land value for that cell into m_LandValueResult.
- Retrieves TerrainAttractiveness for the raycast position from the attractiveness map and evaluates terrain attractiveness score using TerrainAttractivenessSystem.EvaluateAttractiveness with sampled terrain height and attractiveness parameters; writes result to m_TerrainAttractiveResult.
- Reads pollution values (ground/air/noise) from their respective maps and writes their .m_Pollution float to the corresponding NativeValue result outputs.
-
This job is Burst-compiled for performance and runs off the main thread.
-
[Preserve] public LandValueTooltipSystem()
Public constructor (same as listed above). Included here as a preserved constructor used by the ECS/Unity system creation.
Usage Example
// Example: core pattern used by the system to schedule a tooltip job and display tooltips.
// (This mirrors the logic found in OnUpdate.)
if (cameraUpdateSystem.TryGetViewer(out var viewer))
{
var input = new RaycastInput
{
m_Line = ToolRaycastSystem.CalculateRaycastLine(viewer.camera),
m_TypeMask = TypeMask.Terrain | TypeMask.Water,
m_CollisionMask = CollisionMask.OnGround | CollisionMask.Overground
};
raycastSystem.AddInput(this, input);
NativeArray<RaycastResult> results = raycastSystem.GetResult(this);
if (results.Length > 0)
{
TerrainHeightData heightData = terrainSystem.GetHeightData();
float3 hitPos = results[0].m_Hit.m_HitPosition;
float sampledHeight = TerrainUtils.SampleHeight(ref heightData, hitPos);
// Acquire read-only native maps and their dependencies
JobHandle d0, d1, d2, d3, d4;
var landMap = landValueSystem.GetMap(readOnly: true, out d0);
var attractiveMap = terrainAttractivenessSystem.GetMap(readOnly: true, out d1);
var groundMap = groundPollutionSystem.GetMap(readOnly: true, out d2);
var airMap = airPollutionSystem.GetMap(readOnly: true, out d3);
var noiseMap = noisePollutionSystem.GetMap(readOnly: true, out d4);
// Fill job data and schedule
var job = new LandValueTooltipJob
{
m_LandValueMap = landMap,
m_AttractiveMap = attractiveMap,
m_GroundPollutionMap = groundMap,
m_AirPollutionMap = airMap,
m_NoisePollutionMap = noiseMap,
m_TerrainHeight = sampledHeight,
m_AttractivenessParameterData = attractivenessParameterQuery.GetSingleton<AttractivenessParameterData>(),
m_RaycastPosition = hitPos,
m_LandValueResult = m_LandValueResult,
m_TerrainAttractiveResult = m_TerrainAttractiveResult,
m_AirPollutionResult = m_AirPollutionResult,
m_GroundPollutionResult = m_GroundPollutionResult,
m_NoisePollutionResult = m_NoisePollutionResult
};
base.Dependency = IJobExtensions.Schedule(job,
JobHandle.CombineDependencies(base.Dependency,
JobHandle.CombineDependencies(d1, d0, JobHandle.CombineDependencies(d2, d3, d4))));
// Tell the source systems that we have a reader dependency
landValueSystem.AddReader(base.Dependency);
terrainAttractivenessSystem.AddReader(base.Dependency);
groundPollutionSystem.AddReader(base.Dependency);
airPollutionSystem.AddReader(base.Dependency);
noisePollutionSystem.AddReader(base.Dependency);
}
}
Notes and recommendations: - The system uses NativeValue with Allocator.Persistent: ensure they are disposed in OnDestroy (this system does so). - Always call CompleteDependency() on the system before reading NativeValue results on the main thread (the system follows this practice in OnUpdate). - The job obtains read-only maps and combines their dependencies properly; when implementing similar systems follow the same dependency combination pattern and call AddReader on the source systems so their lifetimes / read/write scheduling remain correct.