Game.Tools.DefaultToolSystem
Assembly:
Assembly-CSharp
Namespace:
Game.Tools
Type:
class
Base:
ToolBaseSystem
Summary:
DefaultToolSystem implements the game's generic default tool used for selecting, inspecting and manipulating world entities (objects, nets, icons, areas, route waypoints, etc.). It handles raycast setup for different tool states and infomodes, selection and toggle-selection logic, dragging of movable entities, creation of temporary "definition" entities for UI/preview purposes via a CreateDefinitionsJob, and plays UI selection sounds. It integrates with the ToolOutputBarrier, AudioManager and RenderingSystem and exposes options for underground mode and various debug behaviors.
Nested types
-
private enum State { Default, MouseDownPrepare, MouseDown, Dragging }
Used to track the tool input/interaction state machine (idle, preparing for mouse-down, mouse-down, and dragging). -
private struct CreateDefinitionsJob : IJob
Job that builds CreationDefinition/NetCourse/ObjectDefinition/WaypointDefinition/... entities for the currently hovered entity. Reads many component lookups and writes to an EntityCommandBuffer to spawn preview/definition entities. -
public struct SelectEntityJob : IJob
Job that inspects Temp components (and related owner/attachment/controller data) to determine which entity should be selected, handles debug-select toggling, and writes the chosen entity into a NativeReference for the main thread to consume. -
private struct TypeHandle
Container for caching ComponentTypeHandle/ComponentLookup/BufferLookup handles used by jobs and queries. Has __AssignHandles(ref SystemState) to obtain handles from the SystemState.
Fields
-
public const string kToolID = "Default Tool"
Constant identifier for the tool. -
private ToolOutputBarrier m_ToolOutputBarrier
Barrier used to produce EntityCommandBuffers for creating/modifying output entities (definitions, updates). -
private AudioManager m_AudioManager
Reference to the world's AudioManager used for playing UI/selection sounds. -
private RenderingSystem m_RenderingSystem
Reference to the RenderingSystem to query things like marker visibility used to configure raycast flags. -
private EntityQuery m_DefinitionQuery
Query used to find and destroy previously created definition entities (previews) before recreating. -
private EntityQuery m_DragQuery
Query to find the temporary entity used for direct manipulation/dragging of objects. -
private EntityQuery m_TempQuery
Query that returns Temp components used to detect hovered/selectable items. -
private EntityQuery m_InfomodeQuery
Query to detect whether any infomode is active that requires special raycast settings (routes, net status, heatmap). -
private EntityQuery m_SoundQuery
Query to read ToolUXSoundSettingsData (fallback selection sound settings). -
private EntityQuery m_UpdateQuery
Query used to detect when color-updated signals require forcing a tool update. -
private Entity m_LastRaycastEntity
Last entity that was returned by the raycast; used to avoid redundant updates. -
private float3 m_MouseDownPosition
World position recorded when mouse-down begins (used to detect drag start). -
private State m_State
Current interaction state of the tool. -
private IProxyAction m_DefaultToolApply
Cached action state for the default tool apply action (from InputManager). -
private int m_LastSelectedIndex
Index used when selecting among aggregate elements / subprefabs. -
private TypeHandle __TypeHandle
Cached type/lookups container used to obtain handles for component access within jobs and some main-thread logic.
Properties
-
public override string toolID => "Default Tool"
Identifier exposed by the tool (overrides base ToolBaseSystem). -
public override bool allowUnderground => true
Base override that indicates the tool supports underground toggling. -
public bool underground { get; set; }
Controls whether the tool operates in underground collision mode (affects the raycast collision mask). -
public bool ignoreErrors { get; set; }
Flag intended to configure whether the tool should ignore certain errors (present but not heavily used inside this system). -
public bool allowManipulation { get; set; }
If true, the tool may allow direct manipulation (dragging) of certain movable entities. -
public bool debugSelect { get; set; }
When true, expands raycast to include subelements / net layers to facilitate debug selection. -
public bool debugLandValue { get; set; }
When true, raycast includes terrain to display/debug land value overlay selection. -
private protected override IEnumerable<IProxyAction> toolActions
Yields the IProxyAction(s) used by the tool (the Default Tool apply action is yielded).
Constructors
public DefaultToolSystem()
Default constructor. Typical ECS system initialization will call OnCreate/OnStartRunning after construction.
Methods
-
[Preserve] protected override void OnCreate()
Initializes references (ToolOutputBarrier, AudioManager, RenderingSystem), builds entity queries, and fetches the default tool apply action from InputManager. -
[Preserve] protected override void OnStartRunning()
Called when the system starts running. Resets m_LastRaycastEntity, sets State.Default and initial applyMode/requireUnderground values. -
private protected override void UpdateActions()
Configures the tool's apply/cancel proxy actions depending on whether an entity is currently hovered (m_LastRaycastEntity) to choose between default apply and mouse apply actions. -
public override PrefabBase GetPrefab()
Returns null (DefaultTool does not use a prefab). -
public override bool TrySetPrefab(PrefabBase prefab)
Always returns false (DefaultTool does not support setting a prefab). -
public override void SetUnderground(bool underground)
Sets the underground property. -
public override void ElevationUp()
Sets underground = false. -
public override void ElevationDown()
Sets underground = true. -
public override void ElevationScroll()
Toggles underground. -
public override void InitializeRaycast()
Configures m_ToolRaycastSystem masks and flags according to current state (underground, debug flags, infomodes, editor mode). Selects types/layers/route/area/icon masks for the current mode. -
private void SetInfomodeRaycastSettings()
When infomode entities exist, queries them and adjusts raycast type masks (e.g., route waypoints/segments, lanes and utility type masks for various net-status infoviews). -
private void PlaySelectedSound(Entity selected, bool forcePlay = false)
Determines appropriate UI selection sound for the selected entity (uses Resident/Citizen/Prefab selected-sound or fallback ToolUXSoundSettingsData) and plays it via AudioManager (optionally forcing play even when already playing). -
[Preserve] protected override JobHandle OnUpdate(JobHandle inputDeps)
Main update entry. Updates underground requirement, checks for forced updates, and runs the appropriate flow depending on input state (apply/cancel/drag/update). It will call Apply, Cancel, Update or Clear as appropriate. -
private JobHandle Clear(JobHandle inputDeps)
Sets applyMode to Clear and returns dependencies unchanged. -
private JobHandle Cancel(JobHandle inputDeps)
Handles cancel behavior depending on tool state (stops dragging, clears selection, or returns to default state). Sets applyMode accordingly. -
private JobHandle Apply(JobHandle inputDeps, bool singleFrameOnly = false, bool toggleSelected = false)
Handles press/release apply behavior. From Default state it may move to MouseDownPrepare and then calls SelectTempEntity. From Dragging it will stop dragging and apply selection; otherwise it returns to Default. -
private JobHandle Update(JobHandle inputDeps)
State-driven update handler: - Default: performs raycast, if raycast entity changed or forced update, calls UpdateDefinitions to create definition entities.
- MouseDownPrepare: stores mouse-down position and moves to MouseDown on successful raycast.
- MouseDown: if pointer moved far enough, starts dragging.
-
Dragging: updates position of the temporary drag entity or updates definition positions when dragging an owned object.
-
private void StartDragging(RaycastHit raycastHit)
If allowManipulation and a drag Temp entity exists and is movable (Moving component or Marker), marks it as dragging, updates its Transform to the hit position and sets state to Dragging. Otherwise returns to Default. -
private void StopDragging()
Clears the Dragging flag on the drag Temp entity and sets state back to Default. Adds Updated tag so changes are processed. -
private void SetState(State state)
Sets the internal m_State field. -
private JobHandle UpdateDefinitions(JobHandle inputDeps, Entity entity, int index, float3 position, bool setPosition)
Destroys existing definition entities, schedules/CreateDefinitionsJob for the passed entity to produce new definition entities (previews). Adds the produced job handle to the ToolOutputBarrier and records the last selected index. -
private JobHandle SelectTempEntity(JobHandle inputDeps, bool toggleSelected)
Schedules the SelectEntityJob to determine which entity (if any) should become the tool's selection based on Temp components. After completion updates the tool system selection and plays selection sounds. Updates m_LastSelectedIndex and handles toggling selection off. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Compiler-generated placeholder used to assign entity queries during OnCreateForCompiler (empty here). -
protected override void OnCreateForCompiler()
Compiler support to assign queries and type handles (__AssignQueries and TypeHandle.__AssignHandles).
Usage Example
// Example showing how the DefaultToolSystem is configured by the game and how you might toggle modes:
var defaultTool = world.GetOrCreateSystemManaged<Game.Tools.DefaultToolSystem>();
// Toggle underground view (e.g., bound to elevation controls)
defaultTool.SetUnderground(true);
// Enable debug select to widen raycast to nets/subelements
defaultTool.debugSelect = true;
// The DefaultToolSystem automatically handles input and selection; changes above affect raycast and selection behavior.
Note: DefaultToolSystem is an ECS System intended to run within the game's World/Entity system. Most integration is done via the engine systems (ToolRaycastSystem, ToolOutputBarrier, InputManager); modding should generally interact with its public properties (like underground/debug flags) rather than trying to replace internal job logic.