Skip to content

Game.UI.Editor.EditorToolUISystem

Assembly: Assembly-CSharp
Namespace: Game.UI.Editor

Type: class

Base: UISystemBase

Summary:
Manages the editor-mode tool UI and bindings between the in-game editor tool systems and the UI. Initializes the standard editor tools, keeps track of the currently active tool, synchronizes tool disabled states with UI bindings, and routes entity selection to the inspector panel. Interacts with ToolSystem, EditorPanelUISystem and InspectorPanelSystem to coordinate selection and active UI panel behavior.


Fields

  • private const string kGroup = "editorTool"
    Group name used for UI bindings. The bindings created in OnCreate use this group.

  • private ToolSystem m_ToolSystem
    Reference to the game's ToolSystem (retrieved from the ECS world). Used to observe the currently selected entity.

  • private EditorPanelUISystem m_EditorPanelUISystem
    Reference to the EditorPanelUISystem (retrieved from the ECS world). Used to set which editor panel is active (e.g., inspector panel).

  • private InspectorPanelSystem m_InspectorPanelSystem
    Reference to the InspectorPanelSystem (retrieved from the ECS world). Used to route entity/mesh selection to the inspector.

  • private GetterValueBinding<IEditorTool[]> m_ToolsBinding
    Getter binding used to expose the tools array to the UI. Created with the "editorTool" group and "tools" key; uses an ArrayWriter> to serialize the tool list.

  • private IEditorTool[] m_Tools
    Currently exposed array of editor tools. The setter for the public tools property updates this field and refreshes the internal m_Disabled state array.

  • private bool[] m_Disabled
    Cached disabled states for each tool (mirrors IEditorTool.disabled) used to detect changes and trigger UI updates.

  • private IEditorTool m_ActiveTool
    Reference to the current active IEditorTool (null if none). The activeTool property setter ensures activation/deactivation is applied on the previous and new tool.

  • private Entity m_LastSelectedEntity
    Tracks the last entity that was selected (used to detect selection changes coming from ToolSystem).

Properties

  • public override GameMode gameMode => GameMode.Editor
    Specifies that this UI system operates in GameMode.Editor. This is used by the UI system manager to enable/disable systems per game mode.

  • public IEditorTool[] tools { get; set; }
    Getter returns the current m_Tools array.
    Setter replaces the tool array and initializes m_Disabled to the current disabled states of the supplied tools (m_Disabled = value.Select(t => t.disabled).ToArray()). The setter is used during OnCreate to initialize the default editor tools.

  • [CanBeNull] public IEditorTool activeTool { get; set; }
    The currently active tool. The setter implements logic to ensure only one tool is active at a time:

  • If the new value differs from the current m_ActiveTool, or if the current tool has become inactive externally, it will deactivate the previous tool (if non-null) by setting its active property to false, set m_ActiveTool, and activate the new tool (if non-null) by setting its active property to true.
  • The property can be set to null to deactivate the current tool.

Constructors

  • [Preserve] public EditorToolUISystem()
    Default constructor. Marked with [Preserve] to prevent Unity's code stripping from removing it. Initialization that depends on the ECS world is performed in OnCreate.

Methods

  • [Preserve] protected override void OnCreate() : System.Void
    Creates references to required systems and initializes the editor tool list and UI bindings. Key behaviors:
  • Retrieves ToolSystem, EditorPanelUISystem and InspectorPanelSystem from the ECS World.
  • Initializes the tools array with six built-in editor tools:
    • EditorAssetImportTool
    • EditorTerrainTool
    • EditorPrefabTool
    • EditorPrefabEditorTool
    • EditorPhotoTool
    • EditorBulldozeTool
  • Adds a GetterValueBinding for the tools array (group "editorTool", key "tools").
  • Adds a GetterValueBinding for the current active tool id (group "editorTool", key "activeTool").
  • Adds a TriggerBinding (group "editorTool", key "selectTool") that binds to SelectTool(string).
  • The bindings ensure the UI receives updates and can trigger tool selection.

  • [Preserve] protected override void OnUpdate() : System.Void
    Runs each frame while the system is active. Responsibilities:

  • If activeTool exists but its active flag has been turned off externally, clear activeTool (sets to null).
  • Detects changes in selected entity coming from m_ToolSystem.selected and forwards them to SelectEntity if they differ from m_LastSelectedEntity.
  • Calls UpdateToolState to detect tool disabled-state changes; if any state changed, triggers the tools binding so the UI updates.

  • public void SelectEntity(Entity entity) : System.Void
    Handles selection of an entity from ToolSystem or UI:

  • Stores the entity in m_LastSelectedEntity.
  • Calls m_InspectorPanelSystem.SelectEntity(entity). If it returns true, the inspector panel takes over: activeTool is set to null and m_EditorPanelUISystem.activePanel is set to the inspector panel.
  • If SelectEntity returns false and the active panel is currently the inspector, clears the active panel (sets activePanel to null).

  • public void SelectEntitySubMesh(Entity entity, int subMeshIndex) : System.Void
    Similar to SelectEntity but targets a specific sub-mesh of an entity:

  • Stores the entity in m_LastSelectedEntity.
  • Calls m_InspectorPanelSystem.SelectMesh(entity, subMeshIndex). If it returns true, the inspector panel becomes active and activeTool is cleared. Otherwise clears the active editor panel if it was the inspector.

  • public void SelectTool([CanBeNull] string id) : System.Void
    Selects a tool by its id string:

  • Sets activeTool to tools.FirstOrDefault(t => t.id == id).
  • If id is null or there is no matching tool, activeTool will be set to null, which deactivates any previously active tool.

  • private bool UpdateToolState() : System.Boolean
    Compares the current disabled state of each tool with the cached m_Disabled array and updates the cache:

  • Iterates all tools, checks each tool.disabled against m_Disabled[i].
  • If any difference is found, updates m_Disabled[i] and marks result true.
  • Returns true if any disabled state changed (caller uses this to trigger a UI binding update), otherwise false.

Usage Example

// Example: customizing the tool list during OnCreate (called by the system)
[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Obtain the UI system instance from the world (example only; actual retrieval depends on context)
    var editorToolSystem = World.GetOrCreateSystemManaged<Game.UI.Editor.EditorToolUISystem>();

    // Programmatically select a tool by id (will activate that tool and deactivate previous)
    editorToolSystem.SelectTool("editor.prefab");

    // Or iterate the tools to pick the first available
    var firstTool = editorToolSystem.tools?.FirstOrDefault();
    if (firstTool != null)
    {
        editorToolSystem.activeTool = firstTool;
    }

    // Select an entity (for the inspector panel)
    Entity someEntity = /* obtain entity */;
    editorToolSystem.SelectEntity(someEntity);

    // Add a custom tool to the UI tools list (append)
    var list = editorToolSystem.tools?.ToList() ?? new List<IEditorTool>();
    list.Add(new MyCustomEditorTool(World)); // MyCustomEditorTool : IEditorTool
    editorToolSystem.tools = list.ToArray(); // setter will update the disabled cache
}

Notes and remarks: - The system relies on IEditorTool implementations to expose id, active, and disabled members; toggling active on a tool is handled by this system's activeTool property to enforce single active tool semantics. - Bindings created in OnCreate expose "editorTool:tools", "editorTool:activeTool" and a trigger "editorTool:selectTool" to the UI layer. UI should call the trigger with a tool id to select tools via SelectTool. - [Preserve] attributes are used to prevent managed code stripping; [CanBeNull] annotations indicate properties that can return or accept null.