Game.Rendering.GuideLinesSystem
Assembly: Game
Namespace: Game.Rendering
Type: class
Base: GameSystemBase
Summary:
GuideLinesSystem is a rendering/utility system that draws guide lines, helper overlays and tooltips for in-game placement and editing tools (net/road tool, route tool, object tool, area/zone tool, selection, water tools, etc.). It collects control points, snap lines, temporary nodes and prefab definitions via EntityQueries and schedules multiple Burst-compiled IJob structs to produce overlay draw commands into an OverlayRenderSystem.Buffer. The system also collects tooltip info (angles and lengths) for use by UI or other systems. It interacts with many other game systems (TerrainSystem, WaterSystem, Tool systems, PrefabSystem) and uses Unity.Entities/ECS patterns with async archetype chunk list retrieval and dependency combination to keep work off the main thread when possible.
Fields
-
private EntityQuery m_DefinitionQuery
Holds entity query that finds CreationDefinition entities and any related buffers/components used to draw guide lines (NetCourse, WaypointDefinition, Zoning, Areas nodes, ObjectDefinition). Used to gather archetype chunks for jobs. -
private EntityQuery m_MarkerNodeQuery
Query for marker nodes (orphan marker nodes) used by net tool marker drawing. -
private EntityQuery m_TempNodeQuery
Query for temporary net nodes (Temp + Node) used to draw node connection feedback while placing or replacing nets. -
private EntityQuery m_WaterSourceQuery
Query for water source entities used by the water tool guide-line job. -
private EntityQuery m_RenderingSettingsQuery
Query used to read GuideLineSettingsData singleton (colors / style settings for guide lines). -
private TerrainSystem m_TerrainSystem
Cached reference to the TerrainSystem used to sample heights and get terrain-related data for overlay placement. -
private WaterSystem m_WaterSystem
Cached reference to the WaterSystem used to read water surface/depth and sample water heights. -
private ToolSystem m_ToolSystem
Reference to the global ToolSystem to determine the currently active tool. -
private NetToolSystem m_NetToolSystem
Reference to the Net tool system used to get control points, snap lines and prefab selection for road placement overlays. -
private RouteToolSystem m_RouteToolSystem
Reference to the route tool (public transit route editor) used to draw route-related overlays. -
private ZoneToolSystem m_ZoneToolSystem
Reference to the zone tool (zoning overlays). -
private SelectionToolSystem m_SelectionToolSystem
Reference used to draw selection quad overlays. -
private AreaToolSystem m_AreaToolSystem
Reference used to draw area tool overlays. -
private ObjectToolSystem m_ObjectToolSystem
Reference to object placement tool; used to draw object-specific guide lines like sub-snap points and upgrade ranges. -
private WaterToolSystem m_WaterToolSystem
Reference to water tool used to draw water source overlays. -
private OverlayRenderSystem m_OverlayRenderSystem
Reference to overlay render system; provides the Buffer writer used by jobs to emit draw commands. -
private CameraUpdateSystem m_CameraUpdateSystem
Used to get camera viewer info (e.g., camera right vector) required by some overlay computations. -
private ToolRaycastSystem m_ToolRaycastSystem
Contains raycast flags (DebugDisable/UIDisable) that can disable drawing while debugging or UI operations require it. -
private PrefabSystem m_PrefabSystem
Used to translate editor prefabs into ECS entities for certain jobs. -
private NativeList<bool> m_AngleSides
Persistent NativeList storing preferred angle sides for angle indicators between consecutive control points. Updated by jobs and persisted across frames. -
private NativeList<TooltipInfo> m_Tooltips
Persistent NativeList where jobs append TooltipInfo (angle or length) entries. Accessible via GetTooltips() after job completion. -
private JobHandle m_TooltipDeps
JobHandle for the last scheduled job that produced tooltips — callers should use this handle to coordinate reading m_Tooltips on main thread. -
private TypeHandle __TypeHandle
Internal struct storing ComponentTypeHandle / BufferTypeHandle / ComponentLookup handles used to set up jobs quickly. Populated in OnCreateForCompiler / __AssignHandles.
Properties
- None (this system exposes behavior via methods, not public properties).
Constructors
public GuideLinesSystem()
Default constructor. The system performs initialization of NativeLists and sets up entity queries in OnCreate rather than the constructor. The constructor is preserved for ECS usage.
Methods
-
protected override void OnCreate()
Initializes references to other world-managed systems (TerrainSystem, WaterSystem, tool systems, overlay render system, etc.), creates entity queries (definition, temp/maker node queries, water source query, rendering settings query), and allocates persistent NativeLists (m_AngleSides, m_Tooltips). -
protected override void OnDestroy()
Disposes persistent NativeLists (m_AngleSides, m_Tooltips) and calls base.OnDestroy(). -
public NativeList<TooltipInfo> GetTooltips(out JobHandle dependencies)
Returns the NativeListcontaining tooltips collected during the last frame and outputs the associated JobHandle (dependencies) that must be completed before reading the list on the main thread. -
protected override void OnUpdate()
Main update method: clears the tooltip list, checks whether drawing is allowed (raycast flags), determines active tool and schedules the appropriate Burst IJob (NetToolGuideLinesJob, RouteToolGuideLinesJob, ZoneToolGuideLinesJob, SelectionToolGuideLinesJob, AreaToolGuideLinesJob, ObjectToolGuideLinesJob, WaterToolGuideLinesJob). The method prepares job data including retrieving archetype chunk lists (async), control points, snap lines, terrain/water data, overlay buffer handles and combines dependencies. It registers read/write dependencies with TerrainSystem, WaterSystem and OverlayRenderSystem as needed. -
private static void CheckDirection(float2 startDir, float2 checkDir, ref float2 leftDir, ref float2 rightDir, ref int bestLeft, ref int bestRight, ref float2 leftDir2, ref float2 rightDir2, ref int bestLeft2, ref int bestRight2)
Utility that compares a candidate direction (checkDir) against a starting direction (startDir) and updates best-left / best-right best angles and the corresponding direction vectors. Used by several jobs to find best snapping/angle directions. -
private static void DrawAngleIndicator(OverlayRenderSystem.Buffer buffer, NativeList<TooltipInfo> tooltips, GuideLineSettingsData guideLineSettings, Line3.Segment line1, Line3.Segment line2, float2 dir1, float2 dir2, float size, float lineWidth, int angle, bool angleSide)
Draws an angle indicator overlay between two line segments and appends a TooltipInfo entry describing the angle. Handles multiple cases (straight 180°, >90°, 90°, and <90°) and uses curves/lines accordingly. -
private static void DrawAreaRange(OverlayRenderSystem.Buffer buffer, quaternion rotation, float3 position, LotData lotData)
Draws a circular area range overlay for lots (sale/placement ranges) using LotData.m_MaxRadius and LotData.m_RangeColor. -
private static void DrawUpgradeRange(OverlayRenderSystem.Buffer buffer, quaternion rotation, float3 position, GuideLineSettingsData guideLineSettings, BuildingData ownerBuildingData, BuildingData buildingData, ServiceUpgradeData serviceUpgradeData)
Draws the upgrade/service-range overlay for service upgrade prefabs (rectangular or circular shapes) based on building and service upgrade data. -
private static void DrawNetCourse(OverlayRenderSystem.Buffer buffer, NetCourse netCourse, ref TerrainHeightData terrainHeightData, ref WaterSurfaceData waterSurfaceData, NetGeometryData netGeometryData, GuideLineSettingsData guideLineSettings)
Draws a NetCourse (part of a placeable network's curve) as projected or world-space curves, sampling terrain/water heights and splitting the curve into segments as needed (to account for intersections with water surface). Used by net-related jobs. -
Nested types:
TooltipInfo
struct andTooltipType
enum: small POD types used to record tooltip position, type (Angle or Length) and numeric value.- Several Burst-compiled job structs implementing IJob: WaterToolGuideLinesJob, ObjectToolGuideLinesJob, AreaToolGuideLinesJob, SelectionToolGuideLinesJob, ZoneToolGuideLinesJob, RouteToolGuideLinesJob, NetToolGuideLinesJob. Each job encapsulates overlay-drawing logic for the respective tool and writes commands into OverlayRenderSystem.Buffer. They make extensive use of ComponentTypeHandle / ComponentLookup / BufferLookup and NativeList/archtype chunk lists.
-
TypeHandle
struct: holds per-frame ComponentTypeHandle/BufferTypeHandle/ComponentLookup handles and provides a __AssignHandles method to populate them from a SystemState. -
Compiler / helper methods:
protected override void OnCreateForCompiler()
andprivate void __AssignQueries(ref SystemState state)
/__AssignHandles
— internal plumbing used by the compiled ECS system to setup handles and queries.
Usage Example
// Example: reading tooltips produced by GuideLinesSystem.
// Must complete the job handle returned by GetTooltips before accessing the NativeList on the main thread.
GuideLinesSystem guideLines = World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged<GuideLinesSystem>();
// get tooltip list and dependency (job handle)
JobHandle deps;
NativeList<GuideLinesSystem.TooltipInfo> tooltips = guideLines.GetTooltips(out deps);
// wait for scheduled job(s) that produce tooltips to finish
deps.Complete();
// iterate tooltips (angle/length info). Each TooltipInfo contains:
// - m_Type (TooltipType.Angle or TooltipType.Length)
// - m_Position (world position to place the tooltip)
// - m_Value (angle in degrees or length in map units)
for (int i = 0; i < tooltips.Length; i++)
{
var t = tooltips[i];
// use t.m_Type, t.m_Position, t.m_Value for UI rendering or debug printing
}
Notes and tips: - GuideLinesSystem is tightly coupled to the game's internal data types (CreationDefinition, NetCourse, ControlPoint, SnapLine, LotData, etc.) and to the OverlayRenderSystem. Modifying or extending its behavior usually requires creating compatible OverlayRenderSystem.Buffer draw calls or adding custom job logic that follows the same dependency/reader/writer registration patterns (TerrainSystem.AddCPUHeightReader, WaterSystem.AddSurfaceReader, OverlayRenderSystem.AddBufferWriter). - Many of the per-tool drawing routines are implemented as Burst-compiled IJob structs to run off the main thread — when adding or changing code, respect thread-safety rules and use ComponentLookup/BufferLookup and ToArchetypeChunkListAsync for chunk access.