Game.UI.Tooltip.NetCourseTooltipSystem
Assembly: Assembly-CSharp (runtime game assembly)
Namespace: Game.UI.Tooltip
Type: class
Base: TooltipSystemBase
Summary:
NetCourseTooltipSystem is an ECS system that provides in-game tooltips for net (road/track/etc.) courses while the NetTool is active. It queries CreationDefinition and NetCourse components, filters out temporary/irrelevant creations, aggregates course segments, computes displayed metrics (displayed curve length and slope), and positions a tooltip group or falls back to mouse tooltips if the computed position is off-screen. The system is designed to run only when the Net tool is active and not in Replace mode.
Fields
-
private const float kMinLength = 12f
Threshold (12 units) used to decide whether the aggregated on-screen tooltip should be shown based on the aggregated curve length. -
private ToolSystem m_ToolSystem
Cached reference to the game's ToolSystem used to check the active tool. -
private NetToolSystem m_NetTool
Cached reference to the NetToolSystem to check mode and determine if NetTool is active. -
private EntityQuery m_NetCourseQuery
EntityQuery that selects entities with CreationDefinition and NetCourse components. Used to gather net-course segments currently being created/edited. -
private TooltipGroup m_Group
TooltipGroup that contains the length and slope child tooltips and is positioned in world/tooltip space when appropriate. -
private FloatTooltip m_Length
Float tooltip for displaying the computed curve (world) length. Configured with an icon ("Media/Glyphs/Length.svg") and unit "length". -
private FloatTooltip m_Slope
Float tooltip for displaying the computed slope (percentage). Configured with icon ("Media/Glyphs/Slope.svg"), unit "percentageSingleFraction", and marked as signed. -
private TypeHandle __TypeHandle
Internal compiler-generated struct containing ComponentTypeHandleand ComponentTypeHandle used for efficient chunk access. It exposes an __AssignHandles method to initialize these handles from a SystemState.
TypeHandle (nested)
- public ComponentTypeHandle<NetCourse> __Game_Tools_NetCourse_RO_ComponentTypeHandle
ReadOnly component type handle for NetCourse.
-
public ComponentTypeHandle<CreationDefinition> __Game_Tools_CreationDefinition_RO_ComponentTypeHandle
ReadOnly component type handle for CreationDefinition. -
public void __AssignHandles(ref SystemState state)
Assigns the component type handles from the provided SystemState (called in system initialization).
Properties
- (none)
This system does not expose public properties.
Constructors
public NetCourseTooltipSystem()
Default constructor (Preserve attribute indicates it should not be stripped). Initialization of runtime members is performed in OnCreate.
Methods
protected override void OnCreate()
Initializes references and tooltip UI elements:- Retrieves ToolSystem and NetToolSystem from the World.
- Builds an EntityQuery for CreationDefinition + NetCourse and calls RequireForUpdate so the system only updates when matching entities exist.
- Creates two FloatTooltip instances (m_Length and m_Slope) and configures icons/units.
-
Sets up a TooltipGroup (m_Group) with center alignment and Network category and adds the two child tooltips.
-
protected override void OnUpdate()
Main update logic executed each frame when requirements are met: - Early-exits if NetTool isn't active, is in Replace mode, or no Camera.main.
- Calls CompleteDependency() to ensure jobs are finished before reading component data on the main thread.
- Allocates a temporary NativeList
sized from the query entity count and obtains chunk array for iteration. - Uses InternalCompilerInterface + the stored TypeHandle to obtain ComponentTypeHandle
and ComponentTypeHandle . - Iterates chunks and elements, filtering out creations with an original entity or with flags (Permanent/Delete/Upgrade/Invert/Align) — these are ignored. Also ignores course positions flagged as IsParallel.
- Aggregates two length metrics:
- num: sum of NetCourse.m_Length (original/straight length)
- num2: sum of curve XZ length computed via MathUtils.Cut(...).xz and MathUtils.Length (actual curved horizontal length)
- Collects accepted NetCourse segments into the temporary NativeList.
- Sets m_Length.value to the curve length (num2).
- If there are courses and curve length >= kMinLength (12f):
- Compute slope: use Y of first start and last end to compute 100 * deltaY / curveLength. Small slopes (<0.05) are treated as 0.
- Sort courses (SortCourses) so the sequence starts at the IsFirst segment and is ordered by adjacency.
- Compute a world position somewhere near the center of the combined course set (GetWorldPosition with half original summed length).
- Transform to tooltip coordinates via TooltipSystemBase.WorldToTooltipPos, update m_Group.position and mark children changed if position changed.
- If on-screen, show the tooltip group (AddGroup). Otherwise, fall back to AddMouseTooltip for each child (length and slope).
- Ensures native containers (courses and nativeArray) are disposed in finally block.
Notes: - Uses math.select to treat near-zero slopes as zero. - Uses CompleteDependency to ensure safety when reading ECS data on main thread.
-
private static float3 GetWorldPosition(NativeList<NetCourse> courses, float length)
Walks the ordered courses accumulating their lengths until reaching a specified relative length offset (length is expected to be negative or zero offset from start). It lerps along the segment curve to find a position at that accumulated distance and returns the corresponding world-space position. If not found, returns the end position of the last course. -
private static void SortCourses(NativeList<NetCourse> courses)
In-place sorts/reorders the course list so the first element is the segment that has CoursePosFlags.IsFirst, then attempts to order subsequent segments by matching the end position of one segment to the start position of the next. It performs pairwise swapping to achieve adjacency order. -
private void __AssignQueries(ref SystemState state)
Compiler-generated helper used by the ECS compiler; currently only constructs and disposes an EntityQueryBuilder (no user-level behavior). -
protected override void OnCreateForCompiler()
Compiler-time helper: calls __AssignQueries and assigns the TypeHandle component handles via __TypeHandle.__AssignHandles(ref base.CheckedStateRef). This method exists to satisfy generated code expectations. -
TypeHandle.__AssignHandles(ref SystemState state)
(See TypeHandle section above) Initializes ComponentTypeHandle fields from SystemState.
Usage Example
This system is an ECS managed system and is normally created and run by the game's world/system manager. You usually do not instantiate it directly. Example: when the Net tool is active while creating a road, the system will automatically show length and slope tooltips for the sequence of NetCourse segments.
If you are authoring a similar TooltipSystemBase-derived system, a minimal OnCreate pattern looks like:
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Acquire systems and build EntityQuery, create tooltips and group as needed.
}
If you need to debug or inspect values at runtime, consider logging in OnUpdate or using conditional breakpoints when NetToolSystem is active.
Additional notes and implementation caveats: - The system uses Native containers (NativeList, NativeArray) and disposes them in a finally block to avoid leaks. - It relies on MathUtils for Bezier curve operations and Unity.Mathematics for vector/mathematical operations. - It filters CreationDefinition via CreationFlags to exclude non-relevant segments (permanent, delete, upgrade, invert, align) and ignores segments with CoursePosFlags.IsParallel. - Tooltip positioning respects screen visibility: if the computed group position is off-screen the system falls back to per-item mouse tooltips. - The behavior and naming follow the game's internal systems; member names beginning with m_ are internal caches/state.