From 43efc3b035f5211394ea2fe36c516be6ee2653b1 Mon Sep 17 00:00:00 2001 From: Simon Wittber Date: Mon, 28 Oct 2024 14:24:34 +0800 Subject: [PATCH 1/5] FIX: ISXB-1127 composite incorrectly returning IsPressed (#2035) * Revert "FIX: Composite binding isn't triggered after ResetDevice() called during Action handler (ISXB-746) (#1893)" This reverts commit 0ddd534d86ea0b7bb2d48b48fd47af951a93aef9. --- Assets/Tests/InputSystem/CoreTests_Actions.cs | 95 ------------------- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + .../InputSystem/Actions/InputActionState.cs | 62 +++++------- 3 files changed, 24 insertions(+), 134 deletions(-) diff --git a/Assets/Tests/InputSystem/CoreTests_Actions.cs b/Assets/Tests/InputSystem/CoreTests_Actions.cs index ba26bc52b6..0aa3d09fbe 100644 --- a/Assets/Tests/InputSystem/CoreTests_Actions.cs +++ b/Assets/Tests/InputSystem/CoreTests_Actions.cs @@ -12405,99 +12405,4 @@ public void Actions_ActionMapDisabledDuringOnAfterSerialization() Assert.That(map.enabled, Is.True); Assert.That(map.FindAction("MyAction", true).enabled, Is.True); } - - // ResetDevice wasn't properly clearly Composite key state, i.e. BindingState.pressTime - // https://jira.unity3d.com/browse/ISXB-746 - [Test] - [TestCase(false)] - [TestCase(true)] - [Category("Actions")] - public void Actions_CompositeBindingResetWhenResetDeviceCalledWhileExecutingAction(bool useTwoModifierComposite) - { - var keyboard = InputSystem.AddDevice(); - bool actionPerformed; - - // Enables "Modifier must be pressed first" behavior on all Composite Bindings - InputSystem.settings.shortcutKeysConsumeInput = true; - - const string modifier1 = "/shift"; - const string modifier2 = "/ctrl"; - const string key = "/F1"; - - var map = new InputActionMap(); - var resetAction = map.AddAction("resetAction"); - - if (!useTwoModifierComposite) - { - resetAction.AddCompositeBinding("OneModifier") - .With("Modifier", modifier1) - .With("Binding", key); - } - else - { - resetAction.AddCompositeBinding("TwoModifiers") - .With("Modifier1", modifier1) - .With("Modifier2", modifier2) - .With("Binding", key); - } - - resetAction.performed += (InputAction.CallbackContext ctx) => - { - // Disable the Keyboard while action is being performed. - // This simulates an "OnFocusLost" event occurring while processing the Action, e.g. when switching primary displays or moving the main window - actionPerformed = true; - InputSystem.s_Manager.EnableOrDisableDevice(keyboard.device, false, InputManager.DeviceDisableScope.TemporaryWhilePlayerIsInBackground); - }; - - map.Enable(); - - actionPerformed = false; - Press(keyboard.leftShiftKey); - Press(keyboard.leftCtrlKey); - Press(keyboard.f1Key); - - Assert.IsTrue(actionPerformed); - - // Re enable the Keyboard (before keys are released) and execute Action again - InputSystem.s_Manager.EnableOrDisableDevice(keyboard.device, true, InputManager.DeviceDisableScope.TemporaryWhilePlayerIsInBackground); - - actionPerformed = false; - Release(keyboard.leftShiftKey); - Release(keyboard.leftCtrlKey); - Release(keyboard.f1Key); - - Press(keyboard.leftCtrlKey); - Press(keyboard.leftShiftKey); - Press(keyboard.f1Key); - - Assert.IsTrue(actionPerformed); - - actionPerformed = false; - Release(keyboard.leftCtrlKey); - Release(keyboard.leftShiftKey); - Release(keyboard.f1Key); - - // Re enable the Keyboard (after keys are released) and execute Action one more time - InputSystem.s_Manager.EnableOrDisableDevice(keyboard.device, true, InputManager.DeviceDisableScope.TemporaryWhilePlayerIsInBackground); - - Press(keyboard.leftCtrlKey); - Press(keyboard.leftShiftKey); - Press(keyboard.f1Key); - - Assert.IsTrue(actionPerformed); - - actionPerformed = false; - Press(keyboard.leftShiftKey); - Press(keyboard.leftCtrlKey); - Press(keyboard.f1Key); - - // Re enable the Keyboard (before keys are released) and verify Action isn't triggered when Key pressed first - InputSystem.s_Manager.EnableOrDisableDevice(keyboard.device, true, InputManager.DeviceDisableScope.TemporaryWhilePlayerIsInBackground); - - Press(keyboard.f1Key); - Press(keyboard.leftCtrlKey); - Press(keyboard.leftShiftKey); - - Assert.IsFalse(actionPerformed); - } } diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 4c9fc9a71e..edfb394b39 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -12,6 +12,7 @@ however, it has to be formatted properly to pass verification tests. ### Fixed - Fixed an issue causing the Action context menu to not show on right click when right clicking an action in the Input Action Editor [ISXB-1134](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1134). +- Reverted changes from 0ddd534d8 (ISXB-746) which introduced a regression [ISXB-1127](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1127). - Fixed `ArgumentNullException: Value cannot be null.` during the migration of Project-wide Input Actions from `InputManager.asset` to `InputSystem_Actions.inputactions` asset which lead do the lost of the configuration [ISXB-1105](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1105) - Fixed pointerId staying the same when simultaneously releasing and then pressing in the same frame on mobile using touch. [ISXB-1006](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-845) diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs index cd17fdd942..79cfa1b8cb 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs @@ -1476,43 +1476,37 @@ private void ProcessControlStateChange(int mapIndex, int controlIndex, int bindi // If the binding is part of a composite, check for interactions on the composite // itself and give them a first shot at processing the value change. var haveInteractionsOnComposite = false; - var compositeAlreadyTriggered = false; if (bindingStatePtr->isPartOfComposite) { var compositeBindingIndex = bindingStatePtr->compositeOrCompositeBindingIndex; var compositeBindingPtr = &bindingStates[compositeBindingIndex]; - // If the composite has already been triggered from the very same event set a flag so it isn't triggered again. + // If the composite has already been triggered from the very same event, ignore it. // Example: KeyboardState change that includes both A and W key state changes and we're looking // at a WASD composite binding. There's a state change monitor on both the A and the W // key and thus the manager will notify us individually of both changes. However, we // want to perform the action only once. - // NOTE: Do NOT ignore this Event, we still need finish processing the individual button states. - if (!ShouldIgnoreInputOnCompositeBinding(compositeBindingPtr, eventPtr)) - { - // Update magnitude for composite. - var compositeIndex = bindingStates[compositeBindingIndex].compositeOrCompositeBindingIndex; - var compositeContext = new InputBindingCompositeContext - { - m_State = this, - m_BindingIndex = compositeBindingIndex - }; - trigger.magnitude = composites[compositeIndex].EvaluateMagnitude(ref compositeContext); - memory.compositeMagnitudes[compositeIndex] = trigger.magnitude; + if (ShouldIgnoreInputOnCompositeBinding(compositeBindingPtr, eventPtr)) + return; - // Run through interactions on composite. - var interactionCountOnComposite = compositeBindingPtr->interactionCount; - if (interactionCountOnComposite > 0) - { - haveInteractionsOnComposite = true; - ProcessInteractions(ref trigger, - compositeBindingPtr->interactionStartIndex, - interactionCountOnComposite); - } - } - else + // Update magnitude for composite. + var compositeIndex = bindingStates[compositeBindingIndex].compositeOrCompositeBindingIndex; + var compositeContext = new InputBindingCompositeContext + { + m_State = this, + m_BindingIndex = compositeBindingIndex + }; + trigger.magnitude = composites[compositeIndex].EvaluateMagnitude(ref compositeContext); + memory.compositeMagnitudes[compositeIndex] = trigger.magnitude; + + // Run through interactions on composite. + var interactionCountOnComposite = compositeBindingPtr->interactionCount; + if (interactionCountOnComposite > 0) { - compositeAlreadyTriggered = true; + haveInteractionsOnComposite = true; + ProcessInteractions(ref trigger, + compositeBindingPtr->interactionStartIndex, + interactionCountOnComposite); } } @@ -1521,31 +1515,21 @@ private void ProcessControlStateChange(int mapIndex, int controlIndex, int bindi // one of higher magnitude) or may even lead us to switch to processing a different binding // (e.g. when an input of previously greater magnitude has now fallen below the level of another // ongoing input with now higher magnitude). - // - // If Composite has already been triggered, skip this step; it's unnecessary and could also - // cause a processing issue if we switch to another binding. - var isConflictingInput = false; - if (!compositeAlreadyTriggered) - { - isConflictingInput = IsConflictingInput(ref trigger, actionIndex); - bindingStatePtr = &bindingStates[trigger.bindingIndex]; // IsConflictingInput may switch us to a different binding. - } + var isConflictingInput = IsConflictingInput(ref trigger, actionIndex); + bindingStatePtr = &bindingStates[trigger.bindingIndex]; // IsConflictingInput may switch us to a different binding. // Process button presses/releases. - // We MUST execute this processing even if Composite has already been triggered to ensure button states - // are properly updated (ISXB-746) if (!isConflictingInput) ProcessButtonState(ref trigger, actionIndex, bindingStatePtr); // If we have interactions, let them do all the processing. The presence of an interaction // essentially bypasses the default phase progression logic of an action. - // Interactions are skipped if compositeAlreadyTriggered is set. var interactionCount = bindingStatePtr->interactionCount; if (interactionCount > 0 && !bindingStatePtr->isPartOfComposite) { ProcessInteractions(ref trigger, bindingStatePtr->interactionStartIndex, interactionCount); } - else if (!haveInteractionsOnComposite && !isConflictingInput && !compositeAlreadyTriggered) + else if (!haveInteractionsOnComposite && !isConflictingInput) { ProcessDefaultInteraction(ref trigger, actionIndex); } From 747767fa14933f83602836a787b994651a9f5c04 Mon Sep 17 00:00:00 2001 From: Alex Tyrer Date: Wed, 30 Oct 2024 16:55:21 +0000 Subject: [PATCH 2/5] FIX: Fixed ISubmitHandler.OnSubmit event processing when operating in Manual Update mode (case ISXB-1141) (#2041) * [Input System] Fix for event processing when operating in Manual Update mode (case ISXB-1141) * [Input System] Added CHANGELOG.md entry for ISubmitHandler.OnSubmit fix (ISXB-1141) --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + .../InputSystem/Actions/InputAction.cs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index edfb394b39..46029c93de 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -15,6 +15,7 @@ however, it has to be formatted properly to pass verification tests. - Reverted changes from 0ddd534d8 (ISXB-746) which introduced a regression [ISXB-1127](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1127). - Fixed `ArgumentNullException: Value cannot be null.` during the migration of Project-wide Input Actions from `InputManager.asset` to `InputSystem_Actions.inputactions` asset which lead do the lost of the configuration [ISXB-1105](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1105) - Fixed pointerId staying the same when simultaneously releasing and then pressing in the same frame on mobile using touch. [ISXB-1006](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-845) +- Fixed ISubmitHandler.OnSubmit event processing when operating in Manual Update mode (ISXB-1141) ### Changed - Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086) diff --git a/Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs b/Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs index f196465961..4b025827ef 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs @@ -1186,6 +1186,16 @@ public unsafe bool IsInProgress() return false; } + private int ExpectedFrame() + { + // Used by the WasThisFrame() methods below. + // When processing events manually the event processing will happen one frame later. + // + int frameOffset = InputSystem.settings.updateMode == InputSettings.UpdateMode.ProcessEventsManually ? 1 : 0; + int expectedFrame = Time.frameCount - frameOffset; + return expectedFrame; + } + /// /// Returns true if the action's value crossed the press threshold (see ) /// at any point in the frame. @@ -1236,7 +1246,7 @@ public unsafe bool WasPressedThisFrame() { var actionStatePtr = &state.actionStates[m_ActionIndexInState]; var currentUpdateStep = InputUpdate.s_UpdateStepCount; - return actionStatePtr->pressedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == Time.frameCount; + return actionStatePtr->pressedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame(); } return false; @@ -1285,7 +1295,7 @@ public unsafe bool WasReleasedThisFrame() { var actionStatePtr = &state.actionStates[m_ActionIndexInState]; var currentUpdateStep = InputUpdate.s_UpdateStepCount; - return actionStatePtr->releasedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == Time.frameCount; + return actionStatePtr->releasedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame(); } return false; @@ -1344,7 +1354,7 @@ public unsafe bool WasPerformedThisFrame() { var actionStatePtr = &state.actionStates[m_ActionIndexInState]; var currentUpdateStep = InputUpdate.s_UpdateStepCount; - return actionStatePtr->lastPerformedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == Time.frameCount; + return actionStatePtr->lastPerformedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame(); } return false; @@ -1417,7 +1427,7 @@ public unsafe bool WasCompletedThisFrame() { var actionStatePtr = &state.actionStates[m_ActionIndexInState]; var currentUpdateStep = InputUpdate.s_UpdateStepCount; - return actionStatePtr->lastCompletedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == Time.frameCount; + return actionStatePtr->lastCompletedInUpdate == currentUpdateStep && currentUpdateStep != default && actionStatePtr->frame == ExpectedFrame(); } return false; From 4e8347ae838f01b283d331a2e2a3b841d58e72cc Mon Sep 17 00:00:00 2001 From: bmalrat <47957918+bmalrat@users.noreply.github.com> Date: Wed, 30 Oct 2024 16:33:41 -0400 Subject: [PATCH 3/5] FIX: Fixed Rename mode is not entered and name is autocompleted to default when creating a new Action Map on pre 6000 version (#2040) --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + .../Editor/UITKAssetEditor/Views/ActionMapsView.cs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 46029c93de..0da17e078e 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -16,6 +16,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed `ArgumentNullException: Value cannot be null.` during the migration of Project-wide Input Actions from `InputManager.asset` to `InputSystem_Actions.inputactions` asset which lead do the lost of the configuration [ISXB-1105](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1105) - Fixed pointerId staying the same when simultaneously releasing and then pressing in the same frame on mobile using touch. [ISXB-1006](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-845) - Fixed ISubmitHandler.OnSubmit event processing when operating in Manual Update mode (ISXB-1141) +- Fixed Rename mode is not entered and name is autocompleted to default when creating a new Action Map on 2022.3. [ISXB-1151](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1151) ### Changed - Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs index 3eb1d9efab..2659eaabe1 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionMapsView.cs @@ -88,7 +88,13 @@ public override void RedrawUI(ViewState viewState) if (actionMapData.HasValue) m_ListView.SetSelection(viewState.actionMapData.IndexOf(actionMapData.Value)); } + // UI toolkit doesn't behave the same on 6000.0 way when refreshing items + // On previous versions, we need to call Rebuild() to refresh the items since refreshItems() is less predicatable +#if UNITY_6000_0_OR_NEWER m_ListView.RefreshItems(); +#else + m_ListView.Rebuild(); +#endif RenameNewActionMaps(); } From 08349cc7c63e5be7071598346c9905446910b3fc Mon Sep 17 00:00:00 2001 From: bmalrat <47957918+bmalrat@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:35:44 -0500 Subject: [PATCH 4/5] FIX: Fixed unexpected control scheme switch when using `OnScreenControl` and pointer based schemes (ISXB-656) (#2023) --- .../InputSystem/Plugins/OnScreenTests.cs | 27 ++++++++++ .../InputSystem/Plugins/PlayerInputTests.cs | 53 +++++++++++++++++++ Assets/Tests/InputSystem/Plugins/UITests.cs | 5 ++ Packages/com.unity.inputsystem/CHANGELOG.md | 6 +-- .../Plugins/OnScreen/OnScreenControl.cs | 41 ++++++++++++++ .../Plugins/OnScreen/OnScreenStick.cs | 10 ++-- .../Plugins/PlayerInput/PlayerInput.cs | 4 +- 7 files changed, 138 insertions(+), 8 deletions(-) diff --git a/Assets/Tests/InputSystem/Plugins/OnScreenTests.cs b/Assets/Tests/InputSystem/Plugins/OnScreenTests.cs index 4b38382e47..fd24a691b9 100644 --- a/Assets/Tests/InputSystem/Plugins/OnScreenTests.cs +++ b/Assets/Tests/InputSystem/Plugins/OnScreenTests.cs @@ -365,6 +365,33 @@ public void Devices_DisablingLastOnScreenControlRemovesCreatedDevice() Assert.That(InputSystem.devices, Has.None.InstanceOf()); } + [Test] + [Category("Devices")] + public void Devices_DisablingLastOnScreenControlDoesReportActiveControl() + { + var gameObject = new GameObject(); + + Assert.That(OnScreenControl.HasAnyActive, Is.False); + + var buttonA = gameObject.AddComponent(); + + Assert.That(OnScreenControl.HasAnyActive, Is.True); + + var buttonB = gameObject.AddComponent(); + buttonA.controlPath = "//a"; + buttonB.controlPath = "//b"; + + Assert.That(OnScreenControl.HasAnyActive, Is.True); + + buttonA.enabled = false; + + Assert.That(OnScreenControl.HasAnyActive, Is.True); + + buttonB.enabled = false; + + Assert.That(OnScreenControl.HasAnyActive, Is.False); + } + // https://fogbugz.unity3d.com/f/cases/1271942 [UnityTest] [Category("Devices")] diff --git a/Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs b/Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs index 035fc199f8..ece203817b 100644 --- a/Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs +++ b/Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs @@ -17,6 +17,7 @@ using Object = UnityEngine.Object; using Gyroscope = UnityEngine.InputSystem.Gyroscope; using Is = UnityEngine.TestTools.Constraints.Is; +using UnityEngine.InputSystem.OnScreen; /// /// Tests for and . @@ -663,6 +664,58 @@ public void PlayerInput_CanAutoSwitchControlSchemesInSinglePlayer() })); } + [Test] + [Category("PlayerInput")] + public void PlayerInput_AutoSwitchControlSchemesInSinglePlayerWithOnScreenControl_AutoSwitchToTargetDeviceAndIgnoreMouse() + { + var keyboard = InputSystem.AddDevice(); + var mouse = InputSystem.AddDevice(); + + var go = new GameObject(); + + var onScreenButton = go.AddComponent(); + onScreenButton.enabled = false; + onScreenButton.controlPath = "/buttonSouth"; + + var playerInput = go.AddComponent(); + playerInput.defaultControlScheme = "Keyboard&Mouse"; + playerInput.defaultActionMap = "gameplay"; + playerInput.actions = InputActionAsset.FromJson(kActions); + + Assert.That(playerInput.devices, Is.EquivalentTo(new InputDevice[] { keyboard, mouse })); + + // enable the OnScreenButton, it should switch to Gamepad + onScreenButton.enabled = true; + var gamepad = onScreenButton.control.device; + Assert.That(gamepad, Is.TypeOf()); + Assert.That(playerInput.devices, Is.EquivalentTo(new InputDevice[] { gamepad })); + Assert.That(playerInput.user.controlScheme, Is.Not.Null); + Assert.That(playerInput.user.controlScheme.Value.name, Is.EqualTo("Gamepad")); + + // Perform mouse move and click. to try to switch to Keyboard&Mouse scheme + Move(mouse.position, new Vector2(0.123f, 0.234f)); + Click(mouse.leftButton); + Move(mouse.position, new Vector2(100f, 100f)); + InputSystem.Update(); + + // The controlScheme shouldn't have changed + Assert.That(playerInput.devices, Is.EquivalentTo(new[] { gamepad })); + Assert.That(playerInput.user.controlScheme, Is.Not.Null); + Assert.That(playerInput.user.controlScheme.Value.name, Is.EqualTo("Gamepad")); + + // disabling the OnScreenButton to ensure that it will now switch to Keyboard&Mouse as expected + onScreenButton.enabled = false; + + // Perform mouse move and click. to try to switch to Keyboard&Mouse scheme + Move(mouse.position, new Vector2(0.123f, 0.234f)); + Click(mouse.leftButton); + Move(mouse.position, new Vector2(100f, 100f)); + + Assert.That(playerInput.devices, Is.EquivalentTo(new InputDevice[] { keyboard, mouse })); + Assert.That(playerInput.user.controlScheme, Is.Not.Null); + Assert.That(playerInput.user.controlScheme.Value.name, Is.EqualTo("Keyboard&Mouse")); + } + [Test] [Category("PlayerInput")] public void PlayerInput_CanAutoSwitchControlSchemesInSinglePlayer_WithSomeDevicesSharedBetweenSchemes() diff --git a/Assets/Tests/InputSystem/Plugins/UITests.cs b/Assets/Tests/InputSystem/Plugins/UITests.cs index 856517326c..f098df98a6 100644 --- a/Assets/Tests/InputSystem/Plugins/UITests.cs +++ b/Assets/Tests/InputSystem/Plugins/UITests.cs @@ -2630,6 +2630,11 @@ public void UI_ClickDraggingMouseDoesNotAllocateGCMemory() Release(mouse.leftButton); scene.eventSystem.InvokeUpdate(); +#if UNITY_2023_2_OR_NEWER // UnityEngine.InputForUI Module unavailable in earlier releases + // Process all queued UI events to ensure that next events will not make the events list capacity growing + UnityEngine.InputForUI.EventProvider.NotifyUpdate(); +#endif + var kProfilerRegion = "UI_ClickDraggingDoesNotAllocateGCMemory"; // Now for real. diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 0da17e078e..5df223e59d 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -17,9 +17,11 @@ however, it has to be formatted properly to pass verification tests. - Fixed pointerId staying the same when simultaneously releasing and then pressing in the same frame on mobile using touch. [ISXB-1006](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-845) - Fixed ISubmitHandler.OnSubmit event processing when operating in Manual Update mode (ISXB-1141) - Fixed Rename mode is not entered and name is autocompleted to default when creating a new Action Map on 2022.3. [ISXB-1151](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1151) +- Fixed unexpected control scheme switch when using `OnScreenControl` and pointer based schemes which registed "Cancel" event on every frame.[ISXB-656](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-656) ### Changed - Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086) +- 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. ## [1.11.2] - 2024-10-16 @@ -30,14 +32,12 @@ however, it has to be formatted properly to pass verification tests. - Fixed "AnalyticsResult" errors on consoles [ISXB-1107] - Fixed wrong `Display Index` value for touchscreen events.[ISXB-1101](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1101) - Fixed event handling when using Fixed Update processing where WasPressedThisFrame could appear to true for consecutive frames [ISXB-1006](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1006) +- Removed a redundant warning when using fallback code to parse a HID descriptor. (UUM-71260) ### Added - Added the display of the device flag `CanRunInBackground` in device debug view. - Added analytics for programmatic `InputAction` setup via `InputActionSetupExtensions` when exiting play-mode. -### Fixed -- Removed a redundant warning when using fallback code to parse a HID descriptor. (UUM-71260) - ### Changed - Removed the InputManager to InputSystem project-wide asset migration code for performance improvement (ISX-2086) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenControl.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenControl.cs index d1fedda694..06b464802f 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenControl.cs @@ -2,6 +2,7 @@ using Unity.Collections; using UnityEngine.InputSystem.Layouts; using UnityEngine.InputSystem.LowLevel; +using UnityEngine.InputSystem.Users; using UnityEngine.InputSystem.Utilities; ////REVIEW: should we make this ExecuteInEditMode? @@ -34,6 +35,14 @@ namespace UnityEngine.InputSystem.OnScreen /// types of device layouts (e.g. one control references 'buttonWest' on /// a gamepad and another references 'leftButton' on a mouse), then a device /// is created for each type referenced by the setup. + /// + /// The works by simulating events from the device specified in the + /// property. Some parts of the Input System, such as the component, can be set up to + /// auto-switch to a new device when input from them is detected. + /// When a device is switched, any currently running inputs from the previously active device are cancelled. + /// + /// To avoid this situation, you need to ensure, depending on your case, that the Mouse, Pen, Touchsceen and/or XRController devices are not used in a concurent + /// control schemes of the simulated device. /// public abstract class OnScreenControl : MonoBehaviour { @@ -208,13 +217,45 @@ protected void SentDefaultValueToControl() InputSystem.QueueEvent(m_InputEventPtr); } + // Used by PlayerInput auto switch for scheme to prevent using Pointer device. + internal static bool HasAnyActive => s_nbActiveInstances != 0; + private static int s_nbActiveInstances = 0; + protected virtual void OnEnable() { + ++s_nbActiveInstances; SetupInputControl(); + if (m_Control == null) + return; + // if we are in single player and if it the first active switch to the target device. + if (s_nbActiveInstances == 1 && + PlayerInput.isSinglePlayer) + { + var firstPlayer = PlayerInput.GetPlayerByIndex(0); + if (firstPlayer?.neverAutoSwitchControlSchemes == false) + { + var devices = firstPlayer.devices; + bool deviceFound = false; + // skip is the device is already part of the current scheme + foreach (var device in devices) + { + if (m_Control.device.deviceId == device.deviceId) + { + deviceFound = true; + break; + } + } + if (!deviceFound) + { + firstPlayer.SwitchCurrentControlScheme(m_Control.device); + } + } + } } protected virtual void OnDisable() { + --s_nbActiveInstances; if (m_Control == null) return; diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenStick.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenStick.cs index 629f94beb8..c226926a02 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenStick.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenStick.cs @@ -23,13 +23,15 @@ namespace UnityEngine.InputSystem.OnScreen /// /// The works by simulating events from the device specified in the /// property. Some parts of the Input System, such as the component, can be set up to - /// auto-switch to a new device when input from them is detected. When a device is switched, any currently running - /// inputs from the previously active device are cancelled. In the case of , this can mean that the - /// method will be called and the stick will jump back to center, even though - /// the pointer input has not physically been released. + /// auto-switch to a new device when input from them is detected. + /// When a device is switched, any currently running inputs from the previously active device are cancelled. + /// In the case of , this can mean that the method will be called + /// and the stick will jump back to center, even though the pointer input has not physically been released. /// /// To avoid this situation, set the property to true. This will create a set of local /// Input Actions to drive the stick that are not cancelled when device switching occurs. + /// You might also need to ensure, depending on your case, that the Mouse, Pen, Touchsceen and/or XRController devices are not used in a concurent + /// control schemes of the simulated device. /// [AddComponentMenu("Input/On-Screen Stick")] [HelpURL(InputSystem.kDocUrl + "/manual/OnScreen.html#on-screen-sticks")] diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInput.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInput.cs index df23a4ff96..ce27ff2620 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInput.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInput.cs @@ -4,6 +4,7 @@ using UnityEngine.InputSystem.LowLevel; using UnityEngine.InputSystem.Users; using UnityEngine.InputSystem.Utilities; +using UnityEngine.InputSystem.OnScreen; #if UNITY_EDITOR using UnityEngine.InputSystem.Editor; @@ -1867,7 +1868,8 @@ private static bool OnPreFilterUnpairedDeviceUsed(InputDevice device, InputEvent { // Early out if the device isn't usable with any of our control schemes. var actions = all[0].actions; - return actions != null && actions.IsUsableWithDevice(device); + // Skip Pointer device if any OnScreenControl is active since they will use it to generate device event + return actions != null && (!OnScreenControl.HasAnyActive || !(device is Pointer)) && actions.IsUsableWithDevice(device); } private void OnUnpairedDeviceUsed(InputControl control, InputEventPtr eventPtr) From 12ee89a3f55d490bd9a5819346717c7b6f763432 Mon Sep 17 00:00:00 2001 From: Alex Tyrer Date: Wed, 6 Nov 2024 17:18:09 +0000 Subject: [PATCH 5/5] FIX: The "Add Control Scheme..." popup now requires explicit Save/Close user action (case ISXB-1131) (#2044) * [Input System] The "Add Control Scheme..." popup now requires explicit Save/Close user action (case ISXB-1131) o Previously clicking outside the popup window (anywhere in the editor) would close the popup window. o This would leave a new blank (unnamed, orphaned) control scheme populating the UI - this was confusing. o Now this popup will persist until the user explictly chooses to Save or Cancel. * [Input System] Added CHANGELOG entry for "Add Control Scheme..." popup fix (case ISXB-1131) * [Input System] Fix typo in CHANGELOG entry - removed extraneous final closing parenthesis. * [Input System] Licensing failure - try limiting to version 2021.3.45f --- .yamato/config.metadata | 2 +- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + .../Editor/UITKAssetEditor/Views/ControlSchemesView.cs | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.yamato/config.metadata b/.yamato/config.metadata index fb0b5355cf..4e88db5dc1 100644 --- a/.yamato/config.metadata +++ b/.yamato/config.metadata @@ -1,5 +1,5 @@ editors: - - version: 2021.3 + - version: 2021.3.45f - version: 2022.3 disable_tvos_run: true - version: 6000.0 diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 5df223e59d..caf4b4ec58 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -18,6 +18,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed ISubmitHandler.OnSubmit event processing when operating in Manual Update mode (ISXB-1141) - Fixed Rename mode is not entered and name is autocompleted to default when creating a new Action Map on 2022.3. [ISXB-1151](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1151) - Fixed unexpected control scheme switch when using `OnScreenControl` and pointer based schemes which registed "Cancel" event on every frame.[ISXB-656](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-656) +- Fixed an issue with The "Add Control Scheme..." popup window so that it now persists until any changes are explicitly Saved or Cancelled [case ISXB-1131](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1131) ### Changed - Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs index 86db5db1d5..e6e7e58e5f 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ControlSchemesView.cs @@ -63,7 +63,6 @@ public ControlSchemesView(VisualElement root, StateContainer stateContainer, boo m_ModalWindow.Add(popupWindow); root.Add(m_ModalWindow); m_ModalWindow.StretchToParentSize(); - m_ModalWindow.RegisterCallback(evt => CloseView()); popupWindow.RegisterCallback(evt => evt.StopPropagation()); m_ListView = controlSchemeVisualElement.Q(kControlSchemesListView);