From 772c64f32a9e89d9cd5113569ead5c58b67bc536 Mon Sep 17 00:00:00 2001 From: Siobhan Date: Wed, 29 Jan 2025 17:08:53 +0000 Subject: [PATCH 1/7] First phase of re-organising content. --- .../Documentation~/Interactions.md | 32 ++--- .../apply-interactions-actions.md | 24 ++++ .../apply-interactions-bindings.md | 28 ++++ .../Documentation~/built-in-interactions.md | 105 +++++++++++++++ .../Documentation~/default-interactions.md | 34 +++++ ...s-work.md => introduction-interactions.md} | 16 ++- .../Documentation~/predefined-interactions.md | 127 +----------------- .../Documentation~/using-interactions.md | 35 ----- .../write-custom-interactions.md | 18 ++- 9 files changed, 230 insertions(+), 189 deletions(-) create mode 100644 Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md create mode 100644 Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md create mode 100644 Packages/com.unity.inputsystem/Documentation~/built-in-interactions.md create mode 100644 Packages/com.unity.inputsystem/Documentation~/default-interactions.md rename Packages/com.unity.inputsystem/Documentation~/{how-interactions-work.md => introduction-interactions.md} (89%) delete mode 100644 Packages/com.unity.inputsystem/Documentation~/using-interactions.md diff --git a/Packages/com.unity.inputsystem/Documentation~/Interactions.md b/Packages/com.unity.inputsystem/Documentation~/Interactions.md index 6f6356c561..d20c521158 100644 --- a/Packages/com.unity.inputsystem/Documentation~/Interactions.md +++ b/Packages/com.unity.inputsystem/Documentation~/Interactions.md @@ -3,26 +3,12 @@ uid: input-system-interactions --- # Interactions -- [Operation](#operation) - - [Multiple Controls on an Action](#multiple-controls-on-an-action) - - [Multiple Interactions on a Binding](#multiple-interactions-on-a-binding) - - [Timeouts](#timeouts) -- [Using Interactions](#using-interactions) - - [Interactions applied to Bindings](#interactions-applied-to-bindings) - - [Interactions applied to Actions](#interactions-applied-to-actions) -- [Predefined Interactions](#predefined-interactions) - - [Default Interaction](#default-interaction) - - [Press](#press) - - [Hold](#hold) - - [Tap](#tap) - - [SlowTap](#slowtap) - - [MultiTap](#multitap) -- [Writing custom Interactions](#writing-custom-interactions) - -An Interaction represents a specific input pattern. For example, a [hold](#hold) is an Interaction that requires a Control to be held for at least a minimum amount of time. - -Interactions drive responses on Actions. You can place them on individual Bindings or an Action as a whole, in which case they apply to every Binding on the Action. At runtime, when a particular interaction completes, this triggers the Action. - -![Interaction Properties](Images/InteractionProperties.png) - - +Use Interactions to interpret specific input patterns from Controls that define Action behavior. + +|Topic|Description| +|-----|-----------| +|[Introduction to interactions](introduction-interactions.md)| Use Interactions on Bindings and Actions to read control input patterns and trigger Actions.| +|[Apply interactions to Bindings](using-interactions.md)| Apply Interactions to individual Bindings.| +|[Apply Interactions to Actions](using-interactions.md)| Apply Interactions to Actions, and all the Bindings associated with that Action. | +|[Predefined interactions](predefined-interactions.md)| Use the Input System's default and built-in Interactions on your Actions and Bindings.| +|[Write custom interactions](write-custom-interactions.md)| Write your own custom Interactions for your Actions and Bindings.| \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md new file mode 100644 index 0000000000..411a72b2c5 --- /dev/null +++ b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md @@ -0,0 +1,24 @@ +# Apply Interactions to Actions + +Applying Interactions directly to an Action is equivalent to applying them to all Bindings for the Action. You can use this instead of manually adding the same Interaction(s) to multiple Bindings. + +To apply Interactions to individual Bindings, refer to [Apply Interactions to Bindings](apply-interactions-bindings). + +If you apply Interactions to both an Action and its Bindings, then the effect is the same as if the Action's Interactions are on the list of Interactions on each of the Bindings. This means that the Input System applies the Binding's Interactions first, and then the Action's Interactions. + +## Apply Interactions to Actions via the Editor + +To apply interactions via the Input Action Editor: + +1. Select an Action to edit, so that the right pane of the window displays the properties for that Action. +1. Select the plus icon on the __Interactions__ foldout to open a list of all available Interactions types. +1. Select an Interaction type to add an Interaction instance of that type. The Interaction now appears in the __Interactions__ foldout. +1. If the Interaction has any parameters, you can now edit them at this stage. + +## Apply Interactions to Actions via code + +If you create your Actions in code, you can add Interactions like this: + +```CSharp +var Action = new InputAction(Interactions: "tap(duration=0.8)"); +``` \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md new file mode 100644 index 0000000000..0248fd37c7 --- /dev/null +++ b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md @@ -0,0 +1,28 @@ +# Apply Interactions to Bindings + +When you create Bindings for your [Actions](actions.md), you can choose to add Interactions to the Bindings via the Editor, or via code. + +To apply Interactions to all Bindings on an Action, refer to [Apply Interactions to Actions](apply-interactions-sctions). + +## Apply Interactions to Bindings via the Editor + +If you're using [project-wide actions](ActionsEditor.md), or [Input Action Assets](ActionAssets.md), you can add any Interaction to your Bindings via the Input Action editor. + +1. Once you have [created some Bindings](ActionsEditor.md#bindings), select the Binding you want to add Interactions to, so that the right pane of the window displays the properties for that Binding. +1. Select the plus icon on the __Interactions__ foldout to open a list of all available Interactions types. +1. Select an Interaction type to add an Interaction instance of that type. The Interaction now appears in the __Interactions__ foldout. +1. If the Interaction has any parameters, you can now edit them at this stage. + +![Binding Processors](Images/BindingProcessors.png) + +To remove an Interaction, select the minus (-) button next to it. To change the [order of Interactions](#multiple-interactions-on-a-binding), select the up and down arrows. + +## Apply Interactions to Bindings via code + +To add Interactions to Bindings that you created in code, you can use the following code sample as a template: + +```CSharp +var Action = new InputAction(); +action.AddBinding("/leftStick") + .WithInteractions("tap(duration=0.8)"); +``` \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/Documentation~/built-in-interactions.md b/Packages/com.unity.inputsystem/Documentation~/built-in-interactions.md new file mode 100644 index 0000000000..9c3f750d50 --- /dev/null +++ b/Packages/com.unity.inputsystem/Documentation~/built-in-interactions.md @@ -0,0 +1,105 @@ +# Built-in Interactions + +The Input System package comes with a set of built-in Interactions, which you can use on Actions and Bindings: + +* [`PressInteraction`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html) +* [`HoldInteraction`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html) +* [`TapInteraction`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html) +* [`SlowTapInteraction`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html) +* [`MultiTapInteraction`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html) + +Each built-in Interaction has its own parameters, and responds differently to Interaction callbacks. + +>[!Note] +>The built-in Interactions operate on Control actuation and don't use Control values directly. The Input System evaluates the `pressPoint` parameters against the magnitude of the Control actuation. This means you can use these Interactions on any Control which has a magnitude, such as sticks, and not just on buttons. + +If an Action or Binding has no Interaction set, the system uses its [default Interaction](default-interactions.md). + +## Built-in Press Interaction + +You can use a [`PressInteraction`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html) to explicitly force button-like interactions. Use the [`behavior`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_behavior) parameter to select if the Interaction should trigger on button press, release, or both. + +|__Parameters__|Type|Default value| +|---|---|---| +|[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| +|[`behavior`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_behavior)|[`PressBehavior`](../api/UnityEngine.InputSystem.Interactions.PressBehavior.html)|`PressOnly`| + + +|__Callbacks__/[`behavior`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_behavior)|`PressOnly`|`ReleaseOnly`|`PressAndRelease`| +|---|-----------|-------------|-----------------| +|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)| +|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|- Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)
or
- Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)| +|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|not used|not used|not used| + +## Built-in Hold Interaction + +A [`HoldInteraction`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html) requires the user to hold a Control for [`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration) seconds before the Input System triggers the Action. + +|__Parameters__|Type|Default value| +|---|---|---| +|[`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration)|`float`|[`InputSettings.defaultHoldTime`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultHoldTime)| +|[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| + + +To display UI feedback when a button starts being held, use the [`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started) callback. + +```C# + + action.started += _ => ShowGunChargeUI(); + action.performed += _ => FinishGunChargingAndHideChargeUI(); + action.cancelled += _ => HideChargeUI(); + +``` + +|__Callbacks__|| +|---|---| +|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_pressPoint).| +|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude held above [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_pressPoint) for >= [`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration).| +|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_pressPoint) before [`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration) (that is, the button was not held long enough).| + +## Built-in Tap Interaction + +A [`TapInteraction`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html) requires the user to press and release a Control within [`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration) seconds to trigger the Action. + +|__Parameters__|Type|Default value| +|---|---|---| +|[`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration)|`float`|[`InputSettings.defaultTapTime`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultTapTime)| +|[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| + +|__Callbacks__|| +|---|---| +|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_pressPoint).| +|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_pressPoint) before [`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration).| +|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control magnitude held above [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_pressPoint) for >= [`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration) (that is, the tap was too slow).| + +## Built-in SlowTap Interaction + +A [`SlowTapInteraction`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html) requires the user to press and hold a Control for a minimum duration of [`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration) seconds, and then release it, to trigger the Action. + +|__Parameters__|Type|Default value| +|---|---|---| +|[`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration)|`float`|[`InputSettings.defaultSlowTapTime`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultSlowTapTime)| +|[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| + +|__Callbacks__|| +|---|---| +|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_pressPoint).| +|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_pressPoint) after [`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration).| +|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_pressPoint) before [`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration) (that is, the tap was too fast).| + +## Built-in MultiTap Interaction + +A [`MultiTapInteraction`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html) requires the user to press and release a Control within [`tapTime`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapTime) seconds [`tapCount`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapCount) times, with no more then [`tapDelay`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapDelay) seconds passing between taps, for the Interaction to trigger. You can use this to detect double-click or multi-click gestures. + +|__Parameters__|Type|Default value| +|---|---|---| +|[`tapTime`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapTime)|`float`|[`InputSettings.defaultTapTime`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultTapTime)| +|[`tapDelay`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapDelay)|`float`|2 * [`tapTime`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapTime)| +|[`tapCount`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapCount)|`int`|2| +|[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| + +|__Callbacks__|| +|---|---| +|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint).| +|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude went back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint) and back up above it repeatedly for [`tapCount`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapCount) times.| +|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|- After going back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint), Control magnitude did not go back above [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint) within [`tapDelay`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapDelay) time (that is, taps were spaced out too far apart).
or
- After going back above [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint), Control magnitude did not go back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint) within [`tapTime`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapTime) time (that is, taps were too long).| \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/Documentation~/default-interactions.md b/Packages/com.unity.inputsystem/Documentation~/default-interactions.md new file mode 100644 index 0000000000..4add5410f2 --- /dev/null +++ b/Packages/com.unity.inputsystem/Documentation~/default-interactions.md @@ -0,0 +1,34 @@ +# Default Interactions + +Different Action types have different default Interactions. For example, the following diagram shows the behavior of the built-in Interactions for a simple button press. + +![Interaction Diagram](./Images/InteractionsDiagram.png) + +The following table provides an at-a-glance overview of how Interaction phases change for each action type's default Interaction. + +|__Callback__|[`InputActionType.Value`](RespondingToActions.md#value)|[`InputActionType.Button`](RespondingToActions.md#button)|[`InputActionType.PassThrough`](RespondingToActions.md#pass-through)| +|-----------|-------------|------------|-----------------| +|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control(s) changed value away from the default value.|Button started being pressed but has not necessarily crossed the press threshold yet.|not used| +|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control(s) changed value.|Button was pressed to at least the button [press threshold](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint).|Control changed value.| +|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control(s) are no longer actuated.|Button was released. If the button was pressed above the press threshold, the button has now fallen to or below the [release threshold](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_buttonReleaseThreshold). If the button was never fully pressed, the button is now back to completely unpressed.|Action is disabled.| + +## Value Action default Interaction + +[`Value`](RespondingToActions.md#value)-type Actions have a default Interaction with the following behavior: + +1. As soon as a bound Control becomes [actuated](Controls.md#control-actuation), the Action's Interaction phase goes from `Waiting` to `Started`, and then immediately to `Performed` and back to `Started`. One callback occurs on [`InputAction.started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started), followed by one callback on [`InputAction.performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed). +2. For as long as the bound Control remains actuated, the Action's Interaction phase stays in `Started` and triggers `Performed` whenever the value of the Control changes (that is, one call occurs to [`InputAction.performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)). +3. When the bound Control stops being actuated, the Action's Interaction phase goes to `Canceled` and then back to `Waiting`. One call occurs to [`InputAction.canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled). + +## Button Action default Interaction + +[`Button`](RespondingToActions.md#button)-type Actions have a default Interaction with the following behavior: + +1. As soon as a bound Control becomes [actuated](Controls.md#control-actuation), the Action's Interaction phase goes from `Waiting` to `Started`. One callback occurs on [`InputAction.started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started). +2. If a Control then reaches or exceeds the button press threshold, the Action's Interaction phase goes from `Started` to `Performed`. One callback occurs on [`InputAction.performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed). The default value of the button press threshold is defined in the [input settings](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint). However, an individual control can [override](../api/UnityEngine.InputSystem.Controls.ButtonControl.html#UnityEngine_InputSystem_Controls_ButtonControl_pressPoint) this value. +3. Once the Action has `Performed`, if all Controls then go back to a level of actuation at or below the [release threshold](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_buttonReleaseThreshold), the Action's Interaction phase goes from `Performed` to `Canceled`. One call occurs to [`InputAction.canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled). +4. If the Action's Interaction phase never went to `Performed`, it will go to `Canceled` as soon as all Controls are released. One call occurs to [`InputAction.canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled). + +## PassThrough Action default Interaction + +[`PassThrough`](RespondingToActions.md#pass-through)-type Actions have a default Interaction with a simpler behavior. The Input System doesn't try to track bound Controls as a single source of input. Instead, it triggers a `Performed` callback for each value change. \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/Documentation~/how-interactions-work.md b/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md similarity index 89% rename from Packages/com.unity.inputsystem/Documentation~/how-interactions-work.md rename to Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md index b1b0bbbc40..180795c67b 100644 --- a/Packages/com.unity.inputsystem/Documentation~/how-interactions-work.md +++ b/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md @@ -1,3 +1,11 @@ +# Introduction to interactions + +An Interaction represents a specific input pattern. For example, a [hold](#hold) is an Interaction that requires a Control to be held for a minimum amount of time. + +Interactions drive responses on Actions. You can place them on individual Bindings or an Action as a whole, in which case they apply to every Binding on the Action. At runtime, when a particular interaction completes, this triggers the Action. + +![Interaction Properties](Images/InteractionProperties.png) + ## How interactions work An Interaction has a set of distinct phases it can go through in response to receiving input. @@ -5,7 +13,7 @@ An Interaction has a set of distinct phases it can go through in response to rec |Phase|Description| |-----|-----------| |`Waiting`|The Interaction is waiting for input.| -|`Started`|The Interaction has been started (that is, it received some of its expected input), but is not complete yet.| +|`Started`|The Interaction has started (that is, it received some of its expected input), but is not complete yet.| |`Performed`|The Interaction is complete.| |`Canceled`|The Interaction was interrupted and aborted. For example, the user pressed and then released a button before the minimum time required for a [hold Interaction](#hold) to complete.| @@ -42,11 +50,11 @@ fireAction.canceled += fireAction.Enable(); ``` -### Multiple Controls on an Action +## Multiple Controls on an Action If you have multiple Controls bound to a Binding or an Action which has an Interaction, then the Input System first applies the [Control conflict resolution](ActionBindings.md#conflicting-inputs) logic to get a single value for the Action, which it then feeds to the Interaction logic. Any of the bound Controls can perform the Interaction. -### Multiple Interactions on a Binding +## Multiple Interactions on a Binding If multiple Interactions are present on a single Binding or Action, then the Input System checks the Interactions in the order they are present on the Binding. The code example [above](#operation) illustrates this example. The Binding on the `fireAction` Action has two Interactions: `WithInteractions("tap;slowTap")`. The [tap](#tap) Interaction gets a first chance at interpreting the input from the Action. If the button is pressed, the Action calls the `Started` callback on the tap Interaction. If the user keeps holding the button, the tap Interaction times out, and the Action calls the [`Canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled) callback for the tap Interaction and starts processing the [slow tap](#slowtap) Interaction (which now receives a `Started` callback). @@ -54,7 +62,7 @@ At any one time, only one Interaction can be "driving" the action (that is, it g Note that the order of interactions can affect which interaction is passed to your callback function. For example, an action with [Tap](#tap), [MultiTap](#multitap) and [Hold](#hold) interactions will have different behaviour when the interactions are in a different order, such as [Hold](#hold), [MultiTap](#multitap) and [Tap](#tap). If you get unexpected behaviour, you may need to experiment with a different ordering. -### Timeouts +## Timeouts Interactions might need to wait a certain time for a specific input to occur or to not occur. An example of this is the [Hold](#hold) interaction which, after a button is pressed, has to wait for a set [duration](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration) until the "hold" is complete. To do this, an interaction installs a timeout using [`SetTimeout`](../api/UnityEngine.InputSystem.InputInteractionContext.html#UnityEngine_InputSystem_InputInteractionContext_SetTimeout_System_Single_). diff --git a/Packages/com.unity.inputsystem/Documentation~/predefined-interactions.md b/Packages/com.unity.inputsystem/Documentation~/predefined-interactions.md index 386907185e..6d6330df3b 100644 --- a/Packages/com.unity.inputsystem/Documentation~/predefined-interactions.md +++ b/Packages/com.unity.inputsystem/Documentation~/predefined-interactions.md @@ -1,124 +1,9 @@ -## Predefined Interactions +# Predefined Interactions -The Input System package comes with a set of basic Interactions you can use. If an Action has no Interactions set, the system uses its [default Interaction](#default-interaction). +The Input System provides a set of default Interactions for each Action type, and a set of basic built-in Interactions that you can use to get started. ->__Note__: The built-in Interactions operate on Control actuation and don't use Control values directly. The Input System evaluates the `pressPoint` parameters against the magnitude of the Control actuation. This means you can use these Interactions on any Control which has a magnitude, such as sticks, and not just on buttons. - -The following diagram shows the behavior of the built-in Interactions for a simple button press. - -![Interaction Diagram](./Images/InteractionsDiagram.png) - -### Default Interaction - -If you haven't specifically added an Interaction to a Binding or its Action, the default Interaction applies to the Binding. - -[`Value`](RespondingToActions.md#value) type Actions have the following behavior: - -1. As soon as a bound Control becomes [actuated](Controls.md#control-actuation), the Action goes from `Waiting` to `Started`, and then immediately to `Performed` and back to `Started`. One callback occurs on [`InputAction.started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started), followed by one callback on [`InputAction.performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed). -2. For as long as the bound Control remains actuated, the Action stays in `Started` and triggers `Performed` whenever the value of the Control changes (that is, one call occurs to [`InputAction.performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)). -3. When the bound Control stops being actuated, the Action goes to `Canceled` and then back to `Waiting`. One call occurs to [`InputAction.canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled). - -[`Button`](RespondingToActions.md#button) type Actions have the following behavior: - -1. As soon as a bound Control becomes [actuated](Controls.md#control-actuation), the Action goes from `Waiting` to `Started`. One callback occurs on [`InputAction.started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started). -2. If a Control then reaches or exceeds the button press threshold, the Action goes from `Started` to `Performed`. One callback occurs on [`InputAction.performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed). The default value of the button press threshold is defined in the [input settings](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint). However, an individual control can [override](../api/UnityEngine.InputSystem.Controls.ButtonControl.html#UnityEngine_InputSystem_Controls_ButtonControl_pressPoint) this value. -3. Once the Action has `Performed`, if all Controls then go back to a level of actuation at or below the [release threshold](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_buttonReleaseThreshold), the Action goes from `Performed` to `Canceled`. One call occurs to [`InputAction.canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled). -4. If the Action never went to `Performed`, it will go to `Canceled` as soon as all Controls are released. One call occurs to [`InputAction.canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled). - -[`PassThrough`](RespondingToActions.md#pass-through) type Actions have a simpler behavior. The Input System doesn't try to track bound Controls as a single source of input. Instead, it triggers a `Performed` callback for each value change. - -|__Callback__|[`InputActionType.Value`](RespondingToActions.md#value)|[`InputActionType.Button`](RespondingToActions.md#button)|[`InputActionType.PassThrough`](RespondingToActions.md#pass-through)| -|-----------|-------------|------------|-----------------| -|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control(s) changed value away from the default value.|Button started being pressed but has not necessarily crossed the press threshold yet.|not used| -|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control(s) changed value.|Button was pressed to at least the button [press threshold](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint).|Control changed value.| -|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control(s) are no longer actuated.|Button was released. If the button was pressed above the press threshold, the button has now fallen to or below the [release threshold](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_buttonReleaseThreshold). If the button was never fully pressed, the button is now back to completely unpressed.|Action is disabled.| - -### Press - -You can use a [`PressInteraction`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html) to explicitly force button-like interactions. Use the [`behavior`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_behavior) parameter to select if the Interaction should trigger on button press, release, or both. - -|__Parameters__|Type|Default value| -|---|---|---| -|[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| -|[`behavior`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_behavior)|[`PressBehavior`](../api/UnityEngine.InputSystem.Interactions.PressBehavior.html)|`PressOnly`| - - -|__Callbacks__/[`behavior`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_behavior)|`PressOnly`|`ReleaseOnly`|`PressAndRelease`| -|---|-----------|-------------|-----------------| -|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)| -|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|- Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)
or
- Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)| -|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|not used|not used|not used| - -### Hold - -A [`HoldInteraction`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html) requires the user to hold a Control for [`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration) seconds before the Input System triggers the Action. - -|__Parameters__|Type|Default value| -|---|---|---| -|[`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration)|`float`|[`InputSettings.defaultHoldTime`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultHoldTime)| -|[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| - - -To display UI feedback when a button starts being held, use the [`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started) callback. - -```C# - - action.started += _ => ShowGunChargeUI(); - action.performed += _ => FinishGunChargingAndHideChargeUI(); - action.cancelled += _ => HideChargeUI(); - -``` - -|__Callbacks__|| -|---|---| -|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_pressPoint).| -|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude held above [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_pressPoint) for >= [`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration).| -|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_pressPoint) before [`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration) (that is, the button was not held long enough).| - -### Tap - -A [`TapInteraction`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html) requires the user to press and release a Control within [`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration) seconds to trigger the Action. - -|__Parameters__|Type|Default value| -|---|---|---| -|[`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration)|`float`|[`InputSettings.defaultTapTime`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultTapTime)| -|[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| - -|__Callbacks__|| -|---|---| -|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_pressPoint).| -|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_pressPoint) before [`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration).| -|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control magnitude held above [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_pressPoint) for >= [`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration) (that is, the tap was too slow).| - -### SlowTap - -A [`SlowTapInteraction`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html) requires the user to press and hold a Control for a minimum duration of [`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration) seconds, and then release it, to trigger the Action. - -|__Parameters__|Type|Default value| -|---|---|---| -|[`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration)|`float`|[`InputSettings.defaultSlowTapTime`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultSlowTapTime)| -|[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| - -|__Callbacks__|| -|---|---| -|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_pressPoint).| -|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_pressPoint) after [`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration).| -|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_pressPoint) before [`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration) (that is, the tap was too fast).| - -### MultiTap - -A [`MultiTapInteraction`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html) requires the user to press and release a Control within [`tapTime`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapTime) seconds [`tapCount`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapCount) times, with no more then [`tapDelay`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapDelay) seconds passing between taps, for the Interaction to trigger. You can use this to detect double-click or multi-click gestures. - -|__Parameters__|Type|Default value| -|---|---|---| -|[`tapTime`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapTime)|`float`|[`InputSettings.defaultTapTime`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultTapTime)| -|[`tapDelay`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapDelay)|`float`|2 * [`tapTime`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapTime)| -|[`tapCount`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapCount)|`int`|2| -|[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| - -|__Callbacks__|| -|---|---| -|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint).| -|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude went back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint) and back up above it repeatedly for [`tapCount`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapCount) times.| -|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|- After going back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint), Control magnitude did not go back above [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint) within [`tapDelay`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapDelay) time (that is, taps were spaced out too far apart).
or
- After going back above [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint), Control magnitude did not go back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_pressPoint) within [`tapTime`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapTime) time (that is, taps were too long).| +|Topic|Description| +|-----|-----------| +|[Default Interactions](default-interactions.md)| Use the default Interaction configuration for Value-type Actions, Button-type Actions, and PassThrough-type Actions. | +|[Built-in Interactions](built-in-interactions.md)| Use the Input System's built-in Interactions for Actions and Bindings. | \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/Documentation~/using-interactions.md b/Packages/com.unity.inputsystem/Documentation~/using-interactions.md deleted file mode 100644 index 9fb45e615c..0000000000 --- a/Packages/com.unity.inputsystem/Documentation~/using-interactions.md +++ /dev/null @@ -1,35 +0,0 @@ -# Using Interactions - -You can install Interactions on [Bindings](ActionBindings.md) or [Actions](actions.md). - -### Interactions applied to Bindings - -When you create Bindings for your [Actions](actions.md), you can choose to add Interactions to the Bindings. - -If you're using [project-wide actions](ActionsEditor.md), or [Input Action Assets](ActionAssets.md), you can add any Interaction to your Bindings in the Input Action editor. Once you [created some Bindings](ActionsEditor.md#bindings), select the Binding you want to add Interactions to, so that the right pane of the window shows the properties for that Binding. Next, click on the plus icon on the __Interactions__ foldout to open a list of all available Interactions types. Choose an Interaction type to add an Interaction instance of that type. The Interaction now appears in the __Interactions__ foldout. If the Interaction has any parameters, you can now edit them here as well: - -![Binding Processors](Images/BindingProcessors.png) - -To remove an Interaction, click the minus button next to it. To change the [order of Interactions](#multiple-interactions-on-a-binding), click the up and down arrows. - -If you create your Bindings in code, you can add Interactions like this: - -```CSharp -var Action = new InputAction(); -action.AddBinding("/leftStick") - .WithInteractions("tap(duration=0.8)"); -``` - -### Interactions applied to Actions - -Applying Interactions directly to an Action is equivalent to applying them to all Bindings for the Action. It is thus more or less a shortcut that avoids manually adding the same Interaction(s) to each of the Bindings. - -If Interactions are applied __both__ to an Action and to its Bindings, then the effect is the same as if the Action's Interactions are *appended* to the list of Interactions on each of the Bindings. This means that the Binding's Interactions are applied *first*, and then the Action's Interactions are applied *after*. - -You can add and edit Interactions on Actions in the [Input Action Assets](ActionAssets.md) editor window the [same way](#interactions-applied-to-bindings) as you would do for Bindings: select an Action to Edit, then add the Interactions in the right window pane. - -If you create your Actions in code, you can add Interactions like this: - -```CSharp -var Action = new InputAction(Interactions: "tap(duration=0.8)"); -``` \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md b/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md index 2d1411b584..81ac0fa10e 100644 --- a/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md +++ b/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md @@ -1,11 +1,15 @@ # Write custom Interactions -You can also write a custom Interaction to use in your Project. You can use custom Interactions in the UI and code the same way you use built-in Interactions. Add a class implementing the [`IInputInteraction`](../api/UnityEngine.InputSystem.IInputInteraction.html) interface, like this: +You can write a custom Interaction and use it the same way you use built-in Interactions. + +To write a custom Interaction: + +**1.** Add a class that implements the [`IInputInteraction`](../api/UnityEngine.InputSystem.IInputInteraction.html) interface. For example: ```CSharp // Interaction which performs when you quickly move an // axis all the way from extreme to the other. -public class MyWiggleInteraction : IInputInteraction +public class MyExampleInteraction : IInputInteraction { public float duration = 0.2; @@ -44,14 +48,16 @@ public class MyWiggleInteraction : IInputInteraction } ``` -Now, you need to tell the Input System about your Interaction. Call this method in your initialization code: +**2.** Add your Interaction to the Input System. Call the following method in your initialization code: ```CSharp -InputSystem.RegisterInteraction(); +InputSystem.RegisterInteraction(); ``` -Your new Interaction is now available in the [Input Action Asset Editor window](ActionAssets.md). You can also add it in code like this: +Your new Interaction is now available in the [Input Action Asset Editor window](ActionAssets.md). + +Alternatively, you can add it this way: ```CSharp -var Action = new InputAction(Interactions: "MyWiggle(duration=0.5)"); +var Action = new InputAction(Interactions: "MyExample(duration=0.5)"); ``` From 6981b0cb9f70610a6734f5f63e135697665ba4cc Mon Sep 17 00:00:00 2001 From: Siobhan Date: Thu, 30 Jan 2025 09:33:06 +0000 Subject: [PATCH 2/7] Update TableOfContents.md --- .../Documentation~/TableOfContents.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Packages/com.unity.inputsystem/Documentation~/TableOfContents.md b/Packages/com.unity.inputsystem/Documentation~/TableOfContents.md index 4af1bb1d6f..0d21e0dad1 100644 --- a/Packages/com.unity.inputsystem/Documentation~/TableOfContents.md +++ b/Packages/com.unity.inputsystem/Documentation~/TableOfContents.md @@ -42,6 +42,13 @@ * [Input Action Assets](ActionAssets.md) * [Input Bindings](ActionBindings.md) * [Interactions](Interactions.md) + * [Introduction to interactions](introduction-interactions.md) + * [Apply interactions to Bindings](using-interactions.md) + * [Apply Interactions to Actions](using-interactions.md) + * [Predefined interactions](predefined-interactions.md) + * [Default Interactions](default-interactions.md) + * [Built-in Interactions](built-in-interactions.md) + * [Write custom interactions](write-custom-interactions.md) * [Devices](Devices.md) * [Controls](Controls.md) * [Processors](Processors.md) From db51091ee3f288c573196eb8c452d7652f38e15d Mon Sep 17 00:00:00 2001 From: Siobhan Date: Thu, 30 Jan 2025 10:10:05 +0000 Subject: [PATCH 3/7] Fixed broken links --- Packages/com.unity.inputsystem/Documentation~/Interactions.md | 4 ++-- .../com.unity.inputsystem/Documentation~/TableOfContents.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Packages/com.unity.inputsystem/Documentation~/Interactions.md b/Packages/com.unity.inputsystem/Documentation~/Interactions.md index d20c521158..6eb3f536a7 100644 --- a/Packages/com.unity.inputsystem/Documentation~/Interactions.md +++ b/Packages/com.unity.inputsystem/Documentation~/Interactions.md @@ -8,7 +8,7 @@ Use Interactions to interpret specific input patterns from Controls that define |Topic|Description| |-----|-----------| |[Introduction to interactions](introduction-interactions.md)| Use Interactions on Bindings and Actions to read control input patterns and trigger Actions.| -|[Apply interactions to Bindings](using-interactions.md)| Apply Interactions to individual Bindings.| -|[Apply Interactions to Actions](using-interactions.md)| Apply Interactions to Actions, and all the Bindings associated with that Action. | +|[Apply interactions to Bindings](apply-interactions-bindings.md)| Apply Interactions to individual Bindings.| +|[Apply Interactions to Actions](apply-interactions-actions.md)| Apply Interactions to Actions, and all the Bindings associated with that Action. | |[Predefined interactions](predefined-interactions.md)| Use the Input System's default and built-in Interactions on your Actions and Bindings.| |[Write custom interactions](write-custom-interactions.md)| Write your own custom Interactions for your Actions and Bindings.| \ No newline at end of file diff --git a/Packages/com.unity.inputsystem/Documentation~/TableOfContents.md b/Packages/com.unity.inputsystem/Documentation~/TableOfContents.md index 0d21e0dad1..2497ed68a5 100644 --- a/Packages/com.unity.inputsystem/Documentation~/TableOfContents.md +++ b/Packages/com.unity.inputsystem/Documentation~/TableOfContents.md @@ -43,8 +43,8 @@ * [Input Bindings](ActionBindings.md) * [Interactions](Interactions.md) * [Introduction to interactions](introduction-interactions.md) - * [Apply interactions to Bindings](using-interactions.md) - * [Apply Interactions to Actions](using-interactions.md) + * [Apply interactions to Bindings](apply-interactions-bindings.md) + * [Apply Interactions to Actions](apply-interactions-actions.md) * [Predefined interactions](predefined-interactions.md) * [Default Interactions](default-interactions.md) * [Built-in Interactions](built-in-interactions.md) From 0c15584be3a8e461e97ec08d316ab14457dfc5f1 Mon Sep 17 00:00:00 2001 From: Siobhan Date: Thu, 30 Jan 2025 10:22:39 +0000 Subject: [PATCH 4/7] Fixed broken links and headings --- .../Documentation~/apply-interactions-actions.md | 2 +- .../Documentation~/apply-interactions-bindings.md | 4 ++-- .../Documentation~/built-in-interactions.md | 12 ++++++------ .../Documentation~/introduction-interactions.md | 14 +++++++------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md index 411a72b2c5..c9720b6744 100644 --- a/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md +++ b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md @@ -2,7 +2,7 @@ Applying Interactions directly to an Action is equivalent to applying them to all Bindings for the Action. You can use this instead of manually adding the same Interaction(s) to multiple Bindings. -To apply Interactions to individual Bindings, refer to [Apply Interactions to Bindings](apply-interactions-bindings). +To apply Interactions to individual Bindings, refer to [Apply Interactions to Bindings](apply-interactions-bindings.md). If you apply Interactions to both an Action and its Bindings, then the effect is the same as if the Action's Interactions are on the list of Interactions on each of the Bindings. This means that the Input System applies the Binding's Interactions first, and then the Action's Interactions. diff --git a/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md index 0248fd37c7..ec669ee685 100644 --- a/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md +++ b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md @@ -2,7 +2,7 @@ When you create Bindings for your [Actions](actions.md), you can choose to add Interactions to the Bindings via the Editor, or via code. -To apply Interactions to all Bindings on an Action, refer to [Apply Interactions to Actions](apply-interactions-sctions). +To apply Interactions to all Bindings on an Action, refer to [Apply Interactions to Actions](apply-interactions-actions.md). ## Apply Interactions to Bindings via the Editor @@ -15,7 +15,7 @@ If you're using [project-wide actions](ActionsEditor.md), or [Input Action Asset ![Binding Processors](Images/BindingProcessors.png) -To remove an Interaction, select the minus (-) button next to it. To change the [order of Interactions](#multiple-interactions-on-a-binding), select the up and down arrows. +To remove an Interaction, select the minus (-) button next to it. To change the [order of Interactions](introduction-interactions.md#multiple-interactions-on-a-binding), select the up and down arrows. ## Apply Interactions to Bindings via code diff --git a/Packages/com.unity.inputsystem/Documentation~/built-in-interactions.md b/Packages/com.unity.inputsystem/Documentation~/built-in-interactions.md index 9c3f750d50..d8630dcd33 100644 --- a/Packages/com.unity.inputsystem/Documentation~/built-in-interactions.md +++ b/Packages/com.unity.inputsystem/Documentation~/built-in-interactions.md @@ -15,14 +15,14 @@ Each built-in Interaction has its own parameters, and responds differently to In If an Action or Binding has no Interaction set, the system uses its [default Interaction](default-interactions.md). -## Built-in Press Interaction +## Press You can use a [`PressInteraction`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html) to explicitly force button-like interactions. Use the [`behavior`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_behavior) parameter to select if the Interaction should trigger on button press, release, or both. |__Parameters__|Type|Default value| |---|---|---| |[`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|`float`|[`InputSettings.defaultButtonPressPoint`](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint)| -|[`behavior`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_behavior)|[`PressBehavior`](../api/UnityEngine.InputSystem.Interactions.PressBehavior.html)|`PressOnly`| +|[`behavior`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_behavior)|[`PressBehavior`](../api/UnityEngine.InputSystem.Interactions.PressBehavior.html)|`PressOnly`| |__Callbacks__/[`behavior`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_behavior)|`PressOnly`|`ReleaseOnly`|`PressAndRelease`| @@ -31,7 +31,7 @@ You can use a [`PressInteraction`](../api/UnityEngine.InputSystem.Interactions.P |[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)|- Control magnitude crosses [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)
or
- Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.PressInteraction.html#UnityEngine_InputSystem_Interactions_PressInteraction_pressPoint)| |[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|not used|not used|not used| -## Built-in Hold Interaction +## Hold A [`HoldInteraction`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html) requires the user to hold a Control for [`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration) seconds before the Input System triggers the Action. @@ -57,7 +57,7 @@ To display UI feedback when a button starts being held, use the [`started`](../a |[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude held above [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_pressPoint) for >= [`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration).| |[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_pressPoint) before [`duration`](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration) (that is, the button was not held long enough).| -## Built-in Tap Interaction +## Tap A [`TapInteraction`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html) requires the user to press and release a Control within [`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration) seconds to trigger the Action. @@ -72,7 +72,7 @@ A [`TapInteraction`](../api/UnityEngine.InputSystem.Interactions.TapInteraction. |[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_pressPoint) before [`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration).| |[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control magnitude held above [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_pressPoint) for >= [`duration`](../api/UnityEngine.InputSystem.Interactions.TapInteraction.html#UnityEngine_InputSystem_Interactions_TapInteraction_duration) (that is, the tap was too slow).| -## Built-in SlowTap Interaction +## SlowTap A [`SlowTapInteraction`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html) requires the user to press and hold a Control for a minimum duration of [`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration) seconds, and then release it, to trigger the Action. @@ -87,7 +87,7 @@ A [`SlowTapInteraction`](../api/UnityEngine.InputSystem.Interactions.SlowTapInte |[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_pressPoint) after [`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration).| |[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control magnitude goes back below [`pressPoint`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_pressPoint) before [`duration`](../api/UnityEngine.InputSystem.Interactions.SlowTapInteraction.html#UnityEngine_InputSystem_Interactions_SlowTapInteraction_duration) (that is, the tap was too fast).| -## Built-in MultiTap Interaction +## MultiTap A [`MultiTapInteraction`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html) requires the user to press and release a Control within [`tapTime`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapTime) seconds [`tapCount`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapCount) times, with no more then [`tapDelay`](../api/UnityEngine.InputSystem.Interactions.MultiTapInteraction.html#UnityEngine_InputSystem_Interactions_MultiTapInteraction_tapDelay) seconds passing between taps, for the Interaction to trigger. You can use this to detect double-click or multi-click gestures. diff --git a/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md b/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md index 180795c67b..069ed26e0e 100644 --- a/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md +++ b/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md @@ -1,8 +1,8 @@ # Introduction to interactions -An Interaction represents a specific input pattern. For example, a [hold](#hold) is an Interaction that requires a Control to be held for a minimum amount of time. +An Interaction represents a specific input pattern. For example, a [hold](built-in-interactions.md#hold) Interaction is an Interaction that requires a Control to be held for a minimum amount of time. -Interactions drive responses on Actions. You can place them on individual Bindings or an Action as a whole, in which case they apply to every Binding on the Action. At runtime, when a particular interaction completes, this triggers the Action. +Interactions trigger responses on Actions. You can place them on individual Bindings, or on Actions, in which case they apply to every Binding on the Action. At runtime, when a particular interaction completes, this triggers the Action. ![Interaction Properties](Images/InteractionProperties.png) @@ -15,11 +15,11 @@ An Interaction has a set of distinct phases it can go through in response to rec |`Waiting`|The Interaction is waiting for input.| |`Started`|The Interaction has started (that is, it received some of its expected input), but is not complete yet.| |`Performed`|The Interaction is complete.| -|`Canceled`|The Interaction was interrupted and aborted. For example, the user pressed and then released a button before the minimum time required for a [hold Interaction](#hold) to complete.| +|`Canceled`|The Interaction was interrupted and aborted. For example, the user pressed and then released a button before the minimum time required for a Hold Interaction to complete.| Not every Interaction triggers every phase, and the pattern in which specific Interactions trigger phases depends on the Interaction type. -While `Performed` is typically the phase that triggers the actual response to an Interaction, `Started` and `Canceled` can be useful for providing UI feedback while the Interaction is in progress. For example, when a [hold](#hold) is `Started`, the app can display a progress bar that fills up until the hold time has been reached. If, however, the hold is `Canceled` before it completes, the app can reset the progress bar to the beginning. +While `Performed` is typically the phase that triggers the actual response to an Interaction, `Started` and `Canceled` can be useful for providing UI feedback while the Interaction is in progress. For example, when a [hold](built-in-interactions.md#hold) is `Started`, the app can display a progress bar that fills up until the hold time has been reached. If, however, the hold is `Canceled` before it completes, the app can reset the progress bar to the beginning. The following example demonstrates this kind of setup with a fire Action that the user can tap to fire immediately, or hold to charge: @@ -56,15 +56,15 @@ If you have multiple Controls bound to a Binding or an Action which has an Inter ## Multiple Interactions on a Binding -If multiple Interactions are present on a single Binding or Action, then the Input System checks the Interactions in the order they are present on the Binding. The code example [above](#operation) illustrates this example. The Binding on the `fireAction` Action has two Interactions: `WithInteractions("tap;slowTap")`. The [tap](#tap) Interaction gets a first chance at interpreting the input from the Action. If the button is pressed, the Action calls the `Started` callback on the tap Interaction. If the user keeps holding the button, the tap Interaction times out, and the Action calls the [`Canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled) callback for the tap Interaction and starts processing the [slow tap](#slowtap) Interaction (which now receives a `Started` callback). +If multiple Interactions are present on a single Binding or Action, then the Input System checks the Interactions in the order they are present on the Binding. The code example above illustrates this example. The Binding on the `fireAction` Action has two Interactions: `WithInteractions("tap;slowTap")`. The [tap](built-in-interactions.md#tap) Interaction gets a first chance at interpreting the input from the Action. If the button is pressed, the Action calls the `Started` callback on the tap Interaction. If the user keeps holding the button, the tap Interaction times out, and the Action calls the [`Canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled) callback for the tap Interaction and starts processing the [slow tap](built-in-interactions.md#slowtap) Interaction (which now receives a `Started` callback). At any one time, only one Interaction can be "driving" the action (that is, it gets to determine the action's current [`phase`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_phase)). If an Interaction higher up in the stack cancels, Interactions lower down in the stack can take over. -Note that the order of interactions can affect which interaction is passed to your callback function. For example, an action with [Tap](#tap), [MultiTap](#multitap) and [Hold](#hold) interactions will have different behaviour when the interactions are in a different order, such as [Hold](#hold), [MultiTap](#multitap) and [Tap](#tap). If you get unexpected behaviour, you may need to experiment with a different ordering. +Note that the order of interactions can affect which interaction is passed to your callback function. For example, an action with [Tap](built-in-interactions.md#tap), [MultiTap](built-in-interactions.md#multitap) and [Hold](built-in-interactions.md#hold) interactions will have different behaviour when the interactions are in a different order, such as [Hold](built-in-interactions.md#hold), [MultiTap](built-in-interactions.md#multitap) and [Tap](built-in-interactions.md#tap). If you get unexpected behaviour, you may need to experiment with a different ordering. ## Timeouts -Interactions might need to wait a certain time for a specific input to occur or to not occur. An example of this is the [Hold](#hold) interaction which, after a button is pressed, has to wait for a set [duration](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration) until the "hold" is complete. To do this, an interaction installs a timeout using [`SetTimeout`](../api/UnityEngine.InputSystem.InputInteractionContext.html#UnityEngine_InputSystem_InputInteractionContext_SetTimeout_System_Single_). +Interactions might need to wait a certain time for a specific input to occur or to not occur. An example of this is the [Hold](built-in-interactions.md#hold) interaction which, after a button is pressed, has to wait for a set [duration](../api/UnityEngine.InputSystem.Interactions.HoldInteraction.html#UnityEngine_InputSystem_Interactions_HoldInteraction_duration) until the "hold" is complete. To do this, an interaction installs a timeout using [`SetTimeout`](../api/UnityEngine.InputSystem.InputInteractionContext.html#UnityEngine_InputSystem_InputInteractionContext_SetTimeout_System_Single_). It can be useful to know how much of a timeout is left for an interaction to complete. For example, you might want to display a bar in the UI that is charging up while the interaction is waiting to complete. To query the percentage to which a timeout has completed, use [`GetTimeoutCompletionPercentage`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_GetTimeoutCompletionPercentage_). From e927377c5948915dd65c765d66c9bba655996a73 Mon Sep 17 00:00:00 2001 From: Ben Pitt Date: Thu, 30 Jan 2025 11:41:04 +0000 Subject: [PATCH 5/7] Fixed interaction code example --- .../introduction-interactions.md | 61 ++++++++++++------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md b/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md index 069ed26e0e..2266d2a2af 100644 --- a/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md +++ b/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md @@ -21,33 +21,50 @@ Not every Interaction triggers every phase, and the pattern in which specific In While `Performed` is typically the phase that triggers the actual response to an Interaction, `Started` and `Canceled` can be useful for providing UI feedback while the Interaction is in progress. For example, when a [hold](built-in-interactions.md#hold) is `Started`, the app can display a progress bar that fills up until the hold time has been reached. If, however, the hold is `Canceled` before it completes, the app can reset the progress bar to the beginning. -The following example demonstrates this kind of setup with a fire Action that the user can tap to fire immediately, or hold to charge: + +The following example demonstrates this using a [Slow Tap interaction](./built-in-interactions.md#slowtap) on a `Jump` action so that the user can tap to jump immediately, or hold down the jump button to charge up a higher powered jump, displaying a UI to show the amount charged: ```CSharp -var fireAction = new InputAction("fire"); -fireAction.AddBinding("/buttonSouth") - // Tap fires, slow tap charges. Both act on release. - .WithInteractions("tap,slowTap"); +using UnityEngine; +using UnityEngine.InputSystem; +using UnityEngine.InputSystem.Interactions; -fireAction.started += - context => - { - if (context.interaction is SlowTapInteraction) - ShowChargingUI(); - }; +public class ExampleScript : MonoBehaviour +{ + InputAction jumpAction; -fireAction.performed += - context => + private void Start() { - if (context.interaction is SlowTapInteraction) - ChargedFire(); - else - Fire(); - }; - -fireAction.canceled += - _ => HideChargingUI(); -fireAction.Enable(); + jumpAction = InputSystem.actions.FindAction("Jump"); + + + jumpAction.started += context => + { + if (context.interaction is SlowTapInteraction) + { + // Show "charging" UI + } + }; + + jumpAction.performed += context => + { + if (context.interaction is SlowTapInteraction) + { + // call "charged jump" code + } + else + { + // call "regular jump" code + }; + }; + + jumpAction.canceled += context => + { + // Hide "charging" UI + }; + + } +} ``` ## Multiple Controls on an Action From ad8d41319a637bdc831eb722d21bad8afb43b741 Mon Sep 17 00:00:00 2001 From: Ben Pitt Date: Thu, 30 Jan 2025 11:46:02 +0000 Subject: [PATCH 6/7] changed "mutates" to "changes" --- .../Documentation~/write-custom-interactions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md b/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md index 81ac0fa10e..90eec79ca7 100644 --- a/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md +++ b/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md @@ -39,7 +39,7 @@ public class MyExampleInteraction : IInputInteraction } // Unlike processors, Interactions can be stateful, meaning that you can keep a - // local state that mutates over time as input is received. The system might + // local state that changes over time as input is received. The system might // invoke the Reset() method to ask Interactions to reset to the local state // at certain points. void Reset() From d335941491b61c6a012663ba30f493d9236f76f5 Mon Sep 17 00:00:00 2001 From: Siobhan Fitzgerald-Gibson <52451117+siobhan-unity@users.noreply.github.com> Date: Thu, 30 Jan 2025 15:05:32 +0000 Subject: [PATCH 7/7] Update Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md Co-authored-by: Ben Pitt --- .../Documentation~/introduction-interactions.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md b/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md index 2266d2a2af..c362abb631 100644 --- a/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md +++ b/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md @@ -1,6 +1,10 @@ # Introduction to interactions -An Interaction represents a specific input pattern. For example, a [hold](built-in-interactions.md#hold) Interaction is an Interaction that requires a Control to be held for a minimum amount of time. +An Interaction represents a specific pattern of [control actuation](control-actuation.md) that determines how an action is started, performed, or canceled. + +An action with no explicit interaction applied behaves according the [default interaction](default-interactions.md) for its [action type](about-action-control-types.md). For example, a button action's default interaction is to immediately perform the action when the button is pressed. + +When you apply an interaction to an action, it overrides the default interaction behavior and changes how the action is performed. This allows you, for example, to implement a [hold](built-in-interactions.md#hold) interaction that requires a control to be held for a minimum amount of time, or a [multi-tap](built-in-interactions.md#multitap) interaction that requires the control to be quickly tapped multiple times to perform the action. Interactions trigger responses on Actions. You can place them on individual Bindings, or on Actions, in which case they apply to every Binding on the Action. At runtime, when a particular interaction completes, this triggers the Action.