Fix for games where InputSystem is present but not active

This commit is contained in:
Sinai 2021-04-27 21:22:16 +10:00
parent af3ee07143
commit 73cde0f91f
3 changed files with 25 additions and 18 deletions

View File

@ -47,32 +47,43 @@ namespace UnityExplorer.Core.Input
private static void InitHandler() private static void InitHandler()
{ {
// First, just try to use the legacy input, see if its working.
// The InputSystem package may be present but not actually activated, so we can find out this way.
if (LegacyInput.TInput != null || (ReflectionUtility.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
{
try
{
m_inputModule = new LegacyInput();
CurrentType = InputType.Legacy;
// make sure its working
GetKeyDown(KeyCode.F5);
ExplorerCore.Log("Initialized Legacy Input support");
return;
}
catch
{
// It's not working, we'll fall back to InputSystem.
}
}
if (InputSystem.TKeyboard != null || (ReflectionUtility.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null)) if (InputSystem.TKeyboard != null || (ReflectionUtility.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
{ {
try try
{ {
m_inputModule = new InputSystem(); m_inputModule = new InputSystem();
CurrentType = InputType.InputSystem; CurrentType = InputType.InputSystem;
ExplorerCore.Log("Initialized new InputSystem support.");
// make sure its working, the package may be present but not enabled.
GetKeyDown(KeyCode.F5);
return; return;
} }
catch catch (Exception ex)
{ {
ExplorerCore.LogWarning("The InputSystem package was found but it does not seem to be working, defaulting to legacy Input..."); ExplorerCore.Log(ex);
} }
} }
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!"); ExplorerCore.LogWarning("Could not find any Input Module Type!");
m_inputModule = new NoInput(); m_inputModule = new NoInput();
CurrentType = InputType.None; CurrentType = InputType.None;

View File

@ -12,8 +12,6 @@ namespace UnityExplorer.Core.Input
{ {
public InputSystem() public InputSystem()
{ {
ExplorerCore.Log("Initializing new InputSystem support...");
m_kbCurrentProp = TKeyboard.GetProperty("current"); m_kbCurrentProp = TKeyboard.GetProperty("current");
m_kbIndexer = TKeyboard.GetProperty("Item", new Type[] { TKey }); m_kbIndexer = TKeyboard.GetProperty("Item", new Type[] { TKey });

View File

@ -10,8 +10,6 @@ namespace UnityExplorer.Core.Input
{ {
public LegacyInput() public LegacyInput()
{ {
ExplorerCore.Log("Initializing Legacy Input support...");
m_mousePositionProp = TInput.GetProperty("mousePosition"); m_mousePositionProp = TInput.GetProperty("mousePosition");
m_mouseDeltaProp = TInput.GetProperty("mouseScrollDelta"); m_mouseDeltaProp = TInput.GetProperty("mouseScrollDelta");
m_getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) }); m_getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });