Skip to content

Commit 63fd8a3

Browse files
author
Rene Damm
committed
MERGE: develop => stable.
2 parents 4c7b1da + c5b2457 commit 63fd8a3

26 files changed

+1055
-508
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void Actions_CanTargetSameControlWithMultipleActions()
170170
// https://fogbugz.unity3d.com/f/cases/1293808/
171171
[Test]
172172
[Category("Actions")]
173-
public void Actions_WhenSeveralBindingsResolveToSameControl_ControlIsAssociatedWithFirstActiveBinding()
173+
public void Actions_WhenSeveralBindingsResolveToSameControl_SameControlFeedsIntoActionMultipleTimes_ButIsListedInControlsOnlyOnce()
174174
{
175175
var gamepad = InputSystem.AddDevice<Gamepad>();
176176

@@ -180,6 +180,8 @@ public void Actions_WhenSeveralBindingsResolveToSameControl_ControlIsAssociatedW
180180
var actionMap = new InputActionMap();
181181
var action3 = actionMap.AddAction("action3");
182182
var action4 = actionMap.AddAction("action4");
183+
var action5 = actionMap.AddAction("action5");
184+
var action6 = actionMap.AddAction("action6");
183185

184186
action1.AddBinding("<Gamepad>/buttonSouth");
185187
action1.AddBinding("<Gamepad>/buttonSouth");
@@ -192,16 +194,30 @@ public void Actions_WhenSeveralBindingsResolveToSameControl_ControlIsAssociatedW
192194
action3.AddBinding("<Gamepad>/buttonSouth");
193195
action4.AddBinding("<Gamepad>/buttonSouth"); // Should not be removed; different action.
194196

197+
action5.AddBinding("<Gamepad>/buttonSouth", interactions: "press(behavior=0)");
198+
action5.AddBinding("<Gamepad>/buttonSouth", interactions: "press(behavior=1)");
199+
action5.AddBinding("<Gamepad>/buttonSouth", processors: "invert");
200+
201+
action6.AddCompositeBinding("Dpad")
202+
.With("Left", "<Gamepad>/leftStick/y", processors: "clamp(min=0,max=1)")
203+
.With("Right", "<Gamepad>/leftStick/y", processors: "clamp(min=-1,max=0),invert");
204+
205+
var action6Performed = 0;
206+
action6.performed += ctx => action6Performed += ctx.performed ? 1 : 0;
207+
195208
Assert.That(action1.controls, Is.EquivalentTo(new[] { gamepad.buttonSouth }));
196209
Assert.That(action2.controls, Has.Exactly(1).SameAs(gamepad.buttonSouth));
197-
Assert.That(action2.controls, Has.Count.EqualTo(4)); // North, south, east, west
210+
Assert.That(action2.controls, Is.EquivalentTo(new[] { gamepad.buttonNorth, gamepad.buttonSouth, gamepad.buttonEast, gamepad.buttonWest }));
198211
Assert.That(action3.controls, Is.EquivalentTo(new[] { gamepad.buttonNorth, gamepad.buttonSouth }));
199212
Assert.That(action4.controls, Is.EquivalentTo(new[] { gamepad.buttonSouth }));
213+
Assert.That(action5.controls, Is.EquivalentTo(new[] { gamepad.buttonSouth }));
214+
Assert.That(action6.controls, Is.EquivalentTo(new[] { gamepad.leftStick.y })); // Only mentioned once.
200215

201216
Assert.That(action1.GetBindingIndexForControl(gamepad.buttonSouth), Is.EqualTo(0));
202217
Assert.That(action2.GetBindingIndexForControl(gamepad.buttonSouth), Is.EqualTo(0));
203218
Assert.That(action3.GetBindingIndexForControl(gamepad.buttonSouth), Is.EqualTo(1));
204219
Assert.That(action4.GetBindingIndexForControl(gamepad.buttonSouth), Is.EqualTo(0));
220+
Assert.That(action5.GetBindingIndexForControl(gamepad.buttonSouth), Is.EqualTo(0));
205221

206222
// Go through a bit of pressing and releasing to make sure that the action state
207223
// processing wasn't thrown off its track.
@@ -210,6 +226,8 @@ public void Actions_WhenSeveralBindingsResolveToSameControl_ControlIsAssociatedW
210226
action2.Enable();
211227
action3.Enable();
212228
action4.Enable();
229+
action5.Enable();
230+
action6.Enable();
213231

214232
Press(gamepad.buttonSouth);
215233

@@ -245,6 +263,11 @@ public void Actions_WhenSeveralBindingsResolveToSameControl_ControlIsAssociatedW
245263
Assert.That(action2.triggered, Is.False);
246264
Assert.That(action3.triggered, Is.False);
247265
Assert.That(action4.triggered, Is.False);
266+
267+
Set(gamepad.leftStick, new Vector2(0, -1));
268+
269+
Assert.That(action6Performed, Is.EqualTo(1));
270+
Assert.That(action6.ReadValue<Vector2>(), Is.EqualTo(new Vector2(1, 0)));
248271
}
249272

