Game.UI.InGame.LineVisualizerSection
Assembly: Assembly-CSharp (game core assembly)
Namespace: Game.UI.InGame
Type: class LineVisualizerSection
Base: InfoSectionBase
Summary:
LineVisualizerSection is an InfoSection used by the in-game UI to visualize transport lines (public transport / cargo routes) — it collects route segments, stops and vehicles for the currently selected route or stop and exposes that information as JSON properties for the UI. The class uses Unity ECS ComponentLookup/BufferLookup and schedules two Burst-compiled jobs (VisibilityJob and UpdateJob) to compute visibility and to gather detailed runtime data (segments, stop passenger/cargo counts, vehicle positions and cargo capacities). Native collections with Allocator.Persistent are used to store the results and are properly disposed in OnDestroy. This section also adds tooltip tags based on whether the route is a cargo route or a passenger route.
Fields
-
private RenderingSystem m_RenderingSystem
Holds a reference to the RenderingSystem used to obtain rendering frame index/time for interpolating transform frames when computing vehicle positions. -
private CityConfigurationSystem m_CityConfigurationSystem
Reference used to determine traffic handedness (left/right) which affects how relative positions on a route are reported. -
private NativeArray<bool> m_BoolResult
A persistent NativeArray used as an inter-job result buffer (3 bools). Written by jobs and read back on the main thread. -
private NativeArray<Entity> m_EntityResult
A persistent NativeArray used by VisibilityJob to return the selected route entity (if found). -
private NativeList<LineSegment> m_SegmentsResult
NativeList (persistent) used by UpdateJob to produce route segments (start/end fractions and broken flag). -
private NativeList<LineStop> m_StopsResult
NativeList (persistent) used by UpdateJob to produce stops (entity, relative position, cargo, capacity, flags). -
private NativeList<LineVehicle> m_VehiclesResult
NativeList (persistent) used by UpdateJob to produce vehicles (entity, relative position, cargo, capacity, flags). -
private NativeArray<Color32> m_ColorResult
NativeArray (size 1) used by UpdateJob to return the route color. -
private NativeArray<int> m_StopCapacityResult
NativeArray (size 1) used by UpdateJob to return maximum stop capacity (used by UI). -
private TypeHandle __TypeHandle
Internal struct holding ComponentLookup/BufferLookup/SharedComponentTypeHandle handles used by the jobs. Assigned in OnCreateForCompiler / __AssignHandles. -
protected override string group
String property returning "LineVisualizerSection" (used by InfoSectionBase to group UI sections). -
protected override bool displayForDestroyedObjects
Flag override set to true — this section can show data for destroyed objects. -
protected override bool displayForOutsideConnections
Flag override set to true — this section can display info for outside connections. -
private UnityEngine.Color color { get; set; }
Managed cached color (converted from Color32 returned by jobs) used for UI output. -
private int stopCapacity { get; set; }
Cached maximum stop capacity discovered during UpdateJob. -
private NativeList<LineStop> stops { get; set; }
Managed persistent NativeList mirroring m_StopsResult used for JSON output. Cleared/updated by Reset/OnProcess. -
private NativeList<LineVehicle> vehicles { get; set; }
Managed persistent NativeList mirroring m_VehiclesResult used for JSON output. -
private NativeList<LineSegment> segments { get; set; }
Managed persistent NativeList mirroring m_SegmentsResult used for JSON output.
Properties
-
public UnityEngine.Color color { get; private set }
Holds the route color computed by UpdateJob and exposed to the UI. -
public int stopCapacity { get; private set }
Maximum capacity (passenger/cargo) among stops/vehicles for the selected route. -
public NativeList<LineStop> stops { get; private set }
Current snapshot of stops for the selected route, used when serializing JSON properties. -
public NativeList<LineVehicle> vehicles { get; private set }
Current snapshot of vehicles for the selected route. -
public NativeList<LineSegment> segments { get; private set }
Current snapshot of route segments (relative start/end and broken flag). -
protected override string group { get; }
Returns the section group name: "LineVisualizerSection". -
protected override bool displayForDestroyedObjects { get; }
Override enabling display for destroyed objects (true). -
protected override bool displayForOutsideConnections { get; }
Override enabling display for outside connections (true).
Constructors
public LineVisualizerSection()
Default constructor. The real initialization of systems and Native containers is done in OnCreate (override). No parameters.
Methods
-
protected override void Reset()
Clears cached managed color, stopCapacity and clears the managed NativeLists and result NativeLists. Called by base lifecycle to reset section state. -
[Preserve] protected override void OnCreate()
Initializes references to required game systems (RenderingSystem, CityConfigurationSystem), allocates all persistent NativeList/NativeArray result containers (stops, vehicles, segments, m_BoolResult, m_EntityResult, m_ColorResult, m_StopCapacityResult, m_SegmentsResult, m_StopsResult, m_VehiclesResult). Must call base.OnCreate() (it does). This is the correct place to allocate persistent native resources. -
[Preserve] protected override void OnDestroy()
Disposes all persistent NativeLists and NativeArrays allocated in OnCreate and calls base.OnDestroy(). Always ensure these disposals to avoid memory leaks. -
[Preserve] protected override void OnUpdate()
Main per-frame update. Schedules the Burst-compiled VisibilityJob (to determine whether the selection is a route/stop/vehicle and whether it should change selected route). If visible, schedules the Burst-compiled UpdateJob (to gather route segments, vehicle positions and stop/cargo data). Both jobs are scheduled with base.Dependency and then Completed on the main thread (Complete()). After jobs finish, OnProcess will be called by base to move results into managed containers for JSON output.
Important behaviors: - VisibilityJob writes m_BoolResult[0] = visibility and may set m_BoolResult[1] to instruct the UI system to update m_InfoUISystem.selectedRoute. - UpdateJob computes fractional positions along the route (0..1) for segments, stops and vehicles. It uses rendering interpolation (TransformFrame) to compute accurate vehicle positions. - Both jobs use many ComponentLookup/BufferLookup handles provided via __TypeHandle.
-
protected override void OnProcess()
Transfers results produced by UpdateJob (m_*Result NativeLists/Arrays) into the managed NativeList properties (segments, vehicles, stops, color, stopCapacity) and marks the section dirty to force UI update. Also adds tooltip tags (CargoRoute / TransportLine / TransportStop) via m_InfoUISystem.tooltipTags based on route type. -
public override void OnWriteProperties(IJsonWriter writer)
Serializes current state to JSON for the UI. Writes: - "color" (UnityEngine.Color),
- "stops" (array of LineStop objects; each LineStop calls Bind to write its fields and the named entity via NameSystem),
- "vehicles" (array of LineVehicle objects),
- "segments" (array of LineSegment objects),
- "stopCapacity" (int).
This is the primary output consumed by the in-game UI to render the visualizer.
-
private void __AssignQueries(ref SystemState state)
Compiler helper used to assign entity queries; present for generated/compiled ECS integration. No custom logic required. -
protected override void OnCreateForCompiler()
Compiler-time helper that calls __AssignQueries and __TypeHandle.__AssignHandles. Ensures the job type handles are assigned for runtime. -
Nested and important types:
private readonly struct LineStop
— represents a stop with Entity, relative position (fraction), cargo amount, capacity, and flags (isCargo, isOutsideConnection). Includes Bind(IJsonWriter, NameSystem) to write JSON.private readonly struct LineVehicle
— represents a vehicle with Entity, relative position, cargo amount and capacity, and a flag indicating cargo vehicle. Includes Bind(IJsonWriter, NameSystem).private readonly struct LineSegment : IJsonWritable
— start/end fractions and broken flag; implements Write(IJsonWriter).private enum Result
— internal enum used by job results (indices into native arrays).[BurstCompile] private struct VisibilityJob : IJob
— determines whether selected entity corresponds to a route, stop/station (connected to route) or a vehicle on a line. Writes to m_BoolResult and m_EntityResult.[BurstCompile] private struct UpdateJob : IJob
— main data collection job that computes:- route segment fractional extents,
- vehicle fractional positions and aggregate cargo/capacity,
- stop fractional positions, waiting passengers / stored cargo and capacities. Uses many ComponentLookup/BufferLookup handles, EntityStorageInfoLookup and TransformFrame buffers to compute real-time positions. Populates m_SegmentsResult, m_StopsResult, m_VehiclesResult and other results.
Notes for modders: both jobs are Burst compiled and read from many ECS component stores; adding or changing component types used here requires adjusting the TypeHandle and job code. Jobs rely on consistent entity layout and buffer indices.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate(); // required: initializes systems and persistent native containers used by the section
// If you need to extend initialization, do it here.
// Example: log or adjust internal settings (do not reallocate m_* persistent arrays
// — they are owned and disposed by the base section implementation).
Debug.Log("LineVisualizerSection created and ready.");
}
Additional notes and tips for modders: - Native/Unmanaged resources are allocated with Allocator.Persistent in OnCreate and disposed in OnDestroy. If you add more persistent native allocations, follow that pattern and ensure disposal. - The jobs call Complete() before using results on the main thread. This design keeps correctness simple but is synchronous; if you need to change to a fully async pipeline, you must ensure results remain valid and synchronizations are correct. - The UI output is produced by OnWriteProperties using NameSystem to resolve entity names. If you modify how stops/vehicles are represented, update the Bind/Write methods on LineStop/LineVehicle/LineSegment accordingly. - The UpdateJob calculates relative positions (fractions) according to traffic handedness; when interpreting positions in a custom UI, account for RightHandTraffic inversion (m_RightHandTraffic toggles 1f - frac). - Because a large number of ECS component lookups are used, ensure __TypeHandle is kept in sync if you add new component types or change access patterns.