Game.UI.Editor.EditorPrefabTool
Assembly: Assembly-CSharp
Namespace: Game.UI.Editor
Type: class
Base: EditorTool
Summary:
EditorPrefabTool is an editor tool used by the in-game editor UI to handle prefab placement/selection. It remembers the last selected PrefabBase between enable/disable cycles and activates the prefab placement UI/panel when enabled. The constructor initializes the tool id, icon and associates the tool with the PrefabToolPanelSystem from the provided Unity.Entities.World.
Fields
-
public const string kToolId
Constant tool identifier with value "PrefabTool". Can be used when registering or referring to this tool. -
[CanBeNull] private PrefabBase m_LastSelectedPrefab
Stores the last selected prefab instance (may be null). Used to restore the user's last selection when the tool is re-enabled.
Properties
- None declared in this class.
(This class relies on inherited properties from EditorTool such as id, icon, panel and the tool system reference used at runtime.)
Constructors
public EditorPrefabTool(World world)
Creates a new EditorPrefabTool associated with the supplied Unity.Entities.World. The constructor:- Calls the base EditorTool(World) constructor.
- Sets base.id = "PrefabTool" (matches kToolId).
- Sets base.icon = "Media/Editor/Object.svg".
- Sets base.panel by retrieving or creating the PrefabToolPanelSystem from the world (world.GetOrCreateSystemManaged
()).
Methods
protected override void OnEnable()
Called when the tool is enabled. This method:- Calls base.OnEnable().
-
Activates the prefab tool through the tool system and passes m_LastSelectedPrefab so the previously selected prefab (if any) is restored.
-
protected override void OnDisable()
Called when the tool is disabled. This method: - Saves the current active prefab from the tool system into m_LastSelectedPrefab so it can be restored later.
- Calls base.OnDisable().
Usage Example
// Typical creation from an editor/system that has a Unity.Entities.World reference:
var prefabTool = new Game.UI.Editor.EditorPrefabTool(world);
// The editor/tool manager would be responsible for enabling/disabling the tool.
// When enabled, EditorPrefabTool will restore the last selected prefab (if any)
// and activate the prefab tool UI. When disabled it will remember the active prefab.
{{ Additional notes: - Depends on PrefabBase and PrefabToolPanelSystem (Game.Prefabs and editor panel system). - Uses Unity.Entities.World to find/create the corresponding panel/system. - Attributes: m_LastSelectedPrefab is annotated with [CanBeNull] indicating null is an expected value. - The class is intended to be used within the editor/tool framework and interacts with the tool system (m_ToolSystem) inherited from EditorTool. }}