Skip to content

Game.UI.Editor.EditorTool

Assembly:
Game

Namespace:
Game.UI.Editor

Type:
class

Base:
System.Object
Implements: IEditorTool, IJsonWritable, IUITagProvider

Summary:
Represents a UI editor tool entry that ties a UI panel and an optional runtime tool (ToolBaseSystem) into the editor tool system. Responsible for querying and setting activation state, selecting the active editor panel, and delegating activation of the associated runtime tool via the ToolSystem.


Fields

  • protected ToolSystem m_ToolSystem
    Reference to the global ToolSystem obtained from the ECS World. Used to query and change the currently active tool or selected entity.

  • protected EditorPanelUISystem m_EditorPanelUISystem
    Reference to the EditorPanelUISystem obtained from the ECS World. Used to get/set the active editor panel in the UI.

Properties

  • public string id { get; set; }
    Identifier for this editor tool (used by UI or serialization).

  • public string icon { get; set; }
    Icon identifier (path or resource key) for display in the UI.

  • public bool disabled { get; set; }
    Whether the tool is disabled (UI may render it non-interactable).

  • public string shortcut { get; set; }
    Keyboard shortcut string associated with the tool.

  • public string uiTag { get; set; }
    UI tag for grouping or lookup in the UI system.

  • [CanBeNull] public IEditorPanel panel { get; set; }
    Optional associated editor panel. When set as the active panel, the EditorPanelUISystem.activePanel is updated.

  • [CanBeNull] public ToolBaseSystem tool { get; set; }
    Optional runtime tool (ToolBaseSystem) to activate in the ToolSystem when this editor tool is enabled.

  • public bool active { get; private set }
    Gets or sets the active state. The getter calls IsActive() to determine current state. Setting to true calls OnEnable(); setting to false calls OnDisable().

Constructors

  • public EditorTool(World world)
    Initializes a new EditorTool and caches references to the ToolSystem and EditorPanelUISystem from the provided ECS World:
  • world.GetOrCreateSystemManaged() → m_ToolSystem
  • world.GetOrCreateSystemManaged() → m_EditorPanelUISystem

Methods

  • protected virtual bool IsActive() : System.Boolean
    Determines whether this tool is currently active. Logic:
  • Returns true if the EditorPanelUISystem.activePanel equals this tool's panel.
  • If a tool instance is assigned, also requires m_ToolSystem.activeTool == tool.
  • Otherwise returns false.

  • protected virtual void OnEnable() : System.Void
    Enables this editor tool. Behavior:

  • Clears m_ToolSystem.selected (sets to Entity.Null).
  • Sets m_EditorPanelUISystem.activePanel to this.panel.
  • If a tool is assigned, sets m_ToolSystem.activeTool to this.tool.

  • protected virtual void OnDisable() : System.Void
    Disables this editor tool. Behavior:

  • If the active panel equals this.panel, clears m_EditorPanelUISystem.activePanel.
  • If a tool is assigned and it is the currently active tool in m_ToolSystem, calls m_ToolSystem.ActivatePrefabTool(null) to deactivate/clear it.

Usage Example

// Example subclass that configures an EditorTool
public class MyPlacementEditorTool : EditorTool
{
    public MyPlacementEditorTool(World world) : base(world)
    {
        id = "MyPlacement";
        icon = "Textures/Icons/placement";
        shortcut = "P";
        uiTag = "PlacementTools";
        // panel and tool would typically be assigned by the UI/system that creates this instance
    }

    protected override void OnEnable()
    {
        base.OnEnable();
        // custom enable logic, e.g. initialize UI state or start a placement preview
    }

    protected override void OnDisable()
    {
        // custom cleanup before base behavior
        base.OnDisable();
    }
}

// Typical runtime usage:
var world = World.DefaultGameObjectInjectionWorld;
var myTool = new MyPlacementEditorTool(world);
myTool.panel = someEditorPanel;      // assign a panel that implements IEditorPanel
myTool.tool = someToolBaseSystem;    // assign the runtime tool if available

// Activate the tool (this sets UI panel and activates tool in ToolSystem)
myTool.active = true;

// Deactivate
myTool.active = false;