Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW: Throw error when extension for inputsystem needed #2101

Merged
merged 20 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// This class controls all required plugins and extension packages are installed for the InputSystem.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
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<BuildTarget> s_supportedBuildTargets = new HashSet<BuildTarget>()
{
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.";

/// <summary>
/// Used to register extensions externally to the InputSystem, this is needed for all Platforms that require a plugin to be installed.
/// </summary>
/// <remarks>
/// This method is internally called by the InputSystem package extensions to register the PlugIn. This can be called for custom extensions on custom platforms.
/// </remarks>
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)
lyndon-unity marked this conversation as resolved.
Show resolved Hide resolved
{
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading