Skip to content

Game.Settings.SettingsUIKeyboardBindingAttribute

Assembly: Assembly-CSharp
Namespace: Game.Settings

Type: public class (attribute)

Base: SettingsUIKeybindingAttribute

Summary:
Attribute used to annotate settings properties that represent keyboard bindings in the game's settings UI. It defines a default keyboard key (via the BindingKeyboard enum), optional modifier keys (alt, ctrl, shift), and maps the chosen BindingKeyboard to an Input System control path (e.g. "/space"). The attribute also exposes modifier control paths when requested. Several overloads let you declare button, axis, or Vector2 bindings; legacy constructors accepting UnityEngine.InputSystem.Key are marked Obsolete and delegate to the BindingKeyboard-based constructors.


Fields

  • public readonly BindingKeyboard defaultKey
    The default keyboard key for this binding (uses the BindingKeyboard enum). If set, the attribute's control property returns the corresponding Input System control path for this key.

  • public readonly bool alt
    If true, the left/right Alt modifier is part of the binding and will be exposed by modifierControls as "/alt".

  • public readonly bool ctrl
    If true, the left/right Ctrl modifier is part of the binding and will be exposed by modifierControls as "/ctrl".

  • public readonly bool shift
    If true, the left/right Shift modifier is part of the binding and will be exposed by modifierControls as "/shift".

Properties

  • public override string control { get; }
    Returns the Input System control path corresponding to the configured defaultKey. The mapping covers common keys (letters, digits, function keys, arrows, numpad keys, OEM keys and many punctuation keys). If defaultKey is BindingKeyboard.None or not mapped, this returns an empty string.

  • public override IEnumerable<string> modifierControls { get; }
    Yields control path(s) for enabled modifier keys in the order: shift, ctrl, alt. Each yielded string is one of "/shift", "/ctrl", "/alt" depending on which of the shift/ctrl/alt fields are true.

Constructors

  • public SettingsUIKeyboardBindingAttribute(string actionName = null)
    Creates a button binding attribute (ActionType.Button, ActionComponent.Press) targeting the keyboard device. Use when you only need a basic button binding and want to optionally supply an action name.

  • public SettingsUIKeyboardBindingAttribute(AxisComponent component, string actionName = null)
    Creates an axis binding attribute (ActionType.Axis) for the keyboard device. Use when mapping an axis-like keyboard input to a setting.

  • public SettingsUIKeyboardBindingAttribute(Vector2Component component, string actionName = null)
    Creates a Vector2 binding attribute (ActionType.Vector2) for the keyboard device.

  • public SettingsUIKeyboardBindingAttribute(BindingKeyboard defaultKey, string actionName = null, bool alt = false, bool ctrl = false, bool shift = false)
    Specifies a default key and optional modifier flags. Calls the basic constructor internally to set action type to Button.

  • public SettingsUIKeyboardBindingAttribute(BindingKeyboard defaultKey, AxisComponent component, string actionName = null, bool alt = false, bool ctrl = false, bool shift = false)
    Specifies a default key for an Axis binding and optional modifiers.

  • public SettingsUIKeyboardBindingAttribute(BindingKeyboard defaultKey, Vector2Component component, string actionName = null, bool alt = false, bool ctrl = false, bool shift = false)
    Specifies a default key for a Vector2 binding and optional modifiers.

  • [Obsolete] public SettingsUIKeyboardBindingAttribute(Key defaultKey, string actionName = null, bool alt = false, bool ctrl = false, bool shift = false)
    Legacy constructor accepting UnityEngine.InputSystem.Key; marked obsolete and internally casts to BindingKeyboard.

  • [Obsolete] public SettingsUIKeyboardBindingAttribute(Key defaultKey, AxisComponent component, string actionName = null, bool alt = false, bool ctrl = false, bool shift = false)
    Legacy axis constructor accepting Key (obsolete).

  • [Obsolete] public SettingsUIKeyboardBindingAttribute(Key defaultKey, Vector2Component component, string actionName = null, bool alt = false, bool ctrl = false, bool shift = false)
    Legacy Vector2 constructor accepting Key (obsolete).

Methods

  • public override string control { get; }
    Getter that switches on defaultKey and returns a string control path such as:
  • BindingKeyboard.Space => "/space"
  • BindingKeyboard.A => "/a"
  • BindingKeyboard.Digit1 => "/1"
  • BindingKeyboard.F1 => "/f1"
  • BindingKeyboard.LeftArrow => "/leftArrow"
  • ...and many others. Returns empty string for BindingKeyboard.None or unknown values.

  • public override IEnumerable<string> modifierControls { get; }
    Iterator that yields one or more modifier control paths based on the shift/ctrl/alt boolean fields:

  • if shift: yields "/shift"
  • if ctrl: yields "/ctrl"
  • if alt: yields "/alt"

Usage Example

// Simple button binding with a default key (Space) and no modifiers.
[SettingsUIKeyboardBinding(BindingKeyboard.Space, actionName: "Action.Jump")]
public KeybindingSetting JumpKey { get; set; }

// Axis binding with a default key and Ctrl modifier.
[SettingsUIKeyboardBinding(BindingKeyboard.A, AxisComponent.Negative, actionName: "Action.MoveLeft", ctrl: true)]
public KeybindingSetting MoveLeftKey { get; set; }

// If you only need to specify the action name and not a default key:
[SettingsUIKeyboardBinding(actionName: "Action.Custom")]
public KeybindingSetting CustomActionKey { get; set; }

Notes and tips: - Prefer the BindingKeyboard-based constructors; the Key-based overloads are obsolete and will be removed in the future. - The attribute is intended for decorating properties that the game's settings UI reads to populate or edit keybindings. The control and modifierControls outputs can be used to register Input System bindings or display default hints in the UI.