Handle cases where InputSystem is present but not active

This commit is contained in:
Sinai 2021-04-25 21:19:00 +10:00
parent 1487372832
commit 7f6a4514e4

View File

@ -40,25 +40,42 @@ namespace UnityExplorer.Core.Input
public static void Init() public static void Init()
{ {
if (InputSystem.TKeyboard != null || (ReflectionUtility.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null)) InitHandler();
{
m_inputModule = new InputSystem();
CurrentType = InputType.InputSystem;
}
else if (LegacyInput.TInput != null || (ReflectionUtility.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
{
m_inputModule = new LegacyInput();
CurrentType = InputType.Legacy;
}
if (m_inputModule == null)
{
ExplorerCore.LogWarning("Could not find any Input Module Type!");
m_inputModule = new NoInput();
CurrentType = InputType.None;
}
CursorUnlocker.Init(); CursorUnlocker.Init();
} }
private static void InitHandler()
{
if (InputSystem.TKeyboard != null || (ReflectionUtility.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
{
try
{
m_inputModule = new InputSystem();
CurrentType = InputType.InputSystem;
// make sure its working, the package may be present but not enabled.
GetKeyDown(KeyCode.F5);
return;
}
catch
{
ExplorerCore.LogWarning("The InputSystem package was found but it does not seem to be working, defaulting to legacy Input...");
}
}
if (LegacyInput.TInput != null || (ReflectionUtility.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
{
m_inputModule = new LegacyInput();
CurrentType = InputType.Legacy;
return;
}
ExplorerCore.LogWarning("Could not find any Input Module Type!");
m_inputModule = new NoInput();
CurrentType = InputType.None;
}
} }
} }