Skip to content

Commit b850953

Browse files
authored
NEW: Throw error when extension for inputsystem needed (#2101)
1 parent 58bd3ec commit b850953

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ however, it has to be formatted properly to pass verification tests.
4949
### Added
5050
- Added new API `InputSystem.settings.useIMGUIEditorForAssets` that should be used in custom `InputParameterEditor` that use both IMGUI and UI Toolkit.
5151
- Added ProfilerMakers to `InputAction.Enable()` and `InputActionMap.ResolveBindings()` to enable gathering of profiling data.
52+
- Added throwing an error message when trying to use the Input System package on console without the extension package installed.
5253

5354
## [1.11.2] - 2024-10-16
5455

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#if ((UNITY_EDITOR && UNITY_2021_1_OR_NEWER) || PACKAGE_DOCS_GENERATION)
2+
using System;
3+
using System.Collections.Generic;
4+
using UnityEditor;
5+
6+
namespace UnityEngine.InputSystem.Editor
7+
{
8+
/// <summary>
9+
/// This class controls all required plugins and extension packages are installed for the InputSystem.
10+
/// </summary>
11+
/// <remarks>
12+
/// 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.
13+
/// </remarks>
14+
public class InputSystemPluginControl
15+
{
16+
// Input system platform specific classes register with the input system via a class using InitializeOnLoad on static constructors.
17+
// Static constructors in classes that are tagged with the InitializeOnLoad attribute are called before methods using the InitializeOnLoadMethod attribute.
18+
// So the extra input system packages will be registered before this check which is done in InitializeOnLoadMethod.
19+
[InitializeOnLoadMethod]
20+
private static void CheckForExtension()
21+
{
22+
ThrowWarningOnMissingPlugin();
23+
}
24+
25+
// This static HashSet will be reset OnDomainReload and so it will be reset every Domain Reload (at the time of InitializeOnLoad).
26+
// 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.
27+
private static HashSet<BuildTarget> s_supportedBuildTargets = new HashSet<BuildTarget>()
28+
{
29+
BuildTarget.StandaloneOSX,
30+
BuildTarget.StandaloneWindows,
31+
BuildTarget.iOS,
32+
BuildTarget.Android,
33+
BuildTarget.StandaloneWindows64,
34+
BuildTarget.WebGL,
35+
BuildTarget.WSAPlayer,
36+
BuildTarget.StandaloneLinux64,
37+
BuildTarget.tvOS,
38+
BuildTarget.LinuxHeadlessSimulation,
39+
BuildTarget.EmbeddedLinux,
40+
#if UNITY_2022_1_OR_NEWER
41+
BuildTarget.QNX,
42+
#endif
43+
#if UNITY_2023_3_OR_NEWER
44+
BuildTarget.VisionOS,
45+
#endif
46+
#if UNITY_6000_0_OR_NEWER
47+
BuildTarget.ReservedCFE,
48+
#endif
49+
#if UNITY_6000_0_7_OR_NEWER
50+
BuildTarget.Kepler
51+
#endif
52+
BuildTarget.NoTarget
53+
};
54+
55+
static bool BuildTargetNeedsPlugin()
56+
{
57+
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
58+
foreach (var platform in s_supportedBuildTargets)
59+
{
60+
if (platform == target) return false;
61+
}
62+
return true;
63+
}
64+
65+
private const string PlugInName = "com.unity.inputsystem.";
66+
67+
/// <summary>
68+
/// Used to register extensions externally to the InputSystem, this is needed for all Platforms that require a plugin to be installed.
69+
/// </summary>
70+
/// <remarks>
71+
/// This method is internally called by the InputSystem package extensions to register the PlugIn. This can be called for custom extensions on custom platforms.
72+
/// </remarks>
73+
public static void RegisterPlatform(BuildTarget target)
74+
{
75+
s_supportedBuildTargets.Add(target);
76+
}
77+
78+
private static bool IsPluginInstalled()
79+
{
80+
var registeredPackages = UnityEditor.PackageManager.PackageInfo.GetAllRegisteredPackages();
81+
var plugInName = PlugInName + EditorUserBuildSettings.activeBuildTarget.ToString().ToLower();
82+
foreach (var package in registeredPackages)
83+
{
84+
if (package.name.Equals(plugInName))
85+
return true;
86+
}
87+
return false;
88+
}
89+
90+
private static void ThrowWarningOnMissingPlugin()
91+
{
92+
if (!BuildTargetNeedsPlugin())
93+
return;
94+
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.");
95+
}
96+
}
97+
}
98+
#endif

Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)