Logo

Input Glyphs

Show an input action's key on the device in use, following rebinds

Overview

Input Glyphs draw the key of an Input System action the way the player sees it: a key cap with its name on a keyboard, the button's picture on a gamepad, the mouse for a click. They follow the device the player used last and any rebinds, so a prompt never shows a key the player can't press.

Input Glyphs require the Input System package.

ComponentDescription
Input GlyphDraws the key of one action.
Input Glyph HintAn action's key beside what it does, such as Interact. The supplied prefab is Input Glyph (Hint).
Input Glyph Hint ListA column of hints filled from code, for keys that change at runtime.
Input Glyph SetAn asset that sets how each control looks, like a font for keys.

Usage

Select GameObject -> Evo UI -> Input -> Input Glyph or Input Glyph (Hint), or add one from the UI Catalog.

Assign Content -> Action. The supplied Glyph Set is Evo UI/Prefabs/Input/Default Input Glyphs.

Use the Preview As buttons to see the glyph on each device the set has glyphs for. Entering Play Mode draws it for the device in use.

For a hint, write what the action does in Words. A hint without an action shows its words alone, and a hint whose action has no binding on any device hides and takes no room in its layout.


Glyph Sets

A glyph set is a list of glyphs. Each glyph is one control, picked with the Input System's own control picker, the same one used for bindings. Select Listen in the picker and press a control to pick it.

FieldDescription
ControlThe control and the device it belongs to, such as <Gamepad>/buttonSouth or <Mouse>/leftButton.
ShapeKey: a cap that grows with its label. Round: a round cap. Bare: the icon or label alone.
ContentIcon: the control's picture. Label: text, such as LMB for the left mouse button.
IconThe picture shown with Icon content. Without one, the binding's own name is written.
LabelThe text shown with Label content. Leave it empty to use the binding's own name.
Override ColorColors the label or icon with Color.

A device looks for its own glyph first, then the glyphs of the devices it is built on. A DualSense uses <DualShockGamepad> glyphs, and any pad without glyphs of its own uses the <Gamepad> ones. The supplied set has Xbox pictures under <Gamepad> and DualSense pictures under <DualShockGamepad>, so Xbox, Switch and other pads show Xbox buttons.

A control without a glyph is drawn as a key cap with the binding's own name, so every key a player can rebind to still shows. Keyboard keys use this by default.

Creating a Set

Duplicate the supplied set into your own folder, or create one from Create -> Evo -> UI -> Input Glyph Set, and assign it to your glyphs' Glyph Set field.

Any device the Input System knows can have glyphs, including touchscreens, pens and devices with layouts of your own: add a glyph and pick one of its controls. To give one controller its own pictures, pick its controls under its specific device, such as <XInputController> for Xbox controllers only.

If you change the glyphs list from code, call Refresh() on the set afterwards. Inspector changes are read automatically.

Colors

A glyph's parts keep the colors set on the prefab, from their Styler or their own color. Override Color paints the label or icon of that one glyph. In Play Mode it turns on the part's Styler Use Custom Color, and gives the Styler its color back when a glyph without an override is drawn.


Devices

The device in use is the last one that started or performed an action, so a resting gamepad's noise never takes over from the keyboard. A keyboard and a mouse count as one device: moving the mouse while typing changes nothing.

An action shows its first binding that serves the device in use: a binding of that device or of a device it is built on, so a <Gamepad> binding serves every pad. When no binding serves it, the first binding of another device is shown, dimmed to Other Device Alpha. A composite of one stick's directions is drawn as that stick. A composite of separate keys shows their names, such as W/A/S/D.

Binding overrides show at once. Overrides applied to actions that aren't enabled don't notify anything: call InputDeviceTracker.Refresh() after applying them.

To pin one device, such as a settings option for PlayStation prompts, set InputDeviceTracker.Forced to its layout name.

The device in use is shared by every glyph, so local multiplayer with separate prompts per player isn't covered.

Hint Lists

Use Input Glyph Hint List when the keys change at runtime, such as the actions for the item a player holds. Assign Hint Prefab and Content, which needs a layout group, then call Show() with a list of hints. Rows are created the first time they're needed and reused after. Showing the same list again does nothing, so it is safe to call whenever something may have changed.

For keys that never change, place Input Glyph (Hint) prefabs directly instead, so their words stay editable in the scene or prefab.


Public API

All types are in the Evo.UI namespace.

Input Glyph

NameTypeDescription
ActionInputActionThe action drawn. Returns the referenced action until code sets another, such as a component's own action.
GlyphSetInputGlyphSetThe set the glyph's looks come from.
HasBindingboolWhether the action has a binding on any device, so something is drawn.
NameParametersDescription
Redraw()NoneDraws the key for the device in use.
Draw()string layoutDraws the key as it looks on a device layout, such as "DualShockGamepad".
NameTypeDescription
Redrawnevent ActionRaised after each draw, for anything that follows the glyph's size or visibility.

Input Glyph Hint

NameTypeDescription
GlyphInputGlyphThe hint's glyph.
NameParametersDescription
Set()InputAction action, string textShows the action's key beside the text. With no action, shows the text alone.
Set()InputGlyphHintData hintShows a hint.

Input Glyph Hint List

NameTypeDescription
CountintNumber of hints shown.
NameParametersDescription
Show()IReadOnlyList<InputGlyphHintData> hintsShows the hints, one row each, in order.
Clear()NoneShows no hints.

Input Glyph Hint Data

A hint as code hands it over. Create these once per state, not every frame.

NameParametersDescription
InputGlyphHintData()InputAction action, string wordsA hint for an action.
InputGlyphHintData()InputActionReference action, string wordsA hint for a referenced action.

Input Glyph Set

NameTypeDescription
glyphsList<Glyph>The set's glyphs.
NameParametersDescription
Find()string layout, string controlThe glyph for a control, such as "buttonSouth", on a device layout or the nearest layout it is built on. Null when the set has none.
GetLayouts()NoneThe device layouts the set has glyphs for.
Refresh()NoneReads glyphs again on the next Find().

Input Device Tracker

NameTypeDescription
CurrentstringLayout of the device in use, or Forced while it is set.
ForcedstringPins a device layout whatever the player uses. Null follows the player.
NameParametersDescription
Refresh()NoneHas every glyph read its binding's name and draw again.
IsUsing()string layoutWhether the device in use is the layout or built on it. IsUsing("Gamepad") is true for any pad.
IsBasedOn()string layout, string baseLayoutWhether a layout is another or built on it.
BasesOf()string layoutThe layout followed by the layouts it is built on, nearest first, such as DualSenseGamepadHID, DualShockGamepad, Gamepad.
ShownAs()string device, string layoutThe layout a control of layout is shown as while device is in use: the device itself when it is built on that layout, the keyboard or mouse for each other's controls, or null when the device doesn't serve it.
UsedTogether()string a, string bWhether two layouts count as one device: the same layout, or a keyboard and a mouse.
NameTypeDescription
Changedstatic event ActionRaised when the device in use switches or bindings change.

Input Glyph Lookup

NameParametersDescription
TryResolve()InputAction action, string layout, InputGlyphSet set, out InputGlyphInfo infoThe binding an action shows on a device and its glyph. False when the action has no binding.

InputGlyphInfo holds the Glyph (null for a plain key cap), the binding's Label such as Esc, and OtherDevice, which is true when the binding belongs to another device. Its Text is what a glyph writes: the glyph's label when it shows one, otherwise Label. Use it to name a key in text.

Example

InputGlyphExample.cs
using UnityEngine;
using UnityEngine.InputSystem;
using Evo.UI;

public class InputGlyphExample : MonoBehaviour
{
    [SerializeField] private InputGlyphHintList hints;
    [SerializeField] private InputActionReference use;
    [SerializeField] private InputActionReference drop;

    private InputGlyphHintData[] holding;

    private void Start()
    {
        // Build hints once per state, then show them when the state starts
        holding = new[]
        {
            new InputGlyphHintData(use, "Use"),
            new InputGlyphHintData(drop, "Drop")
        };
    }

    public void OnPickedUp() => hints.Show(holding);

    public void OnDropped() => hints.Clear();

    public void SetPlayStationPrompts(bool on)
    {
        InputDeviceTracker.Forced = on ? "DualShockGamepad" : null;
    }
}

On this page