diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 5ac5574df8..cffab2f0af 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -49,6 +49,7 @@ however, it has to be formatted properly to pass verification tests. ### Added - Added new API `InputSystem.settings.useIMGUIEditorForAssets` that should be used in custom `InputParameterEditor` that use both IMGUI and UI Toolkit. - Added ProfilerMakers to `InputAction.Enable()` and `InputActionMap.ResolveBindings()` to enable gathering of profiling data. +- Added throwing an error message when trying to use the Input System package on console without the extension package installed. ## [1.11.2] - 2024-10-16 diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs new file mode 100644 index 0000000000..ad82d8bd5d --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs @@ -0,0 +1,98 @@ +#if ((UNITY_EDITOR && UNITY_2021_1_OR_NEWER) || PACKAGE_DOCS_GENERATION) +using System; +using System.Collections.Generic; +using UnityEditor; + +namespace UnityEngine.InputSystem.Editor +{ + /// + /// This class controls all required plugins and extension packages are installed for the InputSystem. + /// + /// + /// For some platforms, the InputSystem requires additional plugins to be installed. This class checks if the required plugins are installed and throws a warning if they are not. + /// + public class InputSystemPluginControl + { + // Input system platform specific classes register with the input system via a class using InitializeOnLoad on static constructors. + // Static constructors in classes that are tagged with the InitializeOnLoad attribute are called before methods using the InitializeOnLoadMethod attribute. + // So the extra input system packages will be registered before this check which is done in InitializeOnLoadMethod. + [InitializeOnLoadMethod] + private static void CheckForExtension() + { + ThrowWarningOnMissingPlugin(); + } + + // This static HashSet will be reset OnDomainReload and so it will be reset every Domain Reload (at the time of InitializeOnLoad). + // This is pre-populated with the list of platforms that don't need a extra platform specific input system package to add platform specific functionality. + private static HashSet s_supportedBuildTargets = new HashSet() + { + BuildTarget.StandaloneOSX, + BuildTarget.StandaloneWindows, + BuildTarget.iOS, + BuildTarget.Android, + BuildTarget.StandaloneWindows64, + BuildTarget.WebGL, + BuildTarget.WSAPlayer, + BuildTarget.StandaloneLinux64, + BuildTarget.tvOS, + BuildTarget.LinuxHeadlessSimulation, + BuildTarget.EmbeddedLinux, + #if UNITY_2022_1_OR_NEWER + BuildTarget.QNX, + #endif + #if UNITY_2023_3_OR_NEWER + BuildTarget.VisionOS, + #endif + #if UNITY_6000_0_OR_NEWER + BuildTarget.ReservedCFE, + #endif + #if UNITY_6000_0_7_OR_NEWER + BuildTarget.Kepler + #endif + BuildTarget.NoTarget + }; + + static bool BuildTargetNeedsPlugin() + { + BuildTarget target = EditorUserBuildSettings.activeBuildTarget; + foreach (var platform in s_supportedBuildTargets) + { + if (platform == target) return false; + } + return true; + } + + private const string PlugInName = "com.unity.inputsystem."; + + /// + /// Used to register extensions externally to the InputSystem, this is needed for all Platforms that require a plugin to be installed. + /// + /// + /// This method is internally called by the InputSystem package extensions to register the PlugIn. This can be called for custom extensions on custom platforms. + /// + public static void RegisterPlatform(BuildTarget target) + { + s_supportedBuildTargets.Add(target); + } + + private static bool IsPluginInstalled() + { + var registeredPackages = UnityEditor.PackageManager.PackageInfo.GetAllRegisteredPackages(); + var plugInName = PlugInName + EditorUserBuildSettings.activeBuildTarget.ToString().ToLower(); + foreach (var package in registeredPackages) + { + if (package.name.Equals(plugInName)) + return true; + } + return false; + } + + private static void ThrowWarningOnMissingPlugin() + { + if (!BuildTargetNeedsPlugin()) + return; + Debug.Assert(IsPluginInstalled(), "Active Input Handling is set to InputSystem, but no Plugin for " + EditorUserBuildSettings.activeBuildTarget + " was found. Please install the missing InputSystem package extensions."); + } + } +} +#endif diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs.meta b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs.meta new file mode 100644 index 0000000000..2651f61c2b --- /dev/null +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 409c8128e33f94c378370cd8163fe3b0 \ No newline at end of file