Skip to content

Commit 967a251

Browse files
author
Rene Damm
authored
DOCS: Misc changes (#1396).
1 parent 27ae3b1 commit 967a251

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

Packages/com.unity.inputsystem/Documentation~/Events.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
* [Reading state events](#reading-state-events)
1010
* [Creating events](#creating-events)
1111
* [Capturing events](#capturing-events)
12-
* [Merging of events](#merging-of-events)
12+
* [Processing events](#processing-events)
13+
* [Merging of events](#merging-of-events)
1314

1415
The Input System is event-driven. All input is delivered as events, and you can generate custom input by injecting events. You can also observe all source input by listening in on the events flowing through the system.
1516

@@ -233,7 +234,27 @@ controller.PlayAllFramesOnyByOne();
233234
controller.PlayAllEventsAccordingToTimestamps();
234235
```
235236

236-
## Merging of events
237+
## Processing events
238+
239+
[Events](../api/UnityEngine.InputSystem.LowLevel.InputEvent.html) are collected on a queue by the Unity runtime. This queue is regularly flushed out and the events on it processed. Events can be added to the queue manually by calling [`InputSystem.QueueEvent`](../api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_QueueEvent_UnityEngine_InputSystem_LowLevel_InputEventPtr_).
240+
241+
Each time input is processed, [`InputSystem.Update`](../api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_Update_) is called implicitly by the Unity runtime.
242+
243+
The interval at which this happens is determined by the ["Update Mode"](Settings.md#update-mode) configured in the settings. By default, input is processed in each frame __before__ <c>MonoBehaviour.Update</c> methods are called. If the setting is changed to process input in fixed updates, then this changes to input being processed each time before <c>MonoBehaviour.FixedUpdate</c> methods are called.
244+
245+
Normally, when input is processed, __all__ outstanding input events on the queue will be consumed. There are two exceptions to this, however.
246+
247+
When using [`UpdateMode.ProcessEventsInFixedUpdate`](../api/UnityEngine.InputSystem.InputSettings.UpdateMode.html#UnityEngine_InputSystem_InputSettings_UpdateMode_ProcessEventsInFixedUpdate), the Input System attempts to associate events with the timeslice of the corresponding <c>FixedUpdate</c>. This is based on the [timestamps](../api/UnityEngine.InputSystem.LowLevel.InputEvent.html#UnityEngine_InputSystem_LowLevel_InputEvent_time) of the events and a "best effort" at calculating the corresponding timeslice of the current <c>FixedUpdated</c>.
248+
249+
The other exception are [`BeforeRender`](../api/UnityEngine.InputSystem.LowLevel.InputUpdateType.html#UnityEngine_InputSystem_LowLevel_InputUpdateType_BeforeRender) updates. These updates are run after fixed or dynamic updates but before rendering and used used exclusively to update devices such as VR headsets that need the most up-to-date tracking data. Other input is not consumed from such updates and these updates are only enabled if such devices are actually present. `BeforeRender` updates are not considered separate frames as far as input is concerned.
250+
251+
>__Note__: Manually calling [`InputSystem.Update`](../api/UnityEngine.InputSystem.InputSystem.html#UnityEngine_InputSystem_InputSystem_Update_) is strongly advised against except within tests employing [`InputTestFixture`](../api/UnityEngine.InputSystem.InputTestFixture.html) or when explicitly setting the system to [manual update mode](../api/UnityEngine.InputSystem.InputSettings.UpdateMode.html#UnityEngine_InputSystem_InputSettings_UpdateMode_ProcessEventsManually).
252+
253+
Methods such as [`InputAction.WasPerformedThisFrame`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasPerformedThisFrame) and [`InputAction.WasPerformedThisFrame`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasPerformedThisFrame) operate implicitly based on the [`InputSystem.Update`] cadence described above. Meaning, that they refer to the state as per the __last__ fixed/dynamic/manual update happened.
254+
255+
You can query the [current/last update type](../api/UnityEngine.InputSystem.LowLevel.InputState.html#UnityEngine_InputSystem_LowLevel_InputState_currentUpdateType) and [count](../api/UnityEngine.InputSystem.LowLevel.InputState.html#UnityEngine_InputSystem_LowLevel_InputState_updateCount) from [`InputState`](../api/UnityEngine.InputSystem.LowLevel.InputState.html).
256+
257+
### Merging of events
237258

238259
Input system uses event mering to reduce amount of events required to be processed.
239260
This greatly improves performance when working with high refresh rate devices like 8000 Hz mice, touchscreens and others.

Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ public ReadOnlyArray<InputControl> controls
507507
/// </remarks>
508508
public InputActionPhase phase => currentState.phase;
509509

510+
/// <summary>
511+
/// True if the action is currently in <see cref="InputActionPhase.Started"/> or <see cref="InputActionPhase.Performed"/>
512+
/// phase. False in all other cases.
513+
/// </summary>
514+
/// <see cref="phase"/>
510515
public bool inProgress => phase.IsInProgress();
511516

512517
/// <summary>
@@ -1121,6 +1126,9 @@ public unsafe bool IsPressed()
11211126
///
11221127
/// This method will disregard whether the action is currently enabled or disabled. It will keep returning
11231128
/// true for the duration of the frame even if the action was subsequently disabled in the frame.
1129+
///
1130+
/// The meaning of "frame" is either the current "dynamic" update (<c>MonoBehaviour.Update</c>) or the current
1131+
/// fixed update (<c>MonoBehaviour.FixedUpdate</c>) depending on the value of the <see cref="InputSettings.updateMode"/> setting.
11241132
/// </remarks>
11251133
/// <seealso cref="IsPressed"/>
11261134
/// <seealso cref="WasReleasedThisFrame"/>
@@ -1167,6 +1175,9 @@ public unsafe bool WasPressedThisFrame()
11671175
///
11681176
/// This method will disregard whether the action is currently enabled or disabled. It will keep returning
11691177
/// true for the duration of the frame even if the action was subsequently disabled in the frame.
1178+
///
1179+
/// The meaning of "frame" is either the current "dynamic" update (<c>MonoBehaviour.Update</c>) or the current
1180+
/// fixed update (<c>MonoBehaviour.FixedUpdate</c>) depending on the value of the <see cref="InputSettings.updateMode"/> setting.
11701181
/// </remarks>
11711182
/// <seealso cref="IsPressed"/>
11721183
/// <seealso cref="WasPressedThisFrame"/>
@@ -1223,6 +1234,9 @@ public unsafe bool WasReleasedThisFrame()
12231234
///
12241235
/// This method will disregard whether the action is currently enabled or disabled. It will keep returning
12251236
/// true for the duration of the frame even if the action was subsequently disabled in the frame.
1237+
///
1238+
/// The meaning of "frame" is either the current "dynamic" update (<c>MonoBehaviour.Update</c>) or the current
1239+
/// fixed update (<c>MonoBehaviour.FixedUpdate</c>) depending on the value of the <see cref="InputSettings.updateMode"/> setting.
12261240
/// </remarks>
12271241
/// <seealso cref="WasPressedThisFrame"/>
12281242
/// <seealso cref="phase"/>

Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInput.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ public InputActionAsset actions
350350
/// </remarks>
351351
/// <seealso cref="SwitchCurrentControlScheme(UnityEngine.InputSystem.InputDevice[])"/>
352352
/// <seealso cref="defaultControlScheme"/>
353+
/// <seealso cref="InputActionAsset.controlSchemes"/>
353354
public string currentControlScheme
354355
{
355356
get
@@ -877,6 +878,28 @@ public void PassivateInput()
877878
DeactivateInput();
878879
}
879880

881+
/// <summary>
882+
/// Switch the current control scheme to one that fits the given set of devices.
883+
/// </summary>
884+
/// <param name="devices">A list of input devices. Note that if any of the devices is already paired to another
885+
/// player, the device will end up paired to both players.</param>
886+
/// <returns>True if the switch was successful, false otherwise. The latter can happen, for example, if
887+
/// <see cref="actions"/> does not have a control scheme that fits the given set of devices.</returns>
888+
/// <exception cref="ArgumentNullException"><paramref name="devices"/> is <c>null</c>.</exception>
889+
/// <exception cref="InvalidOperationException"><see cref="actions"/> has not been assigned.</exception>
890+
/// <remarks>
891+
/// The player's currently paired devices (see <see cref="devices"/>) will get unpaired.
892+
///
893+
/// <example>
894+
/// <code>
895+
/// // Switch the first player to keyboard and mouse.
896+
/// PlayerInput.all[0]
897+
/// .SwitchCurrentControlScheme(Keyboard.current, Mouse.current);
898+
/// </code>
899+
/// </example>
900+
/// </remarks>
901+
/// <seealso cref="currentControlScheme"/>
902+
/// <seealso cref="InputActionAsset.controlSchemes"/>
880903
public bool SwitchCurrentControlScheme(params InputDevice[] devices)
881904
{
882905
if (devices == null)
@@ -895,6 +918,31 @@ public bool SwitchCurrentControlScheme(params InputDevice[] devices)
895918

896919
////REVIEW: these should just be SwitchControlScheme
897920

921+
/// <summary>
922+
/// Switch the player to use the given control scheme together with the given devices.
923+
/// </summary>
924+
/// <param name="controlScheme">Name of the control scheme. See <see cref="InputControlScheme.name"/>.</param>
925+
/// <param name="devices">A list of devices.</param>
926+
/// <exception cref="ArgumentNullException"><paramref name="devices"/> is <c>null</c> -or- <paramref name="controlScheme"/> is
927+
/// <c>null</c> or empty.</exception>
928+
/// <remarks>
929+
/// This method can be used to explicitly force a combination of control scheme and a specific set of
930+
/// devices.
931+
///
932+
/// <example>
933+
/// <code>
934+
/// // Put player 1 on the "Gamepad" control scheme together
935+
/// // with the second gamepad.
936+
/// PlayerInput.all[0].SwitchControlScheme(
937+
/// "Gamepad",
938+
/// Gamepad.all[1]);
939+
/// </code>
940+
/// </example>
941+
///
942+
/// The player's currently paired devices (see <see cref="devices"/>) will get unpaired.
943+
/// </remarks>
944+
/// <seealso cref="InputActionAsset.controlSchemes"/>
945+
/// <seealso cref="currentControlScheme"/>
898946
public void SwitchCurrentControlScheme(string controlScheme, params InputDevice[] devices)
899947
{
900948
if (string.IsNullOrEmpty(controlScheme))

0 commit comments

Comments
 (0)