UI Toolbox logoUI Toolbox

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.

The face buttons, a shoulder button, a trigger, a stick and the D-pad in the Xbox, PlayStation, Switch and Generic looks, three mouse glyphs and a button with a progress ring

<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: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 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.
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

InputGlyph

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.
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.

Tips:

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.
.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); }

License