mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-01 19:13:03 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
e7aa01ebc8 | |||
bf6d526284 | |||
c991cb4b22 | |||
3971e49ce1 |
@ -147,13 +147,13 @@ public class MenuClass_CursorUpdate
|
||||
|
||||
## Building
|
||||
|
||||
If you'd like to build this yourself, everything you need (other than MelonLoader) is included with this repository, there is no need for recursive cloning etc.
|
||||
If you'd like to build this yourself, everything you need (other than MelonLoader and/or BepInEx) is included with this repository.
|
||||
|
||||
1. Install MelonLoader for your game.
|
||||
1. Install MelonLoader or BepInEx for your game.
|
||||
2. Open the `src\Explorer.csproj` file in a text editor.
|
||||
3. Set the relevant `GameFolder` value(s) for the version(s) you want to build, eg. set `MLCppGameFolder` if you want to build for a MelonLoader Il2Cpp game.
|
||||
3. Set the relevant `GameFolder` values for the versions you want to build, eg. set `MLCppGameFolder` if you want to build for a MelonLoader Il2Cpp game.
|
||||
4. Open the `src\Explorer.sln` project.
|
||||
5. Select `Solution 'Explorer' (1 of 1 project)` in the Solution Explorer panel, and set the <b>Active config</b> to the version you want to build, then build it.
|
||||
5. Select `Solution 'Explorer' (1 of 1 project)` in the Solution Explorer panel, and set the <b>Active config</b> property to the version you want to build, then build it.
|
||||
5. The DLLs are built to the `Release\` folder in the root of the repository.
|
||||
|
||||
## Credits
|
||||
|
@ -27,14 +27,12 @@
|
||||
<AssemblyName>Explorer</AssemblyName>
|
||||
<!-- Set this to the MelonLoader Il2Cpp Game folder, without the ending '\' character. -->
|
||||
<MLCppGameFolder>D:\Steam\steamapps\common\Hellpoint</MLCppGameFolder>
|
||||
<!--<MLCppGameFolder>D:\source\Unity Projects\Test\_BUILD</MLCppGameFolder>-->
|
||||
<!-- Set this to the MelonLoader Mono Game folder, without the ending '\' character. -->
|
||||
<MLMonoGameFolder>D:\Steam\steamapps\common\Outward</MLMonoGameFolder>
|
||||
<!-- Set this to the BepInEx Il2Cpp Game folder, without the ending '\' character. -->
|
||||
<BIECppGameFolder>D:\Steam\steamapps\common\Outward - Il2Cpp</BIECppGameFolder>
|
||||
<!-- Set this to the BepInEx Mono Game folder, without the ending '\' character. -->
|
||||
<BIEMonoGameFolder>D:\Steam\steamapps\common\Outward</BIEMonoGameFolder>
|
||||
<!-- <BIEMonoGameFolder>D:\source\Unity Projects\! My Unity Games\NewInputSystemTest\_BUILD</BIEMonoGameFolder> -->
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_ML_Cpp|AnyCPU' ">
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
@ -95,11 +93,11 @@
|
||||
<!-- MCS ref -->
|
||||
<Reference Include="mcs" Condition="'$(IsNet35)'=='false'">
|
||||
<HintPath>..\lib\mcs.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="mcs" Condition="'$(IsNet35)'=='true'">
|
||||
<HintPath>..\lib\mcs.NET35.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<!-- Universal Mono UnityEngine.dll ref (v5.3) -->
|
||||
@ -241,7 +239,10 @@
|
||||
<Compile Include="ExplorerBepInPlugin.cs" />
|
||||
<Compile Include="ExplorerMelonMod.cs" />
|
||||
<Compile Include="Extensions\ReflectionExtensions.cs" />
|
||||
<Compile Include="Helpers\InputHelper.cs" />
|
||||
<Compile Include="Input\AbstractInput.cs" />
|
||||
<Compile Include="Input\InputManager.cs" />
|
||||
<Compile Include="Input\InputSystem.cs" />
|
||||
<Compile Include="Input\LegacyInput.cs" />
|
||||
<Compile Include="Menu\CursorControl.cs" />
|
||||
<Compile Include="Menu\MainMenu\Pages\OptionsPage.cs" />
|
||||
<Compile Include="Tests\TestClass.cs" />
|
||||
|
@ -62,24 +62,11 @@ namespace Explorer
|
||||
SceneManager.activeSceneChanged += DoSceneChange;
|
||||
#endif
|
||||
|
||||
LoadMCS();
|
||||
|
||||
new ExplorerCore();
|
||||
|
||||
//HarmonyInstance.PatchAll();
|
||||
}
|
||||
|
||||
void LoadMCS()
|
||||
{
|
||||
#if NET35
|
||||
var path = @"BepInEx\plugins\mcs.NET35.dll";
|
||||
#else
|
||||
var path = @"BepInEx\plugins\mcs.dll";
|
||||
#endif
|
||||
Assembly.Load(File.ReadAllBytes(path));
|
||||
ExplorerCore.Log("Loaded mcs!");
|
||||
}
|
||||
|
||||
internal static void DoSceneChange(Scene arg0, Scene arg1)
|
||||
{
|
||||
ExplorerCore.OnSceneChange();
|
||||
|
@ -5,7 +5,7 @@ namespace Explorer
|
||||
public class ExplorerCore
|
||||
{
|
||||
public const string NAME = "Explorer (" + PLATFORM + ", " + MODLOADER + ")";
|
||||
public const string VERSION = "1.8.21";
|
||||
public const string VERSION = "1.8.3";
|
||||
public const string AUTHOR = "Sinai";
|
||||
public const string GUID = "com.sinai.explorer";
|
||||
|
||||
@ -33,7 +33,7 @@ namespace Explorer
|
||||
new MainMenu();
|
||||
new WindowManager();
|
||||
|
||||
InputHelper.Init();
|
||||
InputManager.Init();
|
||||
CursorControl.Init();
|
||||
|
||||
Log($"{NAME} {VERSION} initialized.");
|
||||
@ -54,7 +54,7 @@ namespace Explorer
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
if (InputHelper.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
|
||||
if (InputManager.GetKeyDown(ModConfig.Instance.Main_Menu_Toggle))
|
||||
{
|
||||
ShowMenu = !ShowMenu;
|
||||
}
|
||||
|
@ -1,222 +0,0 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer
|
||||
{
|
||||
/// <summary>
|
||||
/// Version-agnostic Input module using Reflection.
|
||||
/// </summary>
|
||||
public static class InputHelper
|
||||
{
|
||||
// If Input module failed to load at all
|
||||
public static bool NO_INPUT;
|
||||
|
||||
// If using new InputSystem module
|
||||
public static bool USING_NEW_INPUT;
|
||||
|
||||
// Cached Types
|
||||
private static Type TInput => _input ?? (_input = ReflectionHelpers.GetTypeByName("UnityEngine.Input"));
|
||||
private static Type _input;
|
||||
|
||||
private static Type TKeyboard => _keyboardSys ?? (_keyboardSys = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Keyboard"));
|
||||
private static Type _keyboardSys;
|
||||
|
||||
private static Type TMouse => _mouseSys ?? (_mouseSys = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Mouse"));
|
||||
private static Type _mouseSys;
|
||||
|
||||
private static Type TKey => _key ?? (_key = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Key"));
|
||||
private static Type _key;
|
||||
|
||||
// Cached member infos (new system)
|
||||
private static PropertyInfo _keyboardCurrent;
|
||||
private static PropertyInfo _kbItemProp;
|
||||
private static PropertyInfo _isPressed;
|
||||
private static PropertyInfo _wasPressedThisFrame;
|
||||
private static PropertyInfo _mouseCurrent;
|
||||
private static PropertyInfo _leftButton;
|
||||
private static PropertyInfo _rightButton;
|
||||
private static PropertyInfo _position;
|
||||
private static MethodInfo _readValueMethod;
|
||||
|
||||
// Cached member infos (legacy)
|
||||
private static PropertyInfo _mousePosition;
|
||||
private static MethodInfo _getKey;
|
||||
private static MethodInfo _getKeyDown;
|
||||
private static MethodInfo _getMouseButton;
|
||||
private static MethodInfo _getMouseButtonDown;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
if (TKeyboard != null || TryManuallyLoadNewInput())
|
||||
{
|
||||
InitNewInput();
|
||||
return;
|
||||
}
|
||||
|
||||
if (TInput != null || TryManuallyLoadLegacyInput())
|
||||
{
|
||||
InitLegacyInput();
|
||||
return;
|
||||
}
|
||||
|
||||
ExplorerCore.LogWarning("Could not find any Input module!");
|
||||
NO_INPUT = true;
|
||||
}
|
||||
|
||||
private static void InitNewInput()
|
||||
{
|
||||
ExplorerCore.Log("Initializing new InputSystem support...");
|
||||
|
||||
USING_NEW_INPUT = true;
|
||||
|
||||
_keyboardCurrent = TKeyboard.GetProperty("current");
|
||||
_kbItemProp = TKeyboard.GetProperty("Item", new Type[] { TKey });
|
||||
|
||||
var btnControl = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Controls.ButtonControl");
|
||||
_isPressed = btnControl.GetProperty("isPressed");
|
||||
_wasPressedThisFrame = btnControl.GetProperty("wasPressedThisFrame");
|
||||
|
||||
_mouseCurrent = TMouse.GetProperty("current");
|
||||
_leftButton = TMouse.GetProperty("leftButton");
|
||||
_rightButton = TMouse.GetProperty("rightButton");
|
||||
|
||||
_position = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Pointer")
|
||||
.GetProperty("position");
|
||||
|
||||
_readValueMethod = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.InputControl`1")
|
||||
.MakeGenericType(typeof(Vector2))
|
||||
.GetMethod("ReadValue");
|
||||
}
|
||||
|
||||
private static void InitLegacyInput()
|
||||
{
|
||||
ExplorerCore.Log("Initializing Legacy Input support...");
|
||||
|
||||
_mousePosition = TInput.GetProperty("mousePosition");
|
||||
_getKey = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
|
||||
_getKeyDown = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
|
||||
_getMouseButton = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) });
|
||||
_getMouseButtonDown = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) });
|
||||
}
|
||||
|
||||
private static bool TryManuallyLoadNewInput()
|
||||
{
|
||||
if (ReflectionHelpers.LoadModule("Unity.InputSystem") && TKeyboard != null)
|
||||
{
|
||||
ExplorerCore.Log("Loaded new InputSystem module!");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryManuallyLoadLegacyInput()
|
||||
{
|
||||
if ((ReflectionHelpers.LoadModule("UnityEngine.InputLegacyModule") || ReflectionHelpers.LoadModule("UnityEngine.CoreModule"))
|
||||
&& TInput != null)
|
||||
{
|
||||
ExplorerCore.Log("Loaded legacy InputModule!");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 MousePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (NO_INPUT) return Vector3.zero;
|
||||
|
||||
if (USING_NEW_INPUT)
|
||||
{
|
||||
var mouse = _mouseCurrent.GetValue(null, null);
|
||||
var pos = _position.GetValue(mouse, null);
|
||||
|
||||
return (Vector2)_readValueMethod.Invoke(pos, new object[0]);
|
||||
}
|
||||
|
||||
return (Vector3)_mousePosition.GetValue(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetKeyDown(KeyCode key)
|
||||
{
|
||||
if (NO_INPUT) return false;
|
||||
|
||||
if (USING_NEW_INPUT)
|
||||
{
|
||||
var parsed = Enum.Parse(TKey, key.ToString());
|
||||
var currentKB = _keyboardCurrent.GetValue(null, null);
|
||||
var actualKey = _kbItemProp.GetValue(currentKB, new object[] { parsed });
|
||||
|
||||
return (bool)_wasPressedThisFrame.GetValue(actualKey, null);
|
||||
}
|
||||
|
||||
return (bool)_getKeyDown.Invoke(null, new object[] { key });
|
||||
}
|
||||
|
||||
public static bool GetKey(KeyCode key)
|
||||
{
|
||||
if (NO_INPUT) return false;
|
||||
|
||||
if (USING_NEW_INPUT)
|
||||
{
|
||||
var parsed = Enum.Parse(TKey, key.ToString());
|
||||
var currentKB = _keyboardCurrent.GetValue(null, null);
|
||||
var actualKey = _kbItemProp.GetValue(currentKB, new object[] { parsed });
|
||||
|
||||
return (bool)_isPressed.GetValue(actualKey, null);
|
||||
}
|
||||
|
||||
return (bool)_getKey.Invoke(null, new object[] { key });
|
||||
}
|
||||
|
||||
/// <param name="btn">0/1 = left, 2 = middle, 3 = right, etc</param>
|
||||
public static bool GetMouseButtonDown(int btn)
|
||||
{
|
||||
if (NO_INPUT) return false;
|
||||
|
||||
if (USING_NEW_INPUT)
|
||||
{
|
||||
var mouse = _mouseCurrent.GetValue(null, null);
|
||||
|
||||
PropertyInfo btnProp;
|
||||
if (btn < 2) btnProp = _leftButton;
|
||||
else btnProp = _rightButton;
|
||||
|
||||
var actualBtn = btnProp.GetValue(mouse, null);
|
||||
|
||||
return (bool)_wasPressedThisFrame.GetValue(actualBtn, null);
|
||||
}
|
||||
|
||||
return (bool)_getMouseButtonDown.Invoke(null, new object[] { btn });
|
||||
}
|
||||
|
||||
/// <param name="btn">1 = left, 2 = middle, 3 = right, etc</param>
|
||||
public static bool GetMouseButton(int btn)
|
||||
{
|
||||
if (NO_INPUT) return false;
|
||||
|
||||
if (USING_NEW_INPUT)
|
||||
{
|
||||
var mouse = _mouseCurrent.GetValue(null, null);
|
||||
|
||||
PropertyInfo btnProp;
|
||||
if (btn < 2) btnProp = _leftButton;
|
||||
else btnProp = _rightButton;
|
||||
|
||||
var actualBtn = btnProp.GetValue(mouse, null);
|
||||
|
||||
return (bool)_isPressed.GetValue(actualBtn, null);
|
||||
}
|
||||
|
||||
return (bool)_getMouseButton.Invoke(null, new object[] { btn });
|
||||
}
|
||||
}
|
||||
}
|
21
src/Input/AbstractInput.cs
Normal file
21
src/Input/AbstractInput.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer.Input
|
||||
{
|
||||
public abstract class AbstractInput
|
||||
{
|
||||
public abstract void Init();
|
||||
|
||||
public abstract Vector2 MousePosition { get; }
|
||||
|
||||
public abstract bool GetKeyDown(KeyCode key);
|
||||
public abstract bool GetKey(KeyCode key);
|
||||
|
||||
public abstract bool GetMouseButtonDown(int btn);
|
||||
public abstract bool GetMouseButton(int btn);
|
||||
}
|
||||
}
|
55
src/Input/InputManager.cs
Normal file
55
src/Input/InputManager.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using Explorer.Input;
|
||||
|
||||
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))
|
||||
{
|
||||
inputModule = new LegacyInput();
|
||||
}
|
||||
|
||||
if (inputModule == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("Could not find any Input module!");
|
||||
NO_INPUT = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
inputModule.Init();
|
||||
}
|
||||
|
||||
bool TryLoadModule(string dll, Type check) => ReflectionHelpers.LoadModule(dll) && check != null;
|
||||
}
|
||||
|
||||
public static Vector3 MousePosition => inputModule?.MousePosition ?? Vector3.zero;
|
||||
|
||||
public static bool GetKeyDown(KeyCode key) => inputModule?.GetKeyDown(key) ?? false;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
109
src/Input/InputSystem.cs
Normal file
109
src/Input/InputSystem.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer.Input
|
||||
{
|
||||
public class InputSystem : AbstractInput
|
||||
{
|
||||
public static Type TKeyboard => _keyboard ?? (_keyboard = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Keyboard"));
|
||||
private static Type _keyboard;
|
||||
|
||||
public static Type TMouse => _mouse ?? (_mouse = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Mouse"));
|
||||
private static Type _mouse;
|
||||
|
||||
public static Type TKey => _key ?? (_key = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Key"));
|
||||
private static Type _key;
|
||||
|
||||
private static PropertyInfo _btnIsPressedProp;
|
||||
private static PropertyInfo _btnWasPressedProp;
|
||||
|
||||
private static object CurrentKeyboard => _currentKeyboard ?? (_currentKeyboard = _kbCurrentProp.GetValue(null, null));
|
||||
private static object _currentKeyboard;
|
||||
private static PropertyInfo _kbCurrentProp;
|
||||
private static PropertyInfo _kbIndexer;
|
||||
|
||||
private static object CurrentMouse => _currentMouse ?? (_currentMouse = _mouseCurrentProp.GetValue(null, null));
|
||||
private static object _currentMouse;
|
||||
private static PropertyInfo _mouseCurrentProp;
|
||||
|
||||
private static object LeftMouseButton => _lmb ?? (_lmb = _leftButtonProp.GetValue(CurrentMouse, null));
|
||||
private static object _lmb;
|
||||
private static PropertyInfo _leftButtonProp;
|
||||
|
||||
private static object RightMouseButton => _rmb ?? (_rmb = _rightButtonProp.GetValue(CurrentMouse, null));
|
||||
private static object _rmb;
|
||||
private static PropertyInfo _rightButtonProp;
|
||||
|
||||
private static object MousePositionInfo => _pos ?? (_pos = _positionProp.GetValue(CurrentMouse, null));
|
||||
private static object _pos;
|
||||
private static PropertyInfo _positionProp;
|
||||
private static MethodInfo _readVector2InputMethod;
|
||||
|
||||
public override Vector2 MousePosition => (Vector2)_readVector2InputMethod.Invoke(MousePositionInfo, new object[0]);
|
||||
|
||||
public override bool GetKeyDown(KeyCode key)
|
||||
{
|
||||
var parsedKey = Enum.Parse(TKey, key.ToString());
|
||||
var actualKey = _kbIndexer.GetValue(CurrentKeyboard, new object[] { parsedKey });
|
||||
|
||||
return (bool)_btnWasPressedProp.GetValue(actualKey, null);
|
||||
}
|
||||
|
||||
public override bool GetKey(KeyCode key)
|
||||
{
|
||||
var parsed = Enum.Parse(TKey, key.ToString());
|
||||
var actualKey = _kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed });
|
||||
|
||||
return (bool)_btnIsPressedProp.GetValue(actualKey, null);
|
||||
}
|
||||
|
||||
public override bool GetMouseButtonDown(int btn)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case 0: return (bool)_btnWasPressedProp.GetValue(LeftMouseButton, null);
|
||||
case 1: return (bool)_btnWasPressedProp.GetValue(RightMouseButton, null);
|
||||
// case 2: return (bool)_btnWasPressedProp.GetValue(MiddleMouseButton, null);
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool GetMouseButton(int btn)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case 0: return (bool)_btnIsPressedProp.GetValue(LeftMouseButton, null);
|
||||
case 1: return (bool)_btnIsPressedProp.GetValue(RightMouseButton, null);
|
||||
// case 2: return (bool)_btnIsPressedProp.GetValue(MiddleMouseButton, null);
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
ExplorerCore.Log("Initializing new InputSystem support...");
|
||||
|
||||
_kbCurrentProp = TKeyboard.GetProperty("current");
|
||||
_kbIndexer = TKeyboard.GetProperty("Item", new Type[] { TKey });
|
||||
|
||||
var btnControl = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Controls.ButtonControl");
|
||||
_btnIsPressedProp = btnControl.GetProperty("isPressed");
|
||||
_btnWasPressedProp = btnControl.GetProperty("wasPressedThisFrame");
|
||||
|
||||
_mouseCurrentProp = TMouse.GetProperty("current");
|
||||
_leftButtonProp = TMouse.GetProperty("leftButton");
|
||||
_rightButtonProp = TMouse.GetProperty("rightButton");
|
||||
|
||||
_positionProp = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Pointer")
|
||||
.GetProperty("position");
|
||||
|
||||
_readVector2InputMethod = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.InputControl`1")
|
||||
.MakeGenericType(typeof(Vector2))
|
||||
.GetMethod("ReadValue");
|
||||
}
|
||||
}
|
||||
}
|
42
src/Input/LegacyInput.cs
Normal file
42
src/Input/LegacyInput.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Explorer.Input
|
||||
{
|
||||
public class LegacyInput : AbstractInput
|
||||
{
|
||||
public static Type TInput => _input ?? (_input = ReflectionHelpers.GetTypeByName("UnityEngine.Input"));
|
||||
private static Type _input;
|
||||
|
||||
private static PropertyInfo _mousePositionProp;
|
||||
private static MethodInfo _getKeyMethod;
|
||||
private static MethodInfo _getKeyDownMethod;
|
||||
private static MethodInfo _getMouseButtonMethod;
|
||||
private static MethodInfo _getMouseButtonDownMethod;
|
||||
|
||||
public override Vector2 MousePosition => (Vector3)_mousePositionProp.GetValue(null, null);
|
||||
|
||||
public override bool GetKey(KeyCode key) => (bool)_getKeyMethod.Invoke(null, new object[] { key });
|
||||
|
||||
public override bool GetKeyDown(KeyCode key) => (bool)_getKeyDownMethod.Invoke(null, new object[] { key });
|
||||
|
||||
public override bool GetMouseButton(int btn) => (bool)_getMouseButtonMethod.Invoke(null, new object[] { btn });
|
||||
|
||||
public override bool GetMouseButtonDown(int btn) => (bool)_getMouseButtonDownMethod.Invoke(null, new object[] { btn });
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
ExplorerCore.Log("Initializing Legacy Input support...");
|
||||
|
||||
_mousePositionProp = TInput.GetProperty("mousePosition");
|
||||
_getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
|
||||
_getKeyDownMethod = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
|
||||
_getMouseButtonMethod = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) });
|
||||
_getMouseButtonDownMethod = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) });
|
||||
}
|
||||
}
|
||||
}
|
@ -108,7 +108,7 @@ namespace Explorer
|
||||
public static void Update()
|
||||
{
|
||||
// Check Force-Unlock input
|
||||
if (InputHelper.GetKeyDown(KeyCode.LeftAlt))
|
||||
if (InputManager.GetKeyDown(KeyCode.LeftAlt))
|
||||
{
|
||||
ForceUnlockMouse = !ForceUnlockMouse;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Explorer
|
||||
{
|
||||
if (ExplorerCore.ShowMenu)
|
||||
{
|
||||
if (InputHelper.GetKey(KeyCode.LeftShift) && InputHelper.GetMouseButtonDown(1))
|
||||
if (InputManager.GetKey(KeyCode.LeftShift) && InputManager.GetMouseButtonDown(1))
|
||||
{
|
||||
EnableInspect = !EnableInspect;
|
||||
}
|
||||
@ -33,7 +33,7 @@ namespace Explorer
|
||||
if (!UnityHelpers.MainCamera)
|
||||
return;
|
||||
|
||||
var ray = UnityHelpers.MainCamera.ScreenPointToRay(InputHelper.MousePosition);
|
||||
var ray = UnityHelpers.MainCamera.ScreenPointToRay(InputManager.MousePosition);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 1000f))
|
||||
{
|
||||
@ -41,7 +41,7 @@ namespace Explorer
|
||||
|
||||
m_objUnderMouseName = obj.transform.GetGameObjectPath();
|
||||
|
||||
if (InputHelper.GetMouseButtonDown(0))
|
||||
if (InputManager.GetMouseButtonDown(0))
|
||||
{
|
||||
EnableInspect = false;
|
||||
m_objUnderMouseName = "";
|
||||
@ -61,7 +61,7 @@ namespace Explorer
|
||||
{
|
||||
if (m_objUnderMouseName != "")
|
||||
{
|
||||
var pos = InputHelper.MousePosition;
|
||||
var pos = InputManager.MousePosition;
|
||||
var rect = new Rect(
|
||||
pos.x - (Screen.width / 2), // x
|
||||
Screen.height - pos.y - 50, // y
|
||||
|
@ -45,6 +45,7 @@ namespace Explorer
|
||||
MethodInput = @"// This is a basic C# console.
|
||||
// Some common using directives are added by default, you can add more below.
|
||||
// If you want to return some output, Debug.Log() or MelonLogger.Log() it.
|
||||
|
||||
"
|
||||
#if ML
|
||||
+ @"MelonLogger.Log(""hello world"");";
|
||||
|
@ -38,18 +38,18 @@ namespace Explorer
|
||||
//var r = GUILayoutUtility.GetLastRect();
|
||||
var r = Internal_LayoutUtility.GetLastRect();
|
||||
|
||||
var mousePos = InputHelper.MousePosition;
|
||||
var mousePos = InputManager.MousePosition;
|
||||
|
||||
try
|
||||
{
|
||||
var mouse = GUIUnstrip.ScreenToGUIPoint(new Vector2(mousePos.x, Screen.height - mousePos.y));
|
||||
if (r.Contains(mouse) && InputHelper.GetMouseButtonDown(0))
|
||||
if (r.Contains(mouse) && InputManager.GetMouseButtonDown(0))
|
||||
{
|
||||
isResizing = true;
|
||||
m_currentWindow = ID;
|
||||
m_currentResize = new Rect(mouse.x, mouse.y, _rect.width, _rect.height);
|
||||
}
|
||||
else if (!InputHelper.GetMouseButton(0))
|
||||
else if (!InputManager.GetMouseButton(0))
|
||||
{
|
||||
isResizing = false;
|
||||
}
|
||||
@ -125,16 +125,16 @@ namespace Explorer
|
||||
//var r = GUILayoutUtility.GetLastRect();
|
||||
var r = GUILayoutUtility.GetLastRect();
|
||||
|
||||
var mousePos = InputHelper.MousePosition;
|
||||
var mousePos = InputManager.MousePosition;
|
||||
|
||||
var mouse = GUIUnstrip.ScreenToGUIPoint(new Vector2(mousePos.x, Screen.height - mousePos.y));
|
||||
if (r.Contains(mouse) && InputHelper.GetMouseButtonDown(0))
|
||||
if (r.Contains(mouse) && InputManager.GetMouseButtonDown(0))
|
||||
{
|
||||
isResizing = true;
|
||||
m_currentWindow = ID;
|
||||
m_currentResize = new Rect(mouse.x, mouse.y, _rect.width, _rect.height);
|
||||
}
|
||||
else if (!InputHelper.GetMouseButton(0))
|
||||
else if (!InputManager.GetMouseButton(0))
|
||||
{
|
||||
isResizing = false;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ namespace Explorer
|
||||
DestroyWindow();
|
||||
return;
|
||||
}
|
||||
else if (Target is UnityEngine.Object uObj)
|
||||
if (Target is UnityEngine.Object uObj)
|
||||
{
|
||||
if (!uObj)
|
||||
{
|
||||
|
@ -78,13 +78,15 @@ namespace Explorer
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
ExplorerCore.Log("Target is null!");
|
||||
DestroyWindow();
|
||||
return;
|
||||
}
|
||||
else if (Target is UnityEngine.Object uObj)
|
||||
if (Target is UnityEngine.Object uObj)
|
||||
{
|
||||
if (!uObj)
|
||||
{
|
||||
ExplorerCore.Log("Target was destroyed!");
|
||||
DestroyWindow();
|
||||
return;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ namespace Explorer
|
||||
{
|
||||
createdNew = false;
|
||||
|
||||
if (InputHelper.GetKey(KeyCode.LeftShift))
|
||||
if (InputManager.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
forceReflection = true;
|
||||
}
|
||||
@ -189,7 +189,7 @@ namespace Explorer
|
||||
|
||||
private static bool RectContainsMouse(Rect rect)
|
||||
{
|
||||
var mousePos = InputHelper.MousePosition;
|
||||
var mousePos = InputManager.MousePosition;
|
||||
return rect.Contains(new Vector2(mousePos.x, Screen.height - mousePos.y));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user