Docsv3.31.0
Back to API Reference
Class

TextContextMenu

abstract
Inherits:MonoBehaviour

Context menu a field presents in Unity UI, from a prefab: its own (UniTextSelectable.ContextMenuPrefab) or the project's (UniTextSettings.ContextMenuPrefab). UniTextContextMenu is the menu laid out from Unity UI objects; derive from this class for a menu of your own — radial, animated, anything.

Remarks

The field instantiates the prefab once per play session under the shared touch overlay, a screen-space canvas above every other measured in density-independent units, and every field presenting the same prefab shares that instance. The field calls Show each time the menu opens, whenever its entries change, and again to re-anchor a menu touch opened over a selection that moved; every call arrives on the main thread. TextMenuPlacement.Trigger tells the menu what opened it.

Derived Types(1)

Types that inherit from TextContextMenu.

public bool IsVisible{ get }

Whether the menu is shown.

public abstract void Show(in TextMenuPlacement placement, IReadOnlyList<TextMenuEntry> entries, Action<int> invoke)

Shows entries at placement and records invoke as the single receiver of invoked entries until the next Show replaces it or Hide clears it — a menu shared across fields always reports to the field that showed it last. A disabled entry (TextMenuEntry.IsEnabled) shows disabled or not at all and is never invoked; a menu left with nothing to show hides.

public abstract void Hide()

Hides the menu and clears the recorded receiver.

public virtual void HandleKey(NativeKeyCode key, NativeModifiers modifiers)

Receives a key pressed while the menu is shown for a mouse, a pen or the keyboard. The field keeps every key from its text until the menu closes and closes it on Escape itself; the menu moves through its entries with the rest or ignores them, as it does by default.