Skip to content

Commit 73b7bcb

Browse files
committed
set active input handler to InputManager when package is removed
1 parent 7f8d00f commit 73b7bcb

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#if UNITY_EDITOR
2+
using System;
3+
using System.Collections.ObjectModel;
4+
using UnityEditor;
5+
using UnityEditor.PackageManager;
6+
7+
8+
namespace UnityEngine.InputSystem.Editor
9+
{
10+
/// <summary>
11+
/// Force restart if InputSystem package is added to activate and initialize it on managed side.
12+
/// Set Project Settings input handling to reflect the presence of the Input System package, since it is not available in the UI.
13+
/// </summary>
14+
internal class InputSystemPackageControl
15+
{
16+
const string packageName = "com.unity.inputsystem";
17+
18+
[InitializeOnLoadMethod]
19+
static void SubscribePackageManagerEvent()
20+
{
21+
//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
22+
UnityEditor.PackageManager.Events.registeringPackages += CheckForInputSystemPackageRemoved;
23+
}
24+
25+
private static void CheckForInputSystemPackageRemoved(PackageRegistrationEventArgs packageArgs)
26+
{
27+
if (InputSystemAddedRemoved(packageArgs.removed))
28+
HandleInputSystemRemoved();
29+
}
30+
31+
private static bool InputSystemAddedRemoved(ReadOnlyCollection<UnityEditor.PackageManager.PackageInfo> packages)
32+
{
33+
foreach (var package in packages)
34+
{
35+
if (package.name == packageName)
36+
return true;
37+
}
38+
return false;
39+
}
40+
41+
private static void HandleInputSystemRemoved()
42+
{
43+
//set input handling to none
44+
EditorPlayerSettingHelpers.newSystemBackendsEnabled = false;
45+
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)"))
46+
EditorApplication.OpenProject(Environment.CurrentDirectory);
47+
}
48+
}
49+
}
50+
#endif

Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPackageControl.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)