This commit is contained in:
sinaioutlander 2020-10-07 16:20:34 +11:00
parent e309821743
commit b012e2305c
5 changed files with 35 additions and 23 deletions

View File

@ -220,6 +220,7 @@
<Compile Include="Input\InputManager.cs" />
<Compile Include="Input\InputSystem.cs" />
<Compile Include="Input\LegacyInput.cs" />
<Compile Include="Input\NoInput.cs" />
<Compile Include="Menu\CursorControl.cs" />
<Compile Include="Menu\MainMenu\Pages\OptionsPage.cs" />
<Compile Include="Tests\TestClass.cs" />

View File

@ -14,7 +14,7 @@ using BepInEx.IL2CPP;
namespace Explorer
{
[BepInPlugin(ExplorerCore.GUID, ExplorerCore.NAME, ExplorerCore.VERSION)]
[BepInPlugin(ExplorerCore.GUID, "Explorer", ExplorerCore.VERSION)]
#if CPP
public class ExplorerBepInPlugin : BasePlugin
#else

View File

@ -2,7 +2,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ILRepacker" AfterTargets="Build">
<!-- Merging DLLs -->
<ItemGroup>
<InputAssemblies Include="$(OutputPath)$(AssemblyName).dll" />
<InputAssemblies Include="..\lib\mcs.dll" />

View File

@ -7,19 +7,12 @@ namespace Explorer
{
public static class InputManager
{
// If no Input modules loaded at all
public static bool NO_INPUT { get; private set; }
// If using new InputSystem module
public static bool USING_NEW_INPUT { get; private set; }
private static AbstractInput inputModule;
public static void Init()
{
if (InputSystem.TKeyboard != null || TryLoadModule("Unity.InputSystem", InputSystem.TKeyboard))
{
USING_NEW_INPUT = true;
inputModule = new InputSystem();
}
else if (LegacyInput.TInput != null || TryLoadModule("UnityEngine.Input", LegacyInput.TInput))
@ -30,26 +23,20 @@ namespace Explorer
if (inputModule == null)
{
ExplorerCore.LogWarning("Could not find any Input module!");
NO_INPUT = true;
inputModule = new NoInput();
}
else
{
inputModule.Init();
}
bool TryLoadModule(string dll, Type check) => ReflectionHelpers.LoadModule(dll) && check != null;
}
public static Vector3 MousePosition => inputModule?.MousePosition ?? Vector3.zero;
public static Vector3 MousePosition => inputModule.MousePosition;
public static bool GetKeyDown(KeyCode key) => inputModule?.GetKeyDown(key) ?? false;
public static bool GetKeyDown(KeyCode key) => inputModule.GetKeyDown(key);
public static bool GetKey(KeyCode key) => inputModule.GetKey(key);
public static bool GetKey(KeyCode key) => inputModule?.GetKey(key) ?? false;
/// <param name="btn">0 = left, 1 = right, 2 = middle.</param>
public static bool GetMouseButtonDown(int btn) => inputModule?.GetMouseButtonDown(btn) ?? false;
/// <param name="btn">0 = left, 1 = right, 2 = middle.</param>
public static bool GetMouseButton(int btn) => inputModule?.GetMouseButton(btn) ?? false;
public static bool GetMouseButtonDown(int btn) => inputModule.GetMouseButtonDown(btn);
public static bool GetMouseButton(int btn) => inputModule.GetMouseButton(btn);
}
}

25
src/Input/NoInput.cs Normal file
View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Explorer.Input
{
// Just a stub for games where no Input module was able to load at all.
public class NoInput : AbstractInput
{
public override Vector2 MousePosition => Vector2.zero;
public override bool GetKey(KeyCode key) => false;
public override bool GetKeyDown(KeyCode key) => false;
public override bool GetMouseButton(int btn) => false;
public override bool GetMouseButtonDown(int btn) => false;
public override void Init() { }
}
}