From 73b7bcb5889cfcf17ed83ee7a9c33b5cab8db441 Mon Sep 17 00:00:00 2001 From: Rita Merkl Date: Fri, 22 Nov 2024 15:00:35 +0100 Subject: [PATCH 01/10] set active input handler to InputManager when package is removed --- .../Editor/InputSystemPackageControl.cs | 50 +++++++++++++++++++ .../Editor/InputSystemPackageControl.cs.meta | 2 + 2 files changed, 52 insertions(+) create mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs create mode 100644 Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs.meta diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs new file mode 100644 index 0000000000..cd4f084995 --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs @@ -0,0 +1,50 @@ +#if UNITY_EDITOR +using System; +using System.Collections.ObjectModel; +using UnityEditor; +using UnityEditor.PackageManager; + + +namespace UnityEngine.InputSystem.Editor +{ + /// + /// Force restart if InputSystem package is added to activate and initialize it on managed side. + /// Set Project Settings input handling to reflect the presence of the Input System package, since it is not available in the UI. + /// + internal class InputSystemPackageControl + { + const string packageName = "com.unity.inputsystem"; + + [InitializeOnLoadMethod] + static void SubscribePackageManagerEvent() + { + //there's a number of cases where it might not be called, for instance if the user changed the project manifest and deleted the Library folder before opening the project + UnityEditor.PackageManager.Events.registeringPackages += CheckForInputSystemPackageRemoved; + } + + private static void CheckForInputSystemPackageRemoved(PackageRegistrationEventArgs packageArgs) + { + if (InputSystemAddedRemoved(packageArgs.removed)) + HandleInputSystemRemoved(); + } + + private static bool InputSystemAddedRemoved(ReadOnlyCollection packages) + { + foreach (var package in packages) + { + if (package.name == packageName) + return true; + } + return false; + } + + private static void HandleInputSystemRemoved() + { + //set input handling to none + EditorPlayerSettingHelpers.newSystemBackendsEnabled = false; + if (EditorUtility.DisplayDialog("Unity editor restart required", "You've removed the input system package. This requires a restart of the Editor.", "Restart Editor", "Ignore (Not recommended)")) + EditorApplication.OpenProject(Environment.CurrentDirectory); + } + } +} +#endif diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs.meta new file mode 100644 index 0000000000..bd16b2d4b4 --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 40a0b3d771450454796d773d18ae0c31 \ No newline at end of file From 7ed68d91e3506eef99661745c1197e2465996720 Mon Sep 17 00:00:00 2001 From: Rita Merkl Date: Fri, 22 Nov 2024 15:44:03 +0100 Subject: [PATCH 02/10] small fixes in comments and names --- .../InputSystem/Editor/InputSystemPackageControl.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs index cd4f084995..64be42c627 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs @@ -8,8 +8,8 @@ namespace UnityEngine.InputSystem.Editor { /// - /// Force restart if InputSystem package is added to activate and initialize it on managed side. - /// Set Project Settings input handling to reflect the presence of the Input System package, since it is not available in the UI. + /// Force restart if InputSystem package is removed to activate and initialize it on managed side. + /// Set Project Settings input handling to InputManager once the package is removed. /// internal class InputSystemPackageControl { @@ -24,11 +24,11 @@ static void SubscribePackageManagerEvent() private static void CheckForInputSystemPackageRemoved(PackageRegistrationEventArgs packageArgs) { - if (InputSystemAddedRemoved(packageArgs.removed)) + if (IsInputSystemRemoved(packageArgs.removed)) HandleInputSystemRemoved(); } - private static bool InputSystemAddedRemoved(ReadOnlyCollection packages) + private static bool IsInputSystemRemoved(ReadOnlyCollection packages) { foreach (var package in packages) { @@ -40,7 +40,7 @@ private static bool InputSystemAddedRemoved(ReadOnlyCollection Date: Fri, 22 Nov 2024 15:49:54 +0100 Subject: [PATCH 03/10] added changelog --- 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 3cde95ec9e..b06fb56b65 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -24,6 +24,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed pasting bindings into empty Input Action asset. [ISXB-1180](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1180) - Fixed missing '&' symbol in Control Scheme dropdown on Windows platform. [ISXB-1109](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1109) - Fixed icon scaling in Input Actions window. +- Fixed an issue where removing the InputSystem package could lead to invalid input handling settings. ### Changed - Added back the InputManager to InputSystem project-wide asset migration code with performance improvement (ISX-2086). From ad67dcbb33fe7001bf1ba0cc4df6022956c69156 Mon Sep 17 00:00:00 2001 From: Rita Merkl Date: Mon, 25 Nov 2024 11:20:33 +0100 Subject: [PATCH 04/10] comments fix --- .../InputSystem/Editor/InputSystemPackageControl.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs index 64be42c627..c54f7ae7db 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs @@ -2,7 +2,6 @@ using System; using System.Collections.ObjectModel; using UnityEditor; -using UnityEditor.PackageManager; namespace UnityEngine.InputSystem.Editor @@ -18,11 +17,11 @@ internal class InputSystemPackageControl [InitializeOnLoadMethod] static void SubscribePackageManagerEvent() { - //there's a number of cases where it might not be called, for instance if the user changed the project manifest and deleted the Library folder before opening the project + //There's a number of cases where it might not be called, for instance if the user changed the project manifest and deleted the Library folder before opening the project UnityEditor.PackageManager.Events.registeringPackages += CheckForInputSystemPackageRemoved; } - private static void CheckForInputSystemPackageRemoved(PackageRegistrationEventArgs packageArgs) + private static void CheckForInputSystemPackageRemoved(UnityEditor.PackageManager.PackageRegistrationEventArgs packageArgs) { if (IsInputSystemRemoved(packageArgs.removed)) HandleInputSystemRemoved(); @@ -40,7 +39,7 @@ private static bool IsInputSystemRemoved(ReadOnlyCollection Date: Mon, 25 Nov 2024 11:21:29 +0100 Subject: [PATCH 05/10] Fix for restart editor dialog text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Freire --- .../InputSystem/Editor/InputSystemPackageControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs index c54f7ae7db..0919ba5d34 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs @@ -41,7 +41,7 @@ private static void HandleInputSystemRemoved() { //Set input handling to InputManager EditorPlayerSettingHelpers.newSystemBackendsEnabled = false; - if (EditorUtility.DisplayDialog("Unity editor restart required", "You've removed the input system package. This requires a restart of the Editor.", "Restart Editor", "Ignore (Not recommended)")) + if (EditorUtility.DisplayDialog("The Unity Editor needs to be restarted", "You've removed the Input System package. This requires a restart of the Unity Editor.", "Restart the Editor", "Ignore (Not recommended)")) EditorApplication.OpenProject(Environment.CurrentDirectory); } } From 045b4bf30d01c2469915722970f485e745b57b3b Mon Sep 17 00:00:00 2001 From: Rita Merkl <127492464+ritamerkl@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:21:43 +0100 Subject: [PATCH 06/10] Fix on comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Freire --- .../InputSystem/Editor/InputSystemPackageControl.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs index 0919ba5d34..3ae95742f8 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs @@ -7,8 +7,8 @@ namespace UnityEngine.InputSystem.Editor { /// - /// Force restart if InputSystem package is removed to activate and initialize it on managed side. - /// Set Project Settings input handling to InputManager once the package is removed. + /// Forces the Editor to restart if the InputSystem package is removed to activate and initialize it on the managed side. + /// Automatically sets "Project Settings > Player > Active Input Handling" to "Input Manager" once the package is removed. /// internal class InputSystemPackageControl { From ad8f26dd29fb8f66cdba0f716bbfaf8a8403f787 Mon Sep 17 00:00:00 2001 From: Rita Merkl Date: Mon, 25 Nov 2024 11:45:39 +0100 Subject: [PATCH 07/10] add namespace --- .../InputSystem/Editor/InputSystemPackageControl.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs index 3ae95742f8..13db952543 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs @@ -2,7 +2,8 @@ using System; using System.Collections.ObjectModel; using UnityEditor; - +using UnityEditor.PackageManager; +using PackageInfo = UnityEditor.PackageInfo; namespace UnityEngine.InputSystem.Editor { From 232a0179c89990e7e4d19a824e32c58e79306416 Mon Sep 17 00:00:00 2001 From: Rita Merkl Date: Mon, 25 Nov 2024 13:37:22 +0100 Subject: [PATCH 08/10] updated with package manager dependency --- .../InputSystem/Editor/InputSystemPackageControl.cs | 3 +-- Packages/com.unity.inputsystem/package.json | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs index 13db952543..dd9e6dccd8 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs @@ -3,7 +3,6 @@ using System.Collections.ObjectModel; using UnityEditor; using UnityEditor.PackageManager; -using PackageInfo = UnityEditor.PackageInfo; namespace UnityEngine.InputSystem.Editor { @@ -22,7 +21,7 @@ static void SubscribePackageManagerEvent() UnityEditor.PackageManager.Events.registeringPackages += CheckForInputSystemPackageRemoved; } - private static void CheckForInputSystemPackageRemoved(UnityEditor.PackageManager.PackageRegistrationEventArgs packageArgs) + private static void CheckForInputSystemPackageRemoved(PackageRegistrationEventArgs packageArgs) { if (IsInputSystemRemoved(packageArgs.removed)) HandleInputSystemRemoved(); diff --git a/Packages/com.unity.inputsystem/package.json b/Packages/com.unity.inputsystem/package.json index 30751e47ba..8469324b59 100755 --- a/Packages/com.unity.inputsystem/package.json +++ b/Packages/com.unity.inputsystem/package.json @@ -15,6 +15,7 @@ "xr" ], "dependencies" : { - "com.unity.modules.uielements": "1.0.0" + "com.unity.modules.uielements": "1.0.0", + "com.unity.modules.packagemanager": "1.0.0" } } From 6d7cf65cdd7fb9f2e754793b7beabba0c89609c4 Mon Sep 17 00:00:00 2001 From: Rita Merkl Date: Mon, 25 Nov 2024 14:08:16 +0100 Subject: [PATCH 09/10] undo update dependencies --- Packages/com.unity.inputsystem/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Packages/com.unity.inputsystem/package.json b/Packages/com.unity.inputsystem/package.json index 8469324b59..30751e47ba 100755 --- a/Packages/com.unity.inputsystem/package.json +++ b/Packages/com.unity.inputsystem/package.json @@ -15,7 +15,6 @@ "xr" ], "dependencies" : { - "com.unity.modules.uielements": "1.0.0", - "com.unity.modules.packagemanager": "1.0.0" + "com.unity.modules.uielements": "1.0.0" } } From 44f193b4905997d59ee746ac81997c2e92933c39 Mon Sep 17 00:00:00 2001 From: Rita Merkl Date: Mon, 25 Nov 2024 16:39:07 +0100 Subject: [PATCH 10/10] make fix available for 2020.2 and newer --- .../InputSystem/Editor/InputSystemPackageControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs index dd9e6dccd8..8fba9fe05f 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs @@ -1,4 +1,4 @@ -#if UNITY_EDITOR +#if UNITY_EDITOR && UNITY_2020_2_OR_NEWER using System; using System.Collections.ObjectModel; using UnityEditor;