From 33cb8f411e8f1a1aed656d3e63c10c972282c2e7 Mon Sep 17 00:00:00 2001 From: jak Date: Fri, 7 Mar 2025 14:57:44 +0000 Subject: [PATCH 1/2] Moved 'InputActionAsset' out of InputSystemProvider.Configuration, made the action strings readonly and renamed the class 'Actions', Added reused DefaultInputActions field to InputSystemProvider and added new 'SelectInputActionAsset' method to select the input asset used (either project wide asset or default input actions), Renamed 'RegisterNextPreviousAction' to 'RegisterFixedActions' to better mirror method used to unregister these actions - moved these methods to be called in Initialize / Shutdown to avoid re-registering when not required, Simplified InputActionAssetVerifier.Verify now that configuration action strings are statically known (an instance of the struct is no longer required) --- .../InputForUI/InputActionAssetVerifier.cs | 42 +++---- .../Plugins/InputForUI/InputSystemProvider.cs | 108 +++++++++--------- 2 files changed, 69 insertions(+), 81 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputActionAssetVerifier.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputActionAssetVerifier.cs index e518f09932..f42433be8b 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputActionAssetVerifier.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputActionAssetVerifier.cs @@ -32,9 +32,23 @@ static InputActionAssetVerifier() public void Verify(InputActionAsset asset, ProjectWideActionsAsset.IReportInputActionAssetVerificationErrors reporter) { - // Note that we never cache this to guarantee we have the current configuration. - var config = InputSystemProvider.Configuration.GetDefaultConfiguration(); - Verify(asset, ref config, reporter); + // Note: + // PWA has initial state check true for "Point" action, DefaultActions do not, does it matter? + // + // Additionally note that "Submit" and "Cancel" are indirectly expected to be of Button action type. + // This is not available in UI configuration, but InputActionRebindingExtensions suggests this. + // + // Additional "LeftClick" has initial state check set in PWA, but not "MiddleClick" and "RightClick". + // Is this intentional? Are requirements different? + var context = new Context(asset, reporter, DefaultReportPolicy); + context.Verify(actionNameOrId: InputSystemProvider.Actions.PointAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2)); + context.Verify(actionNameOrId: InputSystemProvider.Actions.MoveAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2)); + context.Verify(actionNameOrId: InputSystemProvider.Actions.SubmitAction, actionType: InputActionType.Button, expectedControlType: "Button"); + context.Verify(actionNameOrId: InputSystemProvider.Actions.CancelAction, actionType: InputActionType.Button, expectedControlType: "Button"); + context.Verify(actionNameOrId: InputSystemProvider.Actions.LeftClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button"); + context.Verify(actionNameOrId: InputSystemProvider.Actions.MiddleClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button"); + context.Verify(actionNameOrId: InputSystemProvider.Actions.RightClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button"); + context.Verify(actionNameOrId: InputSystemProvider.Actions.ScrollWheelAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2)); } #endregion @@ -111,28 +125,6 @@ public void Verify(string actionNameOrId, InputActionType actionType, string exp private HashSet missingPaths; // Avoids generating multiple warnings around missing map private ReportPolicy policy; } - - private static void Verify(InputActionAsset asset, ref InputSystemProvider.Configuration config, - ProjectWideActionsAsset.IReportInputActionAssetVerificationErrors reporter) - { - // Note: - // PWA has initial state check true for "Point" action, DefaultActions do not, does it matter? - // - // Additionally note that "Submit" and "Cancel" are indirectly expected to be of Button action type. - // This is not available in UI configuration, but InputActionRebindingExtensions suggests this. - // - // Additional "LeftClick" has initial state check set in PWA, but not "MiddleClick" and "RightClick". - // Is this intentional? Are requirements different? - var context = new Context(asset, reporter, DefaultReportPolicy); - context.Verify(actionNameOrId: config.PointAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2)); - context.Verify(actionNameOrId: config.MoveAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2)); - context.Verify(actionNameOrId: config.SubmitAction, actionType: InputActionType.Button, expectedControlType: "Button"); - context.Verify(actionNameOrId: config.CancelAction, actionType: InputActionType.Button, expectedControlType: "Button"); - context.Verify(actionNameOrId: config.LeftClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button"); - context.Verify(actionNameOrId: config.MiddleClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button"); - context.Verify(actionNameOrId: config.RightClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button"); - context.Verify(actionNameOrId: config.ScrollWheelAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2)); - } } } diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputSystemProvider.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputSystemProvider.cs index 9cb34c56a4..98dec05a6b 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputSystemProvider.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/InputForUI/InputSystemProvider.cs @@ -13,10 +13,9 @@ namespace UnityEngine.InputSystem.Plugins.InputForUI internal class InputSystemProvider : IEventProviderImpl { - Configuration m_Cfg; - InputEventPartialProvider m_InputEventPartialProvider; + DefaultInputActions m_DefaultInputActions; InputActionAsset m_InputActionAsset; InputActionReference m_PointAction; @@ -86,28 +85,37 @@ public void Initialize() m_TouchState.Reset(); m_SeenTouchEvents = false; - m_Cfg = Configuration.GetDefaultConfiguration(); - + SelectInputActionAsset(); RegisterActions(); + // TODO make it configurable as it is not part of default config + // The Next/Previous action is not part of the input actions asset + RegisterFixedActions(); + InputSystem.onActionsChange += OnActionsChange; } public void Shutdown() { UnregisterActions(); + UnregisterFixedActions(); m_InputEventPartialProvider.Shutdown(); m_InputEventPartialProvider = null; + if (m_DefaultInputActions != null) + { + m_DefaultInputActions.Dispose(); + m_DefaultInputActions = null; + } + InputSystem.onActionsChange -= OnActionsChange; } public void OnActionsChange() { UnregisterActions(); - - m_Cfg = Configuration.GetDefaultConfiguration(); + SelectInputActionAsset(); RegisterActions(); } @@ -584,7 +592,7 @@ void OnScrollWheelPerformed(InputAction.CallbackContext ctx) })); } - void RegisterNextPreviousAction() + void RegisterFixedActions() { m_NextPreviousAction = new InputAction(name: "nextPreviousAction", type: InputActionType.Button); // TODO add more default bindings, or make them configurable @@ -604,19 +612,17 @@ void UnregisterFixedActions() void RegisterActions() { - m_InputActionAsset = m_Cfg.ActionAsset; - // Invoke potential lister observing registration s_OnRegisterActions?.Invoke(m_InputActionAsset); - m_PointAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.PointAction)); - m_MoveAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.MoveAction)); - m_SubmitAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.SubmitAction)); - m_CancelAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.CancelAction)); - m_LeftClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.LeftClickAction)); - m_MiddleClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.MiddleClickAction)); - m_RightClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.RightClickAction)); - m_ScrollWheelAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.ScrollWheelAction)); + m_PointAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.PointAction)); + m_MoveAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.MoveAction)); + m_SubmitAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.SubmitAction)); + m_CancelAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.CancelAction)); + m_LeftClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.LeftClickAction)); + m_MiddleClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.MiddleClickAction)); + m_RightClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.RightClickAction)); + m_ScrollWheelAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.ScrollWheelAction)); if (m_PointAction != null && m_PointAction.action != null) m_PointAction.action.performed += OnPointerPerformed; @@ -648,10 +654,6 @@ void RegisterActions() } else m_InputActionAsset.Enable(); - - // TODO make it configurable as it is not part of default config - // The Next/Previous action is not part of the input actions asset - RegisterNextPreviousAction(); } void UnregisterActions() @@ -688,49 +690,43 @@ void UnregisterActions() if (m_InputActionAsset != null) m_InputActionAsset.Disable(); - - UnregisterFixedActions(); } - public struct Configuration + void SelectInputActionAsset() { - public InputActionAsset ActionAsset; - public string PointAction; - public string MoveAction; - public string SubmitAction; - public string CancelAction; - public string LeftClickAction; - public string MiddleClickAction; - public string RightClickAction; - public string ScrollWheelAction; + // Only use default actions asset configuration if (ISX-1954): + // - Project-wide Input Actions have not been configured, OR + // - Project-wide Input Actions have been configured but contains no UI action map. + var projectWideInputActions = InputSystem.actions; + var useProjectWideInputActions = + projectWideInputActions != null && + projectWideInputActions.FindActionMap("UI") != null; - public static Configuration GetDefaultConfiguration() + // Use InputSystem.actions (Project-wide Actions) if available, else use default asset if + // user didn't specifically set one, so that UI functions still work (ISXB-811). + if (useProjectWideInputActions) + m_InputActionAsset = InputSystem.actions; + else { - // Only use default actions asset configuration if (ISX-1954): - // - Project-wide Input Actions have not been configured, OR - // - Project-wide Input Actions have been configured but contains no UI action map. - var projectWideInputActions = InputSystem.actions; - var useProjectWideInputActions = - projectWideInputActions != null && - projectWideInputActions.FindActionMap("UI") != null; - - // Use InputSystem.actions (Project-wide Actions) if available, else use default asset if - // user didn't specifically set one, so that UI functions still work (ISXB-811). - return new Configuration - { - ActionAsset = useProjectWideInputActions ? InputSystem.actions : new DefaultInputActions().asset, - PointAction = "UI/Point", - MoveAction = "UI/Navigate", - SubmitAction = "UI/Submit", - CancelAction = "UI/Cancel", - LeftClickAction = "UI/Click", - MiddleClickAction = "UI/MiddleClick", - RightClickAction = "UI/RightClick", - ScrollWheelAction = "UI/ScrollWheel", - }; + if (m_DefaultInputActions is null) + m_DefaultInputActions = new DefaultInputActions(); + + m_InputActionAsset = m_DefaultInputActions.asset; } } + public static class Actions + { + public readonly static string PointAction = "UI/Point"; + public readonly static string MoveAction = "UI/Navigate"; + public readonly static string SubmitAction = "UI/Submit"; + public readonly static string CancelAction = "UI/Cancel"; + public readonly static string LeftClickAction = "UI/Click"; + public readonly static string MiddleClickAction = "UI/MiddleClick"; + public readonly static string RightClickAction = "UI/RightClick"; + public readonly static string ScrollWheelAction = "UI/ScrollWheel"; + } + internal static void SetOnRegisterActions(Action callback) { s_OnRegisterActions = callback; From 9fbe8410c38a3fb72b6e51db8ab897e2a7fca7f9 Mon Sep 17 00:00:00 2001 From: jak Date: Fri, 7 Mar 2025 15:20:45 +0000 Subject: [PATCH 2/2] Added changelog entry --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 40e1aaf6de..ba91f2b476 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -19,6 +19,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed an issue where ButtonStates are not fully updated when switching SingleUnifiedPointer. [ISXB-1356](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1356) - Fixed errors when pasting composite parts into non-composites. [ISXB-757](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-757) - Fixed an issue where updating the InputSystem outside of the dynamic Update would lead to UI input and navigation events get lost. [ISXB-1313](https://issuetracker.unity3d.com/issues/ui-onclick-events-sometimes-do-not-trigger-when-manual-update-is-utilized-with-input-system) +- Fixed an issue causing a number of errors to be displayed when using `InputTestFixture` in playmode tests with domain reloading disabled on playmode entry [ISXB-1446](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1446) ### Changed - Changed enum value `Key.IMESelected` to obsolete which was not a real key. Please use the ButtonControl `imeSelected`.