Skip to content

Editor Tools

Ilia Petrov-Komotskii edited this page Sep 24, 2026 · 6 revisions

Editor Tools

Editor-only helpers for placing UI and editing Selectable navigation. Namespace Mane.Unity.UI.Editor.

UICanvasTools

Use these when you add a GameObject → UI menu item of your own (same pattern as Three States Toggle).

using Mane.Unity.UI.Editor;
using UnityEditor;
using UnityEngine;

[MenuItem("GameObject/UI (Canvas)/My Widget", false, 2200)]
private static void Create(MenuCommand menuCommand)
{
    GameObject go = ObjectFactory.CreateGameObject("My Widget");
    UICanvasTools.PlaceUIElement(go, menuCommand);
    UICanvasTools.BeginHierarchyRename();
}
Method Role
PlaceUIElement(element, menuCommand) Parent under a Canvas (create if needed), unique sibling name, select. Prefab Stage aware.
GetOrCreateCanvas() Valid canvas in the current stage, or CreateCanvas().
CreateCanvas() Screen Space Overlay + scaler + raycaster on the UI layer. Ensures EventSystem in scenes.
EnsureEventSystem() Adds EventSystem + input module if the stage has none.
SetParentAndAlign Parent, reset local transform, copy layer.
IsValidCanvas Active, not hidden, current stage.
BeginHierarchyRename() Focus Hierarchy and start rename next tick.

UINavigationControl

Reusable UI Toolkit block for a Selectable's Navigation: mode, wrap-around (horizontal/vertical), explicit targets, and Visualize.

Default binding path is m_Navigation. Call Bind(serializedObject) from a custom inspector (ThreeStatesToggle already does).

Navigation.Mode is [Flags]. The popup (NavigationModeField) lets you combine bits, including Automatic + Explicit (“Everything”).

Visualize draws Scene View arrows between Selectable.FindSelectableOn* results (same PrefKey as Unity's own selectable editor: SelectableEditor.ShowNavigation). Selected control is brighter. The overlay is subscribed only while a navigation control is in the inspector.

Screenshot: navigation-visualize.png — Scene View arrows on after Visualize. Host at https://raw.githubusercontent.com/wiki/ManeFunction/ManeTools-UnityUI/navigation-visualize.png.

Clone this wiki locally