diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 07dc81f070..8cd2fc389f 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. - Fixed `ArgumentOutOfRangeException` when adding a new Control Scheme with any Device selected. [ISXB-1129](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1129) ### Changed 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..8fba9fe05f --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.cs @@ -0,0 +1,49 @@ +#if UNITY_EDITOR && UNITY_2020_2_OR_NEWER +using System; +using System.Collections.ObjectModel; +using UnityEditor; +using UnityEditor.PackageManager; + +namespace UnityEngine.InputSystem.Editor +{ + /// + /// 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 + { + 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 (IsInputSystemRemoved(packageArgs.removed)) + HandleInputSystemRemoved(); + } + + private static bool IsInputSystemRemoved(ReadOnlyCollection packages) + { + foreach (var package in packages) + { + if (package.name == packageName) + return true; + } + return false; + } + + private static void HandleInputSystemRemoved() + { + //Set input handling to InputManager + EditorPlayerSettingHelpers.newSystemBackendsEnabled = false; + 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); + } + } +} +#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