Skip to content

Commit be8287f

Browse files
authored
FIX: Fixed documentation of bindings with modifiers and UI Toolkit tooltips in the asset editor (ISBX-806) (#2048)
1 parent d19254d commit be8287f

File tree

17 files changed

+355
-38
lines changed

17 files changed

+355
-38
lines changed

Assets/Samples/InGameHints/InGameHintsActions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
4-
// version 1.11.3
4+
// version 1.12.0
55
// from Assets/Samples/InGameHints/InGameHintsActions.inputactions
66
//
77
// Changes to this file may cause incorrect behavior and will be lost if

Assets/Samples/SimpleDemo/SimpleControls.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
4-
// version 1.11.3
4+
// version 1.12.0
55
// from Assets/Samples/SimpleDemo/SimpleControls.inputactions
66
//
77
// Changes to this file may cause incorrect behavior and will be lost if

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,22 +319,67 @@ public void Actions_WhenShortcutsEnabled_PressingShortcutSequenceInWrongOrder_Do
319319
[TestCase("leftShift", "leftAlt", "space", true)]
320320
[TestCase("leftShift", null, "space", false)]
321321
[TestCase("leftShift", "leftAlt", "space", false)]
322-
public void Actions_PressingShortcutSequenceInWrongOrder_DoesNotTriggerShortcut_ExceptIfOverridden(string modifier1, string modifier2, string binding,
323-
bool legacyComposites)
322+
public void Actions_WhenShortcutsDisabled_PressingShortcutSequenceInWrongOrder_DoesNotTriggerShortcutIfOverridden(string modifier1, string modifier2, string binding, bool legacyComposites)
324323
{
325324
var keyboard = InputSystem.AddDevice<Keyboard>();
326325

327326
var action = new InputAction();
328327
if (!string.IsNullOrEmpty(modifier2))
329328
{
330-
action.AddCompositeBinding((legacyComposites ? "ButtonWithTwoModifiers" : "TwoModifiers") + "(overrideModifiersNeedToBePressedFirst)")
329+
action.AddCompositeBinding((legacyComposites ? "ButtonWithTwoModifiers" : "TwoModifiers") + "(modifiersOrder=1)")
331330
.With("Modifier1", "<Keyboard>/" + modifier1)
332331
.With("Modifier2", "<Keyboard>/" + modifier2)
333332
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding);
334333
}
335334
else
336335
{
337-
action.AddCompositeBinding((legacyComposites ? "ButtonWithOneModifier" : "OneModifier") + "(overrideModifiersNeedToBePressedFirst)")
336+
action.AddCompositeBinding((legacyComposites ? "ButtonWithOneModifier" : "OneModifier") + "(modifiersOrder=1)")
337+
.With("Modifier", "<Keyboard>/" + modifier1)
338+
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding);
339+
}
340+
341+
action.Enable();
342+
343+
var wasPerformed = false;
344+
action.performed += _ => wasPerformed = true;
345+
346+
// Press binding first, then modifiers.
347+
Press((ButtonControl)keyboard[binding]);
348+
Press((ButtonControl)keyboard[modifier1]);
349+
if (!string.IsNullOrEmpty(modifier2))
350+
Press((ButtonControl)keyboard[modifier2]);
351+
352+
Assert.That(wasPerformed, Is.False);
353+
}
354+
355+
[Test]
356+
[Category("Actions")]
357+
[TestCase("leftShift", null, "space", true, true)]
358+
[TestCase("leftShift", "leftAlt", "space", true, true)]
359+
[TestCase("leftShift", null, "space", false, true)]
360+
[TestCase("leftShift", "leftAlt", "space", false, true)]
361+
[TestCase("leftShift", null, "space", true, false)]
362+
[TestCase("leftShift", "leftAlt", "space", true, false)]
363+
[TestCase("leftShift", null, "space", false, false)]
364+
[TestCase("leftShift", "leftAlt", "space", false, false)]
365+
public void Actions_WhenShortcutsAreEnabled_PressingShortcutSequenceInWrongOrder_DoesNotTriggerShortcut_ExceptIfOverridden(string modifier1, string modifier2, string binding,
366+
bool legacyComposites, bool overrideModifiersNeedToBePressedFirst)
367+
{
368+
InputSystem.settings.shortcutKeysConsumeInput = true;
369+
370+
var keyboard = InputSystem.AddDevice<Keyboard>();
371+
372+
var action = new InputAction();
373+
if (!string.IsNullOrEmpty(modifier2))
374+
{
375+
action.AddCompositeBinding((legacyComposites ? "ButtonWithTwoModifiers" : "TwoModifiers") + (overrideModifiersNeedToBePressedFirst ? "(overrideModifiersNeedToBePressedFirst)" : "(modifiersOrder=2)"))
376+
.With("Modifier1", "<Keyboard>/" + modifier1)
377+
.With("Modifier2", "<Keyboard>/" + modifier2)
378+
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding);
379+
}
380+
else
381+
{
382+
action.AddCompositeBinding((legacyComposites ? "ButtonWithOneModifier" : "OneModifier") + (overrideModifiersNeedToBePressedFirst ? "(overrideModifiersNeedToBePressedFirst)" : "(modifiersOrder=2)"))
338383
.With("Modifier", "<Keyboard>/" + modifier1)
339384
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding);
340385
}

