Skip to content

Commit e0722d2

Browse files
authored
Merge branch 'develop' into isxb-1243-fix-visualizer
2 parents 6f82e69 + be8287f commit e0722d2

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,11 +27,14 @@ 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
- Fixed an issue in `Samples/Visualizers/GamepadVisualizer.unity` sample where the visualization wouldn't handle device disconnects or current device changes properly (ISXB-1243).
3133

3234
### Changed
3335
- Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086).
3436
- 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.
37+
- Changed paremeter `overrideModifiersNeedToBePressedFirst` to obsolete for `ButtonWithOneModifier`, `ButtonWithTwoModifiers`, `OneModifierComposite` and `TwoModifiersComposite` in favour the new `modifiersOrder` parameter which is more explicit.
3538
- Changed `Samples/Visualizers/GamepadVisualizer.unity` to visualize the control values of the current device instead of the first device.
3639

3740
## [1.11.2] - 2024-10-16

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
}

0 commit comments

Comments
 (0)