Skip to content

Commit b1a337d

Browse files
authored
FIX: Restart prompt not appearing on Unity 2020.2+ (case 1292513, #1246).
1 parent ccf7193 commit b1a337d

File tree

7 files changed

+149
-36
lines changed

7 files changed

+149
-36
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ however, it has to be formatted properly to pass verification tests.
2323
- Fixed `InputUser.OnEvent` and `RebindingOperation.OnEvent` exhibiting bad performance profiles and leading to multi-millisecond input update times (case 1253371).
2424
* In our own measurements, `InputUser.OnEvent` is >9 times faster than before and `RebindingOperation.OnEvent` is ~2.5 times faster.
2525
- Fixed PS4 controller not recognized on Mac when connected over Bluetooth ([case 1286449](https://issuetracker.unity3d.com/issues/input-system-dualshock-4-zct1e-dualshock-2-v1-devices-are-not-fully-recognised-over-bluetooth)).
26+
- Fixed restart prompt after package installation not appearing on Unity 2020.2+ ([case 1292513](https://issuetracker.unity3d.com/issues/input-system-after-package-install-the-update-slash-switch-and-restart-prompt-does-not-appear)).
2627

2728
### Added
2829

Packages/com.unity.inputsystem/InputSystem/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[assembly: InternalsVisibleTo("Unity.InputSystem.TestFramework")]
77
[assembly: InternalsVisibleTo("Unity.InputSystem.Tests.Editor")]
88
[assembly: InternalsVisibleTo("Unity.InputSystem.Tests")]
9+
[assembly: InternalsVisibleTo("Unity.InputSystem.IntegrationTests")]
910

1011
namespace UnityEngine.InputSystem
1112
{

Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastMouse.partial.cs.meta

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

Packages/com.unity.inputsystem/InputSystem/Editor/Internal/EditorHelpers.cs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,15 @@ internal static class EditorHelpers
1313

1414
public static void RestartEditorAndRecompileScripts(bool dryRun = false)
1515
{
16-
// The APIs here are not public. Use reflection to get to them.
17-
18-
// Delete compilation output.
19-
var editorAssembly = typeof(EditorApplication).Assembly;
20-
var editorCompilationInterfaceType =
21-
editorAssembly.GetType("UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface");
22-
var editorCompilationInstance = editorCompilationInterfaceType.GetProperty("Instance").GetValue(null);
23-
var cleanScriptAssembliesMethod = editorCompilationInstance.GetType().GetMethod("CleanScriptAssemblies");
24-
if (!dryRun)
25-
cleanScriptAssembliesMethod.Invoke(editorCompilationInstance, null);
26-
else if (cleanScriptAssembliesMethod == null)
27-
throw new MissingMethodException(editorCompilationInterfaceType.FullName, "CleanScriptAssemblies");
28-
29-
// Restart editor.
16+
// The API here are not public. Use reflection to get to them.
3017
var editorApplicationType = typeof(EditorApplication);
31-
var requestCloseAndRelaunchWithCurrentArgumentsMethod =
32-
editorApplicationType.GetMethod("RequestCloseAndRelaunchWithCurrentArguments",
18+
var restartEditorAndRecompileScripts =
19+
editorApplicationType.GetMethod("RestartEditorAndRecompileScripts",
3320
BindingFlags.NonPublic | BindingFlags.Static);
3421
if (!dryRun)
35-
requestCloseAndRelaunchWithCurrentArgumentsMethod.Invoke(null, null);
36-
else if (requestCloseAndRelaunchWithCurrentArgumentsMethod == null)
37-
throw new MissingMethodException(editorApplicationType.FullName, "RequestCloseAndRelaunchWithCurrentArguments");
22+
restartEditorAndRecompileScripts.Invoke(null, null);
23+
else if (restartEditorAndRecompileScripts == null)
24+
throw new MissingMethodException(editorApplicationType.FullName, "RestartEditorAndRecompileScripts");
3825
}
3926

4027
public static void CheckOut(string path)

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/EditorPlayerSettingHelpers.cs

Lines changed: 97 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#if UNITY_EDITOR
2+
using System;
23
using System.Linq;
34
using UnityEditor;
45

@@ -14,13 +15,30 @@ public static bool newSystemBackendsEnabled
1415
{
1516
get
1617
{
18+
#if UNITY_2020_2_OR_NEWER
19+
var property = GetPropertyOrNull(kActiveInputHandler);
20+
return property == null || ActiveInputHandlerToTuple(property.intValue).newSystemEnabled;
21+
#else
1722
var property = GetPropertyOrNull(kEnableNewSystemProperty);
18-
if (property != null)
19-
return property.boolValue;
20-
return true;
23+
return property == null || property.boolValue;
24+
#endif
2125
}
2226
set
2327
{
28+
#if UNITY_2020_2_OR_NEWER
29+
var property = GetPropertyOrNull(kActiveInputHandler);
30+
if (property != null)
31+
{
32+
var tuple = ActiveInputHandlerToTuple(property.intValue);
33+
tuple.newSystemEnabled = value;
34+
property.intValue = TupleToActiveInputHandler(tuple);
35+
property.serializedObject.ApplyModifiedProperties();
36+
}
37+
else
38+
{
39+
Debug.LogError($"Cannot find '{kActiveInputHandler}' in player settings");
40+
}
41+
#else
2442
var property = GetPropertyOrNull(kEnableNewSystemProperty);
2543
if (property != null)
2644
{
@@ -31,6 +49,7 @@ public static bool newSystemBackendsEnabled
3149
{
3250
Debug.LogError($"Cannot find '{kEnableNewSystemProperty}' in player settings");
3351
}
52+
#endif
3453
}
3554
}
3655

@@ -42,13 +61,30 @@ public static bool oldSystemBackendsEnabled
4261
{
4362
get
4463
{
64+
#if UNITY_2020_2_OR_NEWER
65+
var property = GetPropertyOrNull(kActiveInputHandler);
66+
return property == null || ActiveInputHandlerToTuple(property.intValue).oldSystemEnabled;
67+
#else
4568
var property = GetPropertyOrNull(kDisableOldSystemProperty);
46-
if (property != null)
47-
return !property.boolValue;
48-
return true;
69+
return property == null || !property.boolValue;
70+
#endif
4971
}
5072
set
5173
{
74+
#if UNITY_2020_2_OR_NEWER
75+
var property = GetPropertyOrNull(kActiveInputHandler);
76+
if (property != null)
77+
{
78+
var tuple = ActiveInputHandlerToTuple(property.intValue);
79+
tuple.oldSystemEnabled = value;
80+
property.intValue = TupleToActiveInputHandler(tuple);
81+
property.serializedObject.ApplyModifiedProperties();
82+
}
83+
else
84+
{
85+
Debug.LogError($"Cannot find '{kActiveInputHandler}' in player settings");
86+
}
87+
#else
5288
var property = GetPropertyOrNull(kDisableOldSystemProperty);
5389
if (property != null)
5490
{
@@ -59,21 +95,70 @@ public static bool oldSystemBackendsEnabled
5995
{
6096
Debug.LogError($"Cannot find '{kDisableOldSystemProperty}' in player settings");
6197
}
98+
#endif
6299
}
63100
}
64101

102+
103+
#if UNITY_2020_2_OR_NEWER
104+
private const string kActiveInputHandler = "activeInputHandler";
105+
106+
private enum InputHandler
107+
{
108+
OldInputManager = 0,
109+
NewInputSystem = 1,
110+
InputBoth = 2
111+
};
112+
113+
private static (bool newSystemEnabled, bool oldSystemEnabled) ActiveInputHandlerToTuple(int value)
114+
{
115+
switch ((InputHandler)value)
116+
{
117+
case InputHandler.OldInputManager:
118+
return (false, true);
119+
case InputHandler.NewInputSystem:
120+
return (true, false);
121+
case InputHandler.InputBoth:
122+
return (true, true);
123+
default:
124+
throw new ArgumentException($"Invalid value of 'activeInputHandler' setting: {value}");
125+
}
126+
}
127+
128+
private static int TupleToActiveInputHandler((bool newSystemEnabled, bool oldSystemEnabled) tuple)
129+
{
130+
switch (tuple)
131+
{
132+
case (false, true):
133+
return (int)InputHandler.OldInputManager;
134+
case (true, false):
135+
return (int)InputHandler.NewInputSystem;
136+
case (true, true):
137+
return (int)InputHandler.InputBoth;
138+
// Special case, when using two separate bool's of the public API here,
139+
// it's possible to end up with both settings in false, for example:
140+
// - EditorPlayerSettingHelpers.newSystemBackendsEnabled = true;
141+
// - EditorPlayerSettingHelpers.oldSystemBackendsEnabled = false;
142+
// - EditorPlayerSettingHelpers.newSystemBackendsEnabled = false;
143+
// - EditorPlayerSettingHelpers.oldSystemBackendsEnabled = true;
144+
// On line 3 both settings will be false, even if we set old system to true on line 4.
145+
case (false, false):
146+
return (int)InputHandler.OldInputManager;
147+
}
148+
}
149+
150+
#else
65151
private const string kEnableNewSystemProperty = "enableNativePlatformBackendsForNewInputSystem";
66152
private const string kDisableOldSystemProperty = "disableOldInputManagerSupport";
153+
#endif
67154

68155
private static SerializedProperty GetPropertyOrNull(string name)
69156
{
70157
var playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>().FirstOrDefault();
71-
if (playerSettings != null)
72-
{
73-
var playerSettingsObject = new SerializedObject(playerSettings);
74-
return playerSettingsObject.FindProperty(name);
75-
}
76-
return null;
158+
if (playerSettings == null)
159+
return null;
160+
var playerSettingsObject = new SerializedObject(playerSettings);
161+
return playerSettingsObject.FindProperty(name);
77162
}
78163
}
79164
}

Packages/com.unity.inputsystem/InputSystem/Utilities/MiscHelpers.cs.meta

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

Packages/com.unity.inputsystem/Tests/IntegrationTests/IntegrationTests.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
using UnityEngine.InputSystem.LowLevel;
66
using UnityEngine.Scripting;
77
using UnityEngine.TestTools;
8+
#if UNITY_EDITOR
9+
using UnityEngine.InputSystem.Editor;
10+
11+
#endif
812

913
// Disable irrelevant warning about there not being underscores in method names.
1014
#pragma warning disable CA1707
@@ -83,7 +87,42 @@ public void Integration_CanSendAndReceiveEvents()
8387
}
8488
}
8589

86-
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
90+
#if UNITY_EDITOR
91+
92+
[Test]
93+
[Category("Integration")]
94+
public void Integration_CanChangeInputBackendPlayerSettingInEditor()
95+
{
96+
// Save current player settings so we can restore them.
97+
var oldEnabled = EditorPlayerSettingHelpers.oldSystemBackendsEnabled;
98+
var newEnabled = EditorPlayerSettingHelpers.newSystemBackendsEnabled;
99+
100+
// Enable new and disable old.
101+
EditorPlayerSettingHelpers.newSystemBackendsEnabled = true;
102+
EditorPlayerSettingHelpers.oldSystemBackendsEnabled = false;
103+
Assert.That(EditorPlayerSettingHelpers.newSystemBackendsEnabled, Is.True);
104+
Assert.That(EditorPlayerSettingHelpers.oldSystemBackendsEnabled, Is.False);
105+
106+
// Enable old and disable new.
107+
EditorPlayerSettingHelpers.newSystemBackendsEnabled = false;
108+
EditorPlayerSettingHelpers.oldSystemBackendsEnabled = true;
109+
Assert.That(EditorPlayerSettingHelpers.newSystemBackendsEnabled, Is.False);
110+
Assert.That(EditorPlayerSettingHelpers.oldSystemBackendsEnabled, Is.True);
111+
112+
// Enable both.
113+
EditorPlayerSettingHelpers.newSystemBackendsEnabled = true;
114+
EditorPlayerSettingHelpers.oldSystemBackendsEnabled = true;
115+
Assert.That(EditorPlayerSettingHelpers.newSystemBackendsEnabled, Is.True);
116+
Assert.That(EditorPlayerSettingHelpers.oldSystemBackendsEnabled, Is.True);
117+
118+
// Restore previous settings.
119+
EditorPlayerSettingHelpers.oldSystemBackendsEnabled = oldEnabled;
120+
EditorPlayerSettingHelpers.newSystemBackendsEnabled = newEnabled;
121+
}
122+
123+
#endif
124+
125+
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
87126

88127
[UnityTest]
89128
[Category("Integration")]

0 commit comments

Comments
 (0)