Assets/Tests/InputSystem/InputActionCodeGeneratorActions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
4-
// version 1.11.3
4+
// version 1.12.0
55
// from Assets/Tests/InputSystem/InputActionCodeGeneratorActions.inputactions
66
//
77
// Changes to this file may cause incorrect behavior and will be lost if

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ however, it has to be formatted properly to pass verification tests.
2727
- Fixed an issue where removing the InputSystem package could lead to invalid input handling settings.
2828
- Fixed `ArgumentOutOfRangeException` when adding a new Control Scheme with any Device selected. [ISXB-1129](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1129)
2929
- Fixed a CS0105 compiler warning due to duplicate using statement in test source code (ISXB-1247).
30+
- Fixed tooltip support in the UI Toolkit version of the Input Actions Asset editor.
31+
- Fixed documentation to clarify bindings with modifiers `overrideModifiersNeedToBePressedFirst` configuration [ISXB-806](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-806).
3032

3133
### Changed
3234
- Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086).
3335
- Changed `OnScreenControl` to automaticaly switch, in Single Player with autoswitch enabled, to the target device control scheme when the first component is enabled to prevent bad interactions when it start.
36+
- Changed paremeter `overrideModifiersNeedToBePressedFirst` to obsolete for `ButtonWithOneModifier`, `ButtonWithTwoModifiers`, `OneModifierComposite` and `TwoModifiersComposite` in favour the new `modifiersOrder` parameter which is more explicit.
3437

3538
## [1.11.2] - 2024-10-16
3639

Packages/com.unity.inputsystem/InputSystem/Actions/Composites/ButtonWithOneModifier.cs

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.ComponentModel;
23
using UnityEngine.InputSystem.Layouts;
34
using UnityEngine.InputSystem.Utilities;
@@ -79,16 +80,72 @@ public class ButtonWithOneModifier : InputBindingComposite<float>
7980
/// still trigger. Default is false.
8081
/// </summary>
8182
/// <remarks>
82-
/// By default, <see cref="modifier"/> is required to be in pressed state before or at the same time that <see cref="button"/>
83+
/// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled,
84+
/// <see cref="modifier"/> is required to be in pressed state before or at the same time that <see cref="button"/>
8385
/// goes into pressed state for the composite as a whole to trigger. This means that binding to, for example, <c>Shift+B</c>,
8486
/// the <c>shift</c> key has to be pressed before pressing the <c>B</c> key. This is the behavior usually expected with
8587
/// keyboard shortcuts.
8688
///
8789
/// This parameter can be used to bypass this behavior and allow any timing between <see cref="modifier"/> and <see cref="button"/>.
8890
/// The only requirement is for them both to concurrently be in pressed state.
91+
///
92+
/// To don't depends on the setting please consider using <see cref="modifiersOrder"/> instead.
8993
/// </remarks>
94+
[Tooltip("Obsolete please use modifiers Order. If enabled, this will override the Input Consumption setting, allowing the modifier keys to be pressed after the button and the composite will still trigger.")]
95+
[Obsolete("Use ModifiersOrder.Unordered with 'modifiersOrder' instead")]
9096
public bool overrideModifiersNeedToBePressedFirst;
9197

98+
/// <summary>
99+
/// Determines how a <c>modifiers</c> keys need to be pressed in order or not.
100+
/// </summary>
101+
public enum ModifiersOrder
102+
{
103+
/// <summary>
104+
/// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled,
105+
/// <see cref="modifier"/> is required to be in pressed state before or at the same time that <see cref="button"/>
106+
/// goes into pressed state for the composite as a whole to trigger. This means that binding to, for example, <c>Shift+B</c>,
107+
/// the <c>shift</c> key has to be pressed before pressing the <c>B</c> key. This is the behavior usually expected with
108+
/// keyboard shortcuts.
109+
///
110+
/// If the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is disabled,
111+
/// modifiers can be pressed after the button and the composite will still trigger.
112+
/// </summary>
113+
Default = 0,
114+
115+
/// <summary>
116+
/// <see cref="modifier"/> is required to be in pressed state before or at the same
117+
/// time that <see cref="button"/> goes into pressed state for the composite as a whole to trigger. This means that binding to,
118+
/// for example, <c>Ctrl+B</c>, the <c>ctrl</c> key have to be pressed before pressing the <c>B</c> key.
119+
/// This is the behavior usually expected with keyboard shortcuts.
120+
/// </summary>
121+
Ordered = 1,
122+
123+
/// <summary>
124+
/// <see cref="modifier"/> can be pressed after <see cref="button"/>
125+
/// and the composite will still trigger. The only requirement is for all of them to concurrently be in pressed state.
126+
/// </summary>
127+
Unordered = 2
128+
}
129+
130+
/// <summary>
131+
/// If set to <c>Ordered</c> or <c>Unordered</c>, the built-in logic to determine if modifiers need to be pressed first is overridden.
132+
/// </summary>
133+
/// <remarks>
134+
/// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled,
135+
/// <see cref="modifier"/> is required to be in pressed state before or at the same time that <see cref="button"/>
136+
/// goes into pressed state for the composite as a whole to trigger. This means that binding to, for example, <c>Shift+B</c>,
137+
/// the <c>shift</c> key has to be pressed before pressing the <c>B</c> key. This is the behavior usually expected with
138+
/// keyboard shortcuts.
139+
///
140+
/// If the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is disabled,
141+
/// modifiers can be pressed after the button and the composite will still trigger.
142+
///
143+
/// This parameter can be used to bypass this behavior and enforce the timing order or allow any timing between <see cref="modifier"/> and <see cref="button"/>.
144+
/// The only requirement is for them both to concurrently be in pressed state.
145+
/// </remarks>
146+
[Tooltip("By default it follows the Input Consumption setting to determine if the modifers keys need to be pressed first.")]
147+
public ModifiersOrder modifiersOrder = ModifiersOrder.Default;
148+
92149
/// <summary>
93150
/// Return the value of the <see cref="button"/> part if <see cref="modifier"/> is pressed. Otherwise
94151
/// return 0.
@@ -107,7 +164,7 @@ private bool ModifierIsPressed(ref InputBindingCompositeContext context)
107164
{
108165
var modifierDown = context.ReadValueAsButton(modifier);
109166

110-
if (modifierDown && !overrideModifiersNeedToBePressedFirst)
167+
if (modifierDown && modifiersOrder == ModifiersOrder.Ordered)
111168
{
112169
var timestamp = context.GetPressTime(button);
113170
var timestamp1 = context.GetPressTime(modifier);
@@ -130,8 +187,17 @@ public override float EvaluateMagnitude(ref InputBindingCompositeContext context
130187

131188
protected override void FinishSetup(ref InputBindingCompositeContext context)
132189
{
133-
if (!overrideModifiersNeedToBePressedFirst)
134-
overrideModifiersNeedToBePressedFirst = !InputSystem.settings.shortcutKeysConsumeInput;
190+
if (modifiersOrder == ModifiersOrder.Default)
191+
{
192+
// Legacy. We need to reference the obsolete member here so temporarily
193+
// turn off the warning.
194+
#pragma warning disable CS0618
195+
if (overrideModifiersNeedToBePressedFirst)
196+
#pragma warning restore CS0618
197+
modifiersOrder = ModifiersOrder.Unordered;
198+
else
199+
modifiersOrder = InputSystem.settings.shortcutKeysConsumeInput ? ModifiersOrder.Ordered : ModifiersOrder.Unordered;
200+
}
135201
}
136202
}
137203
}

Packages/com.unity.inputsystem/InputSystem/Actions/Composites/ButtonWithTwoModifiers.cs

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.ComponentModel;
23
using UnityEngine.InputSystem.Layouts;
34
using UnityEngine.InputSystem.Utilities;
@@ -94,16 +95,71 @@ public class ButtonWithTwoModifiers : InputBindingComposite<float>
9495
/// and the composite will still trigger. Default is false.
9596
/// </summary>
9697
/// <remarks>
97-
/// By default, <see cref="modifier1"/> and <see cref="modifier2"/> are required to be in pressed state before or at the same
98+
/// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled,
99+
/// <see cref="modifier1"/> and <see cref="modifier2"/> are required to be in pressed state before or at the same
98100
/// time that <see cref="button"/> goes into pressed state for the composite as a whole to trigger. This means that binding to,
99-
/// for example, <c>Ctrl+Shift+B</c>, the <c>ctrl</c> <c>shift</c> keys have to be pressed before pressing the <c>B</c> key.
101+
/// for example, <c>Ctrl+Shift+B</c>, the <c>ctrl</c> and <c>shift</c> keys have to be pressed, in any order, before pressing the <c>B</c> key.
100102
/// This is the behavior usually expected with keyboard shortcuts.
101103
///
102104
/// This parameter can be used to bypass this behavior and allow any timing between <see cref="modifier1"/>, <see cref="modifier2"/>,
103105
/// and <see cref="button"/>. The only requirement is for all of them to concurrently be in pressed state.
106+
///
107+
/// To don't depends on the setting please consider using <see cref="modifiersOrder"/> instead.
104108
/// </remarks>
109+
[Tooltip("Obsolete please use modifiers Order. If enabled, this will override the Input Consumption setting, allowing the modifier keys to be pressed after the button and the composite will still trigger.")]
110+
[Obsolete("Use ModifiersOrder.Unordered with 'modifiersOrder' instead")]
105111
public bool overrideModifiersNeedToBePressedFirst;
106112

113+
/// <summary>
114+
/// Determines how a <c>modifiers</c> keys need to be pressed in order or not.
115+
/// </summary>
116+
public enum ModifiersOrder
117+
{
118+
/// <summary>
119+
/// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled,
120+
/// <see cref="modifier1"/> and <see cref="modifier2"/> are required to be in pressed state before or at the same
121+
/// time that <see cref="button"/> goes into pressed state for the composite as a whole to trigger. This means that binding to,
122+
/// for example, <c>Ctrl+Shift+B</c>, the <c>ctrl</c> and <c>shift</c> keys have to be pressed, in any order, before pressing the <c>B</c> key.
123+
/// This is the behavior usually expected with keyboard shortcuts.
124+
///
125+
/// If the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is disabled,
126+
/// modifiers can be pressed after the button and the composite will still trigger.
127+
/// </summary>
128+
Default = 0,
129+
130+
/// <summary>
131+
/// <see cref="modifier1"/> and <see cref="modifier2"/> are required to be in pressed state before or at the same
132+
/// time that <see cref="button"/> goes into pressed state for the composite as a whole to trigger. This means that binding to,
133+
/// for example, <c>Ctrl+Shift+B</c>, the <c>ctrl</c> and <c>shift</c> keys have to be pressed, in any order, before pressing the <c>B</c> key.
134+
/// This is the behavior usually expected with keyboard shortcuts.
135+
/// </summary>
136+
Ordered = 1,
137+
138+
/// <summary>
139+
/// <see cref="modifier1"/> and/or <see cref="modifier2"/> can be pressed after <see cref="button"/>
140+
/// and the composite will still trigger. The only requirement is for all of them to concurrently be in pressed state.
141+
/// </summary>
142+
Unordered = 2
143+
}
144+
145+
/// <summary>
146+
/// If set to <c>Ordered</c> or <c>Unordered</c>, the built-in logic to determine if modifiers need to be pressed first is overridden.
147+
/// </summary>
148+
/// <remarks>
149+
/// By default, if the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is enabled,
150+
/// <see cref="modifier1"/> and <see cref="modifier2"/> are required to be in pressed state before or at the same
151+
/// time that <see cref="button"/> goes into pressed state for the composite as a whole to trigger. This means that binding to,
152+
/// for example, <c>Ctrl+Shift+B</c>, the <c>ctrl</c> and <c>shift</c> keys have to be pressed, in any order, before pressing the <c>B</c> key.
153+
/// This is the behavior usually expected with keyboard shortcuts.
154+
///
155+
/// If the setting <see cref="InputSettings.shortcutKeysConsumeInput"/> is disabled,
156+
/// modifiers can be pressed after the button and the composite will still trigger.
157+
///
158+
/// This field allows you to explicitly override this default inference.
159+
/// </remarks>
160+
[Tooltip("By default it follows the Input Consumption setting to determine if the modifers keys need to be pressed first.")]
161+
public ModifiersOrder modifiersOrder = ModifiersOrder.Default;
162+
107163
/// <summary>
108164
/// Return the value of the <see cref="button"/> part while both <see cref="modifier1"/> and <see cref="modifier2"/>
109165
/// are pressed. Otherwise return 0.
@@ -122,7 +178,7 @@ private bool ModifiersArePressed(ref InputBindingCompositeContext context)
122178
{
123179
var modifiersDown = context.ReadValueAsButton(modifier1) && context.ReadValueAsButton(modifier2);
124180

125-
if (modifiersDown && !overrideModifiersNeedToBePressedFirst)
181+
if (modifiersDown && modifiersOrder == ModifiersOrder.Ordered)
126182
{
127183
var timestamp = context.GetPressTime(button);
128184
var timestamp1 = context.GetPressTime(modifier1);
@@ -146,8 +202,17 @@ public override float EvaluateMagnitude(ref InputBindingCompositeContext context
146202

147203
protected override void FinishSetup(ref InputBindingCompositeContext context)
148204
{
149-
if (!overrideModifiersNeedToBePressedFirst)
150-
overrideModifiersNeedToBePressedFirst = !InputSystem.settings.shortcutKeysConsumeInput;
205+
if (modifiersOrder == ModifiersOrder.Default)
206+
{
207+
// Legacy. We need to reference the obsolete member here so temporarily
208+
// turn off the warning.
209+
#pragma warning disable CS0618
210+
if (overrideModifiersNeedToBePressedFirst)
211+
#pragma warning restore CS0618
212+
modifiersOrder = ModifiersOrder.Unordered;
213+
else
214+
modifiersOrder = InputSystem.settings.shortcutKeysConsumeInput ? ModifiersOrder.Ordered : ModifiersOrder.Unordered;
215+
}
151216
}
152217
}
153218
}

0 commit comments

Comments
 (0)