Game.Rendering.EditorGizmoSystem
Assembly:
Game (in-game runtime assembly containing core game systems)
Namespace:
Game.Rendering
Type:
class
Base:
GameSystemBase
Summary:
EditorGizmoSystem is an ECS system responsible for rendering editor gizmos (visual debug handles) for editor-related entities such as net nodes, curves and generic transforms. It schedules a Burst-compiled IJobChunk (EditorGizmoJob) that reads entity component data (Node, Curve, Game.Objects.Transform, Temp, Error, Warning, Highlighted, CullingInfo) and issues draw calls to a GizmoBatcher retrieved from the GizmosSystem. It respects pre-culling information from PreCullingSystem and optionally uses colors from RenderingSettingsData. The system runs only when an EditorContainer is present and overlay rendering is not hidden.
Fields
-
private EntityQuery m_RenderQuery
Query used to determine whether editor rendering should run (requires EditorContainer and excludes Deleted/Hidden). -
private EntityQuery m_RenderingSettingsQuery
Query used to fetch RenderingSettingsData (optional) to override default gizmo colors. -
private GizmosSystem m_GizmosSystem
Reference to the game's GizmosSystem; used to obtain a GizmoBatcher for issuing draw operations from the worker job. -
private PreCullingSystem m_PreCullingSystem
Reference to the PreCullingSystem; used to obtain culling data so the job can skip gizmos far from the camera. -
private RenderingSystem m_RenderingSystem
Reference to the overall RenderingSystem; used to check the hideOverlay flag so gizmo rendering can be suppressed. -
private TypeHandle __TypeHandle
Holds ComponentTypeHandle instances for all component types the job reads. Populated via __AssignHandles during OnCreateForCompiler.
Properties
- None (this system exposes no public properties)
Constructors
public EditorGizmoSystem()
Default (parameterless) constructor. The system uses OnCreate to set up queries and get references to required systems.
Methods
protected override void OnCreate()
Initializes system state:- Retrieves required systems (GizmosSystem, PreCullingSystem, RenderingSystem) via World.GetOrCreateSystemManaged
(). - Creates EntityQueries:
- m_RenderQuery: requires Game.Tools.EditorContainer, excludes Deleted and Hidden.
- m_RenderingSettingsQuery: reads RenderingSettingsData.
-
Calls RequireForUpdate(m_RenderQuery) so the system only updates when an editor container exists.
-
protected override void OnUpdate()
Main update method: - Skips work if renderingSystem.hideOverlay is true.
- Gathers default colors (hovered, error, warning) and overrides them from RenderingSettingsData if available (ensures alpha is 1).
- Prepares and schedules a Burst-compiled EditorGizmoJob via JobChunkExtensions.ScheduleParallel:
- Provides ComponentTypeHandles through InternalCompilerInterface.GetComponentTypeHandle using __TypeHandle entries and the system's CheckedStateRef.
- Passes in colors, culling data (from PreCullingSystem.GetCullingData), and a GizmoBatcher (from GizmosSystem.GetGizmosBatcher).
- Registers dependencies with GizmosSystem and PreCullingSystem (AddGizmosBatcherWriter / AddCullingDataReader).
-
Stores the resulting JobHandle into base.Dependency.
-
protected override void OnCreateForCompiler()
Compiler helper used by generated code paths: -
Calls __AssignQueries and __TypeHandle.__AssignHandles to initialize query and type-handle state for compiled execution.
-
private void __AssignQueries(ref SystemState state)
Tiny helper used at compile-time to assign up-front queries; here it currently performs no persistent query initialization beyond a short-lived EntityQueryBuilder (present in original generated code). -
Editor-inner:
private struct EditorGizmoJob : IJobChunk
(Burst compiled) - Reads component arrays: Node, Curve, Game.Objects.Transform, Temp, Error, Warning, Highlighted, CullingInfo.
- Receives colors and NativeList
culling data and a GizmoBatcher instance. - In Execute, for each chunk:
- Determines base colors depending on presence of Error/Warning/Highlighted components on the chunk; otherwise uses default axis colors.
- Iterates Node components and draws three axis lines (right/up/forward rotated by node rotation) unless culling says not near camera.
- Iterates Curve components and draws curves via GizmoBatcher.DrawCurve unless culled or Temp.HIDDEN flag is set.
- Iterates Transform components and draws arrows along local axes via GizmoBatcher.DrawArrow unless culled or hidden.
- Honors Temp flags to show hovered color for create/delete/select/modify/replace, and skips elements marked Hidden.
- Uses IsNearCamera helper to consult m_CullingData for PreCullingFlags.NearCamera.
-
Implements IJobChunk.Execute wrapper.
-
Editor-inner:
private struct TypeHandle
- Holds ComponentTypeHandle
fields for all component types used by the job (Node, Curve, Game.Objects.Transform, Temp, Error, Warning, Highlighted, CullingInfo). - Method __AssignHandles(ref SystemState) calls state.GetComponentTypeHandle
(isReadOnly: true) for each handle and stores them for later retrieval.
Usage Example
// This is a simplified illustration of the system behavior.
// In-game the system is created/managed by the ECS world automatically.
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// EditorGizmoSystem obtains required systems and queries in its own OnCreate:
// m_GizmosSystem = World.GetOrCreateSystemManaged<GizmosSystem>();
// m_PreCullingSystem = World.GetOrCreateSystemManaged<PreCullingSystem>();
// m_RenderingSystem = World.GetOrCreateSystemManaged<RenderingSystem>();
// m_RenderQuery = GetEntityQuery(ComponentType.ReadOnly<Game.Tools.EditorContainer>(), ComponentType.Exclude<Deleted>(), ComponentType.Exclude<Hidden>());
// RequireForUpdate(m_RenderQuery);
}
[Preserve]
protected override void OnUpdate()
{
// EditorGizmoSystem's OnUpdate schedules a Burst IJobChunk (EditorGizmoJob) which:
// - Reads Node/Curve/Transform components
// - Uses PreCullingSystem.GetCullingData() to skip distant items
// - Obtains a GizmoBatcher from GizmosSystem and issues DrawLine/DrawCurve/DrawArrow calls
// - Honors Temp flags and chunk-level Error/Warning/Highlighted markers to choose colors
}
Notes / Tips: - The actual gizmo drawing is performed on worker threads via a GizmoBatcher writer; the system ensures proper synchronization by combining job dependencies and registering readers/writers with the respective systems. - RenderingSettingsData can override default gizmo colors; check if m_RenderingSettingsQuery.IsEmptyIgnoreFilter before trying to GetSingleton. - Temp flags are used to control visibility and hover/selection state; Hidden elements are skipped and certain flags cause the hovered color to be used.