Game.Input.UIButtonInteraction
Assembly:
(Unknown — not provided in source)
Namespace: Game.Input
Type: class
Base: IInputInteraction
Summary:
Custom Unity Input System interaction that implements UI-style button behavior with support for initial repeat delay and continuous repeat while held. When the control value crosses the configured press point the interaction starts and immediately performs; while held it issues repeated Performed events after a configurable delay and at a configurable repeat rate. If pressPoint is not set (> 0) the interaction falls back to InputSystem.settings.defaultButtonPressPoint. The interaction registers itself with the Input System via InputSystem.RegisterInteraction in the static constructor.
{{
- Designed for use with the Unity Input System as an interaction that can be added to InputAction bindings (e.g. WithInteraction("UIButton(...)" ).
- Useful for UI buttons or keys where you want an initial press and then repeated actions while the input is held (like repeating menu navigation).
}}
Fields
-
public float repeatDelay
{{ Delay (in seconds) before the first repeated Performed event fires while the control remains actuated. Default in source: 0.5f. }} -
public float repeatRate
{{ Interval (in seconds) between subsequent Performed events after the initial repeatDelay has passed while the control is still actuated. Default in source: 0.1f. }} -
public float pressPoint
{{ Optional explicit press point threshold for actuation. If not set (> 0) the interaction will use InputSystem.settings.defaultButtonPressPoint. Typical for analog controls to decide when the button is considered pressed. }}
Properties
private float pressPointOrDefault { get; }
{{ Helper property that returns pressPoint when > 0; otherwise returns InputSystem.settings.defaultButtonPressPoint. Used internally to determine when the control is considered actuated. }}
Constructors
-
public UIButtonInteraction()
{{ Implicit default constructor — no special initialization occurs on instance construction. }} -
static UIButtonInteraction()
{{ Static constructor registers the interaction type with the Input System via InputSystem.RegisterInteraction(), making the interaction available to bindings. }}
Methods
public void Process(ref InputInteractionContext context)
{{ Core interaction logic. Behavior by phase:- Waiting: if the control is actuated (>= press point) the interaction calls context.Started(), context.PerformedAndStayStarted(), and sets a timeout to repeatDelay.
-
Started: if the timeout has expired, it calls context.PerformedAndStayStarted() and sets a timeout to repeatRate (for subsequent repeats). If the control is no longer actuated it calls context.Canceled(). This yields an immediate perform on press, then repeated performs while held. }}
-
public void Reset()
{{ No-op in this implementation — provided to satisfy the IInputInteraction contract. }} -
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] private static void Init()
{{ Empty method decorated to ensure the type is touched/loaded before scene load if needed. The registration actually happens in the static constructor; this method is present but empty. }}
Usage Example
// Example: add the interaction to a binding in code with custom parameters
var action = new InputAction("MyButtonAction", InputActionType.Button);
action.AddBinding("<Keyboard>/space")
.WithInteraction("UIButton(repeatDelay=0.5,repeatRate=0.1)"); // use interaction by name
action.performed += ctx => Debug.Log("Button performed");
action.canceled += ctx => Debug.Log("Button canceled");
action.Enable();
// Note:
// - The interaction is registered via InputSystem.RegisterInteraction<UIButtonInteraction>() in the static ctor,
// so it should be available by the name "UIButton" when adding WithInteraction("UIButton(...)").
// - If pressPoint is needed, specify it either by setting public field via interaction string parameters
// (if supported by your Input System version) or by making a custom configuration.