From 7f6a4514e4f7940f27514dabdc5c37a086ce9604 Mon Sep 17 00:00:00 2001 From: Sinai Date: Sun, 25 Apr 2021 21:19:00 +1000 Subject: [PATCH] Handle cases where InputSystem is present but not active --- src/Core/Input/InputManager.cs | 51 ++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/Core/Input/InputManager.cs b/src/Core/Input/InputManager.cs index 849b8cc..5234d75 100644 --- a/src/Core/Input/InputManager.cs +++ b/src/Core/Input/InputManager.cs @@ -40,25 +40,42 @@ namespace UnityExplorer.Core.Input public static void Init() { - if (InputSystem.TKeyboard != null || (ReflectionUtility.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null)) - { - 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; - } + InitHandler(); 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; + } } } \ No newline at end of file