250273
[Test]
@@ -1513,21 +1536,41 @@ public void Actions_ResettingDevice_CancelsOngoingActionsThatAreDrivenByIt()
15131536
// Create an action that performs on button *up*. This way we can tell whether
15141537
// the action is truly cancelled or whether it simply gets triggered by us
15151538
// resetting the corresponding device state.
1516-
var buttonReleaseAction = new InputAction(type: InputActionType.Button, binding: "<Gamepad>/buttonSouth",
1539+
var buttonReleaseAction = new InputAction(name: "button", type: InputActionType.Button, binding: "<Gamepad>/buttonSouth",
15171540
interactions: "press(behavior=1)");
15181541
buttonReleaseAction.Enable();
15191542

1543+
var valueAction = new InputAction(name: "value", type: InputActionType.Value, binding: "<Gamepad>/buttonSouth");
1544+
valueAction.Enable();
1545+
1546+
var passThroughAction = new InputAction(name: "passthrough", type: InputActionType.PassThrough, binding: "<Gamepad>/buttonSouth");
1547+
passThroughAction.Enable();
1548+
15201549
Press(gamepad.buttonSouth);
15211550

15221551
Assert.That(buttonReleaseAction.phase, Is.EqualTo(InputActionPhase.Started));
15231552
Assert.That(buttonReleaseAction.activeControl, Is.SameAs(gamepad.buttonSouth));
15241553

1554+
Assert.That(valueAction.phase, Is.EqualTo(InputActionPhase.Started)); // Goes back to Started after Performed.
1555+
Assert.That(valueAction.activeControl, Is.SameAs(gamepad.buttonSouth));
1556+
1557+
Assert.That(passThroughAction.phase, Is.EqualTo(InputActionPhase.Performed));
1558+
Assert.That(passThroughAction.activeControl, Is.SameAs(gamepad.buttonSouth));
1559+
15251560
using (var buttonReleaseActionTrace = new InputActionTrace(buttonReleaseAction))
1561+
using (var valueActionTrace = new InputActionTrace(valueAction))
1562+
using (var passThroughActionTrace = new InputActionTrace(passThroughAction))
15261563
{
15271564
InputSystem.ResetDevice(gamepad);
15281565

1529-
Assert.That(buttonReleaseActionTrace,
1530-
Canceled(buttonReleaseAction));
1566+
Assert.That(buttonReleaseActionTrace, Canceled(buttonReleaseAction));
1567+
Assert.That(valueActionTrace, Canceled(valueAction));
1568+
1569+
// This case is quirky. For button and value actions, the reset of the control value
1570+
// does not cause the action to start back up. For pass-through actions, that is different
1571+
// as *any* value change performs the action. So here, we see *both* a cancellation and then
1572+
// immediately a performing of the action.
1573+
Assert.That(passThroughActionTrace, Canceled(passThroughAction).AndThen(Performed(passThroughAction, value: 0f)));
15311574
}
15321575
}
15331576

Assets/Tests/InputSystem/CoreTests_Editor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,15 +2618,15 @@ public void Editor_LeavingPlayMode_DestroysAllActionStates()
26182618
var action = new InputAction(binding: "<Gamepad>/buttonSouth");
26192619
action.Enable();
26202620

2621-
Assert.That(InputActionState.s_GlobalList.length, Is.EqualTo(1));
2621+
Assert.That(InputActionState.s_GlobalState.globalList.length, Is.EqualTo(1));
26222622
Assert.That(InputSystem.s_Manager.m_StateChangeMonitors.Length, Is.GreaterThan(0));
26232623
Assert.That(InputSystem.s_Manager.m_StateChangeMonitors[0].count, Is.EqualTo(1));
26242624

26252625
// Exit play mode.
26262626
InputSystem.OnPlayModeChange(PlayModeStateChange.ExitingPlayMode);
26272627
InputSystem.OnPlayModeChange(PlayModeStateChange.EnteredEditMode);
26282628

2629-
Assert.That(InputActionState.s_GlobalList.length, Is.Zero);
2629+
Assert.That(InputActionState.s_GlobalState.globalList.length, Is.Zero);
26302630
Assert.That(InputSystem.s_Manager.m_StateChangeMonitors[0].listeners[0].control, Is.Null); // Won't get removed, just cleared.
26312631
}
26322632

Assets/Tests/InputSystem/Plugins/EnhancedTouchTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override void Setup()
2626
base.Setup();
2727

2828
// Disable() will not reset this so default initialize it here.
29-
Touch.s_HistoryLengthPerFinger = 64;
29+
Touch.s_GlobalState.historyLengthPerFinger = 64;
3030

3131
if (!TestContext.CurrentContext.Test.Properties.ContainsKey("EnhancedTouchDisabled"))
3232
{
@@ -45,16 +45,16 @@ public override void TearDown()
4545
EnhancedTouchSupport.Disable();
4646

4747
// Make sure cleanup really did clean up.
48-
Assert.That(Touch.s_Touchscreens.length, Is.EqualTo(0));
49-
Assert.That(Touch.s_PlayerState, Is.EqualTo(default(Touch.FingerAndTouchState)));
48+
Assert.That(Touch.s_GlobalState.touchscreens.length, Is.EqualTo(0));
49+
Assert.That(Touch.s_GlobalState.playerState, Is.EqualTo(default(Touch.FingerAndTouchState)));
5050
#if UNITY_EDITOR
51-
Assert.That(Touch.s_EditorState, Is.EqualTo(default(Touch.FingerAndTouchState)));
51+
Assert.That(Touch.s_GlobalState.editorState, Is.EqualTo(default(Touch.FingerAndTouchState)));
5252
#endif
5353

5454
// Some state is kept alive in-between Disable/Enable. Manually clean it out.
55-
Touch.s_OnFingerDown = default;
56-
Touch.s_OnFingerUp = default;
57-
Touch.s_OnFingerMove = default;
55+
Touch.s_GlobalState.onFingerDown = default;
56+
Touch.s_GlobalState.onFingerUp = default;
57+
Touch.s_GlobalState.onFingerMove = default;
5858

5959
TouchSimulation.Destroy();
6060
TouchSimulation.s_Instance = m_OldTouchSimulationInstance;

Assets/Tests/InputSystem/Plugins/UITests.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ private static TestObjects CreateTestUI(Rect viewport = default, bool noFirstSel
109109
var systemObject = new GameObject(namePrefix + "System");
110110
objects.eventSystem = systemObject.AddComponent<TestEventSystem>();
111111
var uiModule = systemObject.AddComponent<InputSystemUIInputModule>();
112+
uiModule.UnassignActions();
112113
objects.uiModule = uiModule;
113114
objects.eventSystem.UpdateModules();
114115

@@ -182,6 +183,40 @@ private static TestObjects CreateTestUI(Rect viewport = default, bool noFirstSel
182183
return objects;
183184
}
184185

186+
[Test]
187+
[Category("UI")]
188+
public void UI_InputModuleHasDefaultActions()
189+
{
190+
var go = new GameObject();
191+
var uiModule = go.AddComponent<InputSystemUIInputModule>();
192+
193+
Assert.That(uiModule.actionsAsset, Is.Not.Null);
194+
Assert.That(uiModule.point?.action, Is.SameAs(uiModule.actionsAsset["UI/Point"]));
195+
Assert.That(uiModule.leftClick?.action, Is.SameAs(uiModule.actionsAsset["UI/Click"]));
196+
Assert.That(uiModule.rightClick?.action, Is.SameAs(uiModule.actionsAsset["UI/RightClick"]));
197+
Assert.That(uiModule.middleClick?.action, Is.SameAs(uiModule.actionsAsset["UI/MiddleClick"]));
198+
Assert.That(uiModule.scrollWheel?.action, Is.SameAs(uiModule.actionsAsset["UI/ScrollWheel"]));
199+
Assert.That(uiModule.submit?.action, Is.SameAs(uiModule.actionsAsset["UI/Submit"]));
200+
Assert.That(uiModule.cancel?.action, Is.SameAs(uiModule.actionsAsset["UI/Cancel"]));
201+
Assert.That(uiModule.move?.action, Is.SameAs(uiModule.actionsAsset["UI/Navigate"]));
202+
Assert.That(uiModule.trackedDeviceOrientation?.action, Is.SameAs(uiModule.actionsAsset["UI/TrackedDeviceOrientation"]));
203+
Assert.That(uiModule.trackedDevicePosition?.action, Is.SameAs(uiModule.actionsAsset["UI/TrackedDevicePosition"]));
204+
205+
uiModule.UnassignActions();
206+
207+
Assert.That(uiModule.actionsAsset, Is.Null);
208+
Assert.That(uiModule.point, Is.Null);
209+
Assert.That(uiModule.leftClick, Is.Null);
210+
Assert.That(uiModule.rightClick, Is.Null);
211+
Assert.That(uiModule.middleClick, Is.Null);
212+
Assert.That(uiModule.scrollWheel, Is.Null);
213+
Assert.That(uiModule.submit, Is.Null);
214+
Assert.That(uiModule.cancel, Is.Null);
215+
Assert.That(uiModule.move, Is.Null);
216+
Assert.That(uiModule.trackedDeviceOrientation, Is.Null);
217+
Assert.That(uiModule.trackedDevicePosition, Is.Null);
218+
}
219+
185220
// Comprehensive test for general pointer input behaviors.
186221
// NOTE: The behavior we test for here is slightly *DIFFERENT* than what you get with StandaloneInputModule. The reason is that
187222
// StandaloneInputModule has both lots of inconsistencies between touch and mouse input (example: touch press handling goes
@@ -3371,8 +3406,8 @@ public IEnumerator UI_WhenAppLosesAndRegainsFocus_WhileUIButtonIsPressed_UIButto
33713406

33723407
Assert.That(scene.actions.UI.Click.phase.IsInProgress(), Is.True);
33733408

3374-
var clickWasCanceled = false;
3375-
scene.actions.UI.Click.canceled += _ => clickWasCanceled = true;
3409+
var clickCanceled = 0;
3410+
scene.actions.UI.Click.canceled += _ => ++ clickCanceled;
33763411

33773412
yield return null;
33783413

@@ -3391,7 +3426,7 @@ public IEnumerator UI_WhenAppLosesAndRegainsFocus_WhileUIButtonIsPressed_UIButto
33913426
scene.leftChildReceiver.events.Clear();
33923427

33933428
runtime.PlayerFocusLost();
3394-
Assert.That(clickWasCanceled, Is.True);
3429+
Assert.That(clickCanceled, Is.EqualTo(1));
33953430
scene.eventSystem.SendMessage("OnApplicationFocus", false);
33963431

33973432
Assert.That(scene.leftChildReceiver.events, Is.Empty);

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
Due to package verification, the latest version below is the unpublished version and the date is meaningless.
99
however, it has to be formatted properly to pass verification tests.
1010

11+
## [1.1.0] - 2021-08-27
12+
13+
### Changed
14+
15+
- Modified the fix that landed in `1.1-preview.3` for [any given control being added to an action only once](#same_control_multiple_times_fix).
16+
* This caused a regression with some setups that, for example, bound the same control multiple times in a composite using processors to alter the value of the control.
17+
* Internally, a control is now again allowed to feed into the same action through more than one binding.
18+
* However, externally the control will be mentioned on the action's `InputAction.controls` list only once.
19+
- Adding `InputSystemUIInputModule` from code now installs `DefaultInputActions`. This is equivalent to the default setup when adding the component in the editor ([case 1259306](https://issuetracker.unity3d.com/issues/input-system-ugui-button-does-not-react-when-clicked)).
20+
```CSharp
21+
var go = new GameObject();
22+
go.AddComponent<EventSystem>();
23+
var uiModule = go.AddComponent<InputSystemUIInputModule>();
24+
// uiModule.actionsAsset now has a DefaultInputActions() asset assigned to it and the various
25+
// action references point to its actions.
26+
```
27+
* `InputSystemUIInputModule.UnassignActions` has been added to remove all actions from the module en bloc.
28+
```CSharp
29+
uiModule.UnassignActions();
30+
```
31+
32+
### Fixed
33+
34+
- Fixed an issue where mixing test cases based on `InputTestFixture` (using mocked `InputSystem`) and regular test cases (using real `InputSystem`) would lead to static state leaking between test cases causing random failures and unexpected/undefined behavior ([case 1329015](https://issuetracker.unity3d.com/product/unity/issues/guid/1329015)).
35+
- Fixed `InputSystemUIInputModule.AssignDefaultActions` not assigning `trackedDeviceOrientation` and `trackedDevicePosition`.
36+
- Fixed regression introduced by [previous change](#ui_multiple_scenes_fix) where `InputSystemUIInputModule` would not disable actions correctly.
37+
- Fixed `InputAction.canceled` not getting triggered reliably for `InputActionType.PassThrough` actions when `InputSystem.ResetDevice` was called.
38+
- Fixed device resets (e.g. happening as part of focus changes) leading to only some actions bound to these devices getting cancelled instead of all of them.
39+
1140
## [1.1.0-pre.6] - 2021-08-23
1241

1342
### Fixed
@@ -174,7 +203,7 @@ however, it has to be formatted properly to pass verification tests.
174203
- Fixed `AxisDeadzoneProcessor` min/max values not being settable to 0 in editor UI ([case 1293744](https://issuetracker.unity3d.com/issues/input-system-input-system-axis-deadzone-minimum-value-fallsback-to-default-value-if-its-set-to-0)).
175204
- Fixed blurry icons in input debugger, asset editor, input settings ([case 1299595](https://issuetracker.unity3d.com/issues/inputsystem-supported-device-list-dropdown-icons-present-under-project-settings-are-not-user-friendly)).
176205
- Fixed `clickCount` not being incremented correctly by `InputSystemUIInputModule` for successive mouse clicks ([case 1317239](https://issuetracker.unity3d.com/issues/eventdata-dot-clickcount-doesnt-increase-when-clicking-repeatedly-in-the-new-input-system)).
177-
- Fixed UI not working after additively loading scenes with additional InputSystemUIInputModule modules ([case 1251720](https://issuetracker.unity3d.com/issues/input-system-buttons-cannot-be-pressed-after-additively-loading-scenes-with-additional-event-systems)).
206+
- <a name="ui_multiple_scenes_fix"></a>Fixed UI not working after additively loading scenes with additional InputSystemUIInputModule modules ([case 1251720](https://issuetracker.unity3d.com/issues/input-system-buttons-cannot-be-pressed-after-additively-loading-scenes-with-additional-event-systems)).
178207
- Fixed no `OnPointerExit` received when changing UI state without moving pointer ([case 1232705](https://issuetracker.unity3d.com/issues/input-system-onpointerexit-is-not-triggered-when-a-ui-element-interrupts-a-mouse-hover)).
179208
- Fixed reference to `.inputactions` of `Player Prefab` referenced by `PlayerInputManager` being destroyed on going into play mode, if the player prefab was a nested prefab ([case 1319756](https://issuetracker.unity3d.com/issues/playerinput-component-loses-its-reference-to-an-inputactionasset)).
180209
- Fixed "Scheme Name" label clipped in "Add Control Schema" popup window ([case 1199560]https://issuetracker.unity3d.com/issues/themes-input-system-scheme-name-is-clipped-in-add-control-schema-window-with-inter-default-font)).
@@ -266,7 +295,7 @@ however, it has to be formatted properly to pass verification tests.
266295

267296
#### Actions
268297

269-
- Fixed actions not triggering correctly when multiple bindings on the same action were referencing the same control ([case 1293808](https://issuetracker.unity3d.com/product/unity/issues/guid/1293808/)).
298+
- <a name="same_control_multiple_times_fix"></a>Fixed actions not triggering correctly when multiple bindings on the same action were referencing the same control ([case 1293808](https://issuetracker.unity3d.com/product/unity/issues/guid/1293808/)).
270299
* Bindings will now "claim" controls during resolution. If several bindings __on the same action__ resolve to the same control, only the first such binding will successfully resolve to the control. Subsequent bindings will only resolve to controls not already referenced by other bindings on the action.
271300
```CSharp
272301
var action = new InputAction();

0 commit comments

Comments
 (0)