Game.ToolUISystem
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: UISystemBase
Summary:
ToolUISystem is the UI-facing system that bridges the game's tool systems with the in-game UI. It creates and manages bindings (value, getter and trigger bindings) exposing tool state and controls (elevation, brush, snapping, color, parallel mode, etc.) to the UI, handles tool/prefab change events, and routes UI-triggered actions back into the appropriate Tool systems (NetToolSystem, ObjectToolSystem, BulldozeToolSystem, TerrainToolSystem, etc.). It also provides helpers to enumerate available brushes and UI modes for the currently active tool.
Fields
-
public struct Brush : IJsonWritable
Represents a brush entry returned to the UI (entity, name, icon path and priority). Implements IJsonWritable to serialize itself for UI bindings. -
public const string kGroup
Constant group name for UI bindings ("tool"). -
private ToolSystem m_ToolSystem
Reference to the central ToolSystem (manages the currently active tool and general tool state). -
private NetToolSystem m_NetToolSystem
Reference to the Net tool system (roads/rails/etc.) used for net-specific controls. -
private AreaToolSystem m_AreaToolSystem
Reference to the Area tool system. -
private ZoneToolSystem m_ZoneToolSystem
Reference to the Zone tool system. -
private RouteToolSystem m_RouteToolSystem
Reference to the Route tool system. -
private ObjectToolSystem m_ObjectToolSystem
Reference to the Object tool system (prop/tree/object placement and brush mode). -
private TerrainToolSystem m_TerrainToolSystem
Reference to the Terrain tool system (terraforming brushes). -
private TerrainSystem m_TerrainSystem
Reference to global terrain system (used for height limits/scale). -
private DefaultToolSystem m_DefaultToolSystem
Fallback/default tool system. -
private UpgradeToolSystem m_UpgradeToolSystem
Reference to Upgrade tool system. -
private BulldozeToolSystem m_BulldozeToolSystem
Reference to Bulldoze tool system; used for confirmation flow and prefab initialization. -
private SelectionToolSystem m_SelectionToolSystem
Reference to Selection tool system. -
private PrefabSystem m_PrefabSystem
Prefab system used for resolving brush/prefab entities to prefab objects. -
private EntityQuery m_BulldozeQuery
EntityQuery used to find bulldoze-related prefab/entity data (used to initialize bulldozer prefab selection). -
private EntityQuery m_BrushQuery
EntityQuery used to enumerate BrushPrefab entities for BindBrushTypes. -
private RawValueBinding m_ActiveToolBinding
RawValueBinding that writes the currently active tool (id, mode index and modes) to the UI when requested. -
private List<ToolMode> m_ToolModes
Reusable list used when gathering UI modes for the active tool.
Properties
- This class does not expose public CLR properties. It uses UI bindings to expose tool state to the UI instead.
Constructors
public ToolUISystem()
[Preserve] default constructor. The real initialization happens in OnCreate where the system fetches required tool systems and registers bindings and event handlers.
Methods
-
protected override void OnCreate()
: System.Void
Initializes references to all relevant tool and game systems, prepares entity queries, registers event handlers (tool changed, prefab changed, bulldoze confirmation), and sets up the full set of UI bindings (getter, value and trigger bindings) that expose tool state and allow UI interactions. -
protected override void OnDestroy()
: System.Void
Tears down event handlers registered in OnCreate and calls base.OnDestroy(). -
private void BindActiveTool(IJsonWriter binder)
: System.Void
Writes the active tool object for the UI (tool id, current mode index and available UI modes) using the provided IJsonWriter. Uses BindToolModes to enumerate modes. -
private void BindToolModes(IJsonWriter binder)
: System.Void
Populates m_ToolModes by calling activeTool.GetUIModes, then writes each mode (id, index and icon path) to the provided IJsonWriter array. -
private void SetSelectedSnapMask(uint mask)
: System.Void
Sets the active tool's selectedSnap to the provided mask (Snap enum underlying uint). -
private string[] InitSnapOptionNames()
: System.String[]
Builds an array of snap option names from the Snap enum, excluding zero and uint.MaxValue entries. Used to populate snap option names for the UI. -
private void SelectTool(string tool)
: System.Void
Finds a ToolBaseSystem by name and delegates to SelectTool(ToolBaseSystem). -
public void SelectTool(ToolBaseSystem tool)
: System.Void
Sets m_ToolSystem.activeTool to the provided tool, and performs tool-specific initialization such as selecting a default bulldozer prefab when switching to bulldoze tool. -
private void SelectToolMode(int modeIndex)
: System.Void
Sets the selected mode/index for the currently active tool. Handles different tool types (Net, Zone, Bulldoze, Area, Object) and updates the active tool binding after change. -
private ToolBaseSystem GetToolSystem(string tool)
: ToolBaseSystem
Returns the correct ToolBaseSystem instance for a given tool name string (maps friendly names like "Net Tool" to internal system references). Defaults to DefaultToolSystem when no match. -
private void OnToolChanged(ToolBaseSystem tool)
: System.Void
Event handler invoked when the active tool changes. Disables terrain FX when leaving terrain tool and updates the active tool binding. -
private void OnPrefabChanged(PrefabBase prefab)
: System.Void
Event handler invoked when the selected prefab changes; triggers update of active tool binding so the UI shows the new prefab state. -
private void OnBulldozeConfirmationRequested()
: System.Void
Triggered by BulldozeToolSystem when a confirmation is required. Shows the confirmation dialog and hooks OnConfirmBulldoze as the callback. -
private void OnConfirmBulldoze(int msg)
: System.Void
Callback invoked by confirmation dialog; calls BulldozeToolSystem.ConfirmAction depending on user selection. -
private bool GetElevationUpDisabled()
: System.Boolean
Getter used by UI to determine if elevation up control should be disabled: checks Net tool elevation range and underground requirements. -
private void OnElevationUp()
: System.Void
Trigger that tells activeTool to raise elevation (activeTool.ElevationUp()). -
private bool GetElevationDownDisabled()
: System.Boolean
Getter used by UI to determine if elevation down should be disabled; mirrors GetElevationUpDisabled logic for down direction and underground allowances. -
private void OnElevationDown()
: System.Void
Trigger that tells activeTool to lower elevation (activeTool.ElevationDown()). -
private void OnElevationScroll()
: System.Void
Trigger that tells activeTool to perform elevation scroll action (activeTool.ElevationScroll()). -
private Bounds1 GetElevationRange()
: Bounds1
Returns the combined elevation range for the currently selected net prefab(s) if using Net tool and if the prefab provides PlaceableNet details. Used to clamp elevation up/down. -
private void SetElevationStep(float step)
: System.Void
Sets NetToolSystem.elevationStep. -
private bool GetParallelModeSupported()
: System.Boolean
Returns whether parallel mode is supported for the current net tool/prefab (based on prefab flags or lane selection and excluding grid/replace modes). -
private void ToggleParallelMode()
: System.Void
Toggles NetToolSystem.parallelCount between 0 and 1. -
private void SetParallelOffset(float offset)
: System.Void
Sets NetToolSystem.parallelOffset. -
private void SetUndergroundMode(bool enabled)
: System.Void
Enables/disables underground mode for the active tool (activeTool.SetUnderground). -
private void SetDistance(float distance)
: System.Void
Sets ObjectToolSystem.distance. -
private Brush[] BindBrushTypes()
: Brush[]
Enumerates brush entities via m_BrushQuery, resolves each to a BrushPrefab and returns an array of Brush structs for the UI, containing entity, name and priority. -
private void SelectBrush(Entity entity)
: System.Void
Selects the given brush entity for the active tool (sets activeTool.brushType), switches ObjectToolSystem into Brush mode when applicable, and handles deselecting (Entity.Null) by switching back to create mode for ObjectToolSystem. -
private bool AllowBrush()
: System.Boolean
Returns whether brushing is allowed for the currently active tool (true for TerrainToolSystem and for ObjectToolSystem subject to allowBrush flag). -
private void SetBrushSize(float size)
: System.Void
Sets activeTool.brushSize. -
private void SetBrushHeight(float height)
: System.Void
Sets TerrainToolSystem.brushHeight (adjusted by WaterSystem.SeaLevel). -
private void SetBrushStrength(float strength)
: System.Void
Sets activeTool.brushStrength. -
private void SetBrushAngle(float angle)
: System.Void
Sets activeTool.brushAngle. -
private void SetColor(Color32 color)
: System.Void
Sets activeTool.color. -
private bool GetColorSupported()
: System.Boolean
Returns true if the active tool's active prefab implements IColored. -
private bool IsEditor()
: System.Boolean
Returns whether the game is currently in an editor mode (GameManager.instance.gameMode.IsEditor()). -
void IJsonWritable.Write(IJsonWriter writer)
(implemented on nested Brush)
Serializes the Brush struct to JSON for the UI writer; used by BindBrushTypes and other writers.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Get the core tool system and setup a UI binding for the active tool
m_ToolSystem = base.World.GetOrCreateSystemManaged<ToolSystem>();
AddBinding(m_ActiveToolBinding = new RawValueBinding("tool", "activeTool", BindActiveTool));
}
Notes: - The system wires multiple getter and trigger bindings in OnCreate to provide the UI with up-to-date tool state and to accept UI-driven commands. - Event handlers registered in OnCreate are explicitly removed in OnDestroy to avoid memory leaks or dangling callbacks. - Many of the methods check the concrete active tool type (NetToolSystem, ObjectToolSystem, etc.) and cast accordingly to apply type-specific behavior.