Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit bf6d526

Browse files
committed
1.8.23
* Fixed an issue in Mono games when the target you are inspecting is destroyed (window would not close as it should). * Cleaned up and refactored the Input support so it's easier to manage.
1 parent c991cb4 commit bf6d526

13 files changed

+251
-224
lines changed

src/Explorer.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@
241241
<Compile Include="ExplorerBepInPlugin.cs" />
242242
<Compile Include="ExplorerMelonMod.cs" />
243243
<Compile Include="Extensions\ReflectionExtensions.cs" />
244-
<Compile Include="Helpers\InputHelper.cs" />
244+
<Compile Include="Input\AbstractInput.cs" />
245+
<Compile Include="Input\InputManager.cs" />
246+
<Compile Include="Input\InputSystem.cs" />
247+
<Compile Include="Input\LegacyInput.cs" />
245248
<Compile Include="Menu\CursorControl.cs" />
246249
<Compile Include="Menu\MainMenu\Pages\OptionsPage.cs" />
247250
<Compile Include="Tests\TestClass.cs" />

src/ExplorerCore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Explorer
55
public class ExplorerCore
66
{
77
public const string NAME = "Explorer (" + PLATFORM + ", " + MODLOADER + ")";
8-
public const string VERSION = "1.8.22";
8+
public const string VERSION = "1.8.23";
99
public const string AUTHOR = "Sinai";
1010
public const string GUID = "com.sinai.explorer";
1111

@@ -33,7 +33,7 @@ public ExplorerCore()
3333
new MainMenu();
3434
new WindowManager();
3535

36-
InputHelper.Init();
36+
InputManager.Init();
3737
CursorControl.Init();
3838

3939
Log($"{NAME} {VERSION} initialized.");
@@ -54,7 +54,7 @@ private static void SetShowMenu(bool show)
5454

5555
public static void Update()
5656
{
57-
if (InputHelper.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
57+
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
5858
{
5959
ShowMenu = !ShowMenu;
6060
}

src/Helpers/InputHelper.cs

Lines changed: 0 additions & 205 deletions
This file was deleted.

src/Input/AbstractInput.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using UnityEngine;
6+
7+
namespace Explorer.Input
8+
{
9+
public abstract class AbstractInput
10+
{
11+
public abstract void Init();
12+
13+
public abstract Vector2 MousePosition { get; }
14+
15+
public abstract bool GetKeyDown(KeyCode key);
16+
public abstract bool GetKey(KeyCode key);
17+
18+
public abstract bool GetMouseButtonDown(int btn);
19+
public abstract bool GetMouseButton(int btn);
20+
}
21+
}

src/Input/InputManager.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Reflection;
3+
using UnityEngine;
4+
using Explorer.Input;
5+
6+
namespace Explorer
7+
{
8+
public static class InputManager
9+
{
10+
// If no Input modules loaded at all
11+
public static bool NO_INPUT { get; private set; }
12+
13+
// If using new InputSystem module
14+
public static bool USING_NEW_INPUT { get; private set; }
15+
16+
private static AbstractInput inputModule;
17+
18+
public static void Init()
19+
{
20+
if (InputSystem.TKeyboard != null || TryLoadModule("Unity.InputSystem", InputSystem.TKeyboard))
21+
{
22+
USING_NEW_INPUT = true;
23+
inputModule = new InputSystem();
24+
}
25+
else if (LegacyInput.TInput != null || TryLoadModule("UnityEngine.Input", LegacyInput.TInput))
26+
{
27+
inputModule = new LegacyInput();
28+
}
29+
30+
if (inputModule == null)
31+
{
32+
ExplorerCore.LogWarning("Could not find any Input module!");
33+
NO_INPUT = true;
34+
}
35+
else
36+
{
37+
inputModule.Init();
38+
}
39+
40+
bool TryLoadModule(string dll, Type check) => ReflectionHelpers.LoadModule(dll) && check != null;
41+
}
42+
43+
public static Vector3 MousePosition => inputModule?.MousePosition ?? Vector3.zero;
44+
45+
public static bool GetKeyDown(KeyCode key) => inputModule?.GetKeyDown(key) ?? false;
46+
47+
public static bool GetKey(KeyCode key) => inputModule?.GetKey(key) ?? false;
48+
49+
/// <param name="btn">0 = left, 1 = right, 2 = middle.</param>
50+
public static bool GetMouseButtonDown(int btn) => inputModule?.GetMouseButtonDown(btn) ?? false;
51+
52+
/// <param name="btn">0 = left, 1 = right, 2 = middle.</param>
53+
public static bool GetMouseButton(int btn) => inputModule?.GetMouseButton(btn) ?? false;
54+
}
55+
}

0 commit comments

Comments
 (0)