UI Toolbox logoUI Toolbox
Support

GamepadGlyph and InputGlyph

A GamepadGlyph shows one gamepad button as a glyph, in the look of an Xbox, a PlayStation or a Switch gamepad. An InputGlyph shows any other input glyph: a mouse button, a key or a device. Use them in a button prompt, a tutorial, a key binding list or a quick time event. They only show the input; they do not listen for it.

Rows of gamepad glyphs for the Generic, Xbox, PlayStation and Switch families: face buttons, D-pad, shoulder buttons, triggers, stick clicks and menu buttonsRows of gamepad glyphs for the Generic, Xbox, PlayStation and Switch families: face buttons, D-pad, shoulder buttons, triggers, stick clicks and menu buttons

<tb:GamepadGlyph button="South" family="Xbox" />
<tb:GamepadGlyph button="LeftShoulder" family="PlayStation" />
<tb:GamepadGlyph
    button="East"
    family="Xbox"
    class="tb-gamepad-glyph--colored" />
<tb:GamepadGlyph button="South" progress="0.6" />
<tb:GamepadGlyph button="South" auto-family="true" />
<tb:GamepadGlyph
    button="West"
    auto-family="true"
    keyboard-glyph="keyboard-x" />
<tb:InputGlyph glyph="mouse-left" />
<tb:InputGlyph glyph="keyboard-enter" />
row.Add(new GamepadGlyph(GamepadGlyphButton.South, GamepadFamily.Xbox));
row.Add(new InputGlyph("mouse-left"));
row.Add(new InputGlyph(PromptFont.KEYBOARD_ENTER));

// The glyph of a binding, in the look of the gamepad of the player
if (GamepadGlyph.TryGetButton("<Gamepad>/buttonSouth", out var button))
    glyph.Button = button;
glyph.Family = GamepadGlyph.FamilyOf(Gamepad.current.layout);

// A glyph that follows the device the player used last: Enter on the
// keyboard, A, a cross or B on a gamepad
glyph.AutoFamily = true;

// A button that the player holds
glyph.Progress = heldSeconds / HOLD_SECONDS;

GamepadGlyph

Member Description
Button (button) The button, a GamepadGlyphButton (default South).
Family (family) The look, a GamepadFamily: Generic (default), Xbox, PlayStation or Switch.
AutoFamily (auto-family) The glyph follows the device that the player used last. After a gamepad button it shows Button in the family of that gamepad. After a key or a mouse button it shows the key of KeyboardGlyph. Off by default: the glyph shows Button in Family. See "Follow the last used device".
KeyboardGlyph (keyboard-glyph) With AutoFamily: the glyph for the keyboard and the mouse, a PromptFont name such as "keyboard-e" or "mouse-left". Empty (default) shows the key that the toolbox controls use for the button.
Action (code only) An InputAction of the game. The glyph shows the binding of the action, so a rebind shows at once: its gamepad binding in place of Button, and with AutoFamily its keyboard or mouse binding in place of KeyboardGlyph. Null (default) shows Button and KeyboardGlyph. Needs the Input System package.
Progress (progress) The part of the ring around the glyph that shows, from 0 to 1. See InputGlyph.
GamepadGlyph.TryGetButton(controlPath, out button) Gives the button of an Input System control path, such as "<Gamepad>/buttonSouth" or "<Gamepad>/dpad/up". False for a path that is not a gamepad button.
GamepadGlyph.FamilyOf(device) Gives the family of a device from its layout name or its display name, such as "DualSenseGamepadHID" or "Xbox Controller". An unknown name gives Generic.

The values of GamepadGlyphButton are the control names of the Unity Input System:

Buttons Values
Face buttons South, East, West, North
D-pad DpadUp, DpadDown, DpadLeft, DpadRight, Dpad (the full d-pad)
Shoulders and triggers LeftShoulder, RightShoulder, LeftTrigger, RightTrigger
Sticks LeftStick, RightStick, LeftStickPress, RightStickPress
Menu buttons Start, Select

Follow the last used device

A glyph with AutoFamily shows the button that the player can press now. A game for the keyboard, the mouse and gamepads then needs one glyph for each prompt, not a glyph for each device.

<!-- Enter on the keyboard, A on an Xbox gamepad, a cross on a
     PlayStation gamepad, B on a Switch gamepad -->
<tb:GamepadGlyph button="South" auto-family="true" />

The key of a glyph with an empty KeyboardGlyph:

Button Key
South Enter
East, Start Escape
LeftShoulder, RightShoulder Q, E
DpadUp, DpadDown, DpadLeft, DpadRight The arrow key
Dpad, LeftStick The four arrow keys
Any other button None. The glyph is hidden while the keyboard is the last device, unless KeyboardGlyph has a name.

One tracker, LastInputDevice, tells every AutoFamily glyph, PromptBar, InteractionPrompt and NavigableTabView with BumperSwitch which device the player used last.

Member Description
LastInputDevice.IsGamepad True when the player used a gamepad last. False for the keyboard and mouse, also before the first press.
LastInputDevice.Family The GamepadFamily of that gamepad. Generic while IsGamepad is false.
LastInputDevice.Changed Raised when IsGamepad or Family changes.
LastInputDevice.AutoDetect True (default): the tracker follows the input. False: the tracker ignores the input, and only Set changes the device. Use it for an option such as "Glyphs: Auto, Xbox, PlayStation, Switch, Keyboard".
LastInputDevice.Set(gamepad, family) Sets the device by hand. Use it for a fixed choice of the player, and for input that the Input System package does not read.
LastInputDevice.Retain(), Release() Keep the tracker running without a glyph on a panel. Each Retain needs a Release. A glyph with AutoFamily does this by itself while it is on a panel.

InputGlyph

A row of keyboard, mouse and gamepad InputGlyph icons above four E key glyphs with progress rings from 25% to 100%A row of keyboard, mouse and gamepad InputGlyph icons above four E key glyphs with progress rings from 25% to 100%

GamepadGlyph is an InputGlyph. Use an InputGlyph for a glyph that is not in the button list.

Member Description
Glyph (glyph) The PromptFont name of the glyph, such as "mouse-left", "keyboard-enter", "analog-l-up" or "device-gamepad". A text that is not a name shows as it is, so a PromptFont constant works too. The Inspector has a ComboBox that shows each glyph beside its name, and a preview.
Progress (progress) The part of the ring around the glyph that shows, from 0 to 1 (default 0). The ring fills clockwise from the top. 0 shows no ring.
PromptFont.<NAME> A constant for each glyph: the character of the glyph, such as PromptFont.MOUSE_LEFT.
PromptFont.Names The names of all glyphs.
PromptFont.TryGetGlyph(name, out glyph) Gives the character of a name. False for a name that the list does not have.
PromptFont.Matches(name, query) True when every typed word is part of the name or of its search words (family, button name, common words), in any order. PlayStation Square finds sony-x.

Tips:

In the examples

Styling

Class or property Element
tb-input-glyph The glyph. color is the color and font-size is the size.
tb-input-glyph__text The text element with the PromptFont font.
--tb-input-glyph-ring-color A custom property on the glyph: the color of the filled part of the ring (--tb-color-accent).
--tb-input-glyph-ring-track A custom property on the glyph: the color of the rest of the ring (--tb-color-border). A transparent color draws no track.
--tb-input-glyph-ring-width A custom property on the glyph: the width of the ring in pixels (3).
tb-gamepad-glyph On each GamepadGlyph.
tb-gamepad-glyph--generic, --xbox, --playstation, --switch The family.
tb-gamepad-glyph--south, --left-shoulder, --dpad-up, ... The button: its name in small letters with "-" between the words.
tb-gamepad-glyph--colored Opt-in. Add it to a glyph for the colors of the face buttons of an Xbox or a PlayStation gamepad. The other buttons keep color.
tb-gamepad-glyph--keyboard Replaces the family class while an AutoFamily glyph shows a key.
tb-gamepad-glyph--empty An AutoFamily glyph that has no key to show. It is display: none.
.prompt .tb-input-glyph {
    font-size: 32px;
    color: var(--tb-color-accent);
}
.prompt .tb-input-glyph {
    --tb-input-glyph-ring-color: var(--tb-color-success);
    --tb-input-glyph-ring-width: 4;
}
.prompt .tb-gamepad-glyph--south { color: var(--tb-color-success); }

The GamepadGlyphDemo scene shows each button in each family, the button hints of an inventory that follow the gamepad of the player, a hold prompt that opens a chest and a glyph that follows a gamepad binding. The InputGlyphDemo scene shows a tutorial whose prompts follow the device that the player uses, the looks of an InputGlyph and all the PromptFont glyphs with a search field.

License