mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-07-15 07:56:41 +08:00
2.0.5
* Added Max Results option to Search (default 5000) * Fixed a TypeInitializationException which can happen when inspecting some classes with Dictionary members * Fixed an issue which could prevent Input support from initializating * Improved and fixed the display of TextAsset objects * A few other minor fixes
This commit is contained in:
@ -1,21 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
21
src/Input/IAbstractInput.cs
Normal file
21
src/Input/IAbstractInput.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 interface IAbstractInput
|
||||
{
|
||||
void Init();
|
||||
|
||||
Vector2 MousePosition { get; }
|
||||
|
||||
bool GetKeyDown(KeyCode key);
|
||||
bool GetKey(KeyCode key);
|
||||
|
||||
bool GetMouseButtonDown(int btn);
|
||||
bool GetMouseButton(int btn);
|
||||
}
|
||||
}
|
@ -10,37 +10,35 @@ namespace Explorer
|
||||
{
|
||||
public static class InputManager
|
||||
{
|
||||
private static AbstractInput inputModule;
|
||||
private static IAbstractInput m_inputModule;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
if (InputSystem.TKeyboard != null || TryLoadModule("Unity.InputSystem", InputSystem.TKeyboard))
|
||||
if (InputSystem.TKeyboard != null || (ReflectionHelpers.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
|
||||
{
|
||||
inputModule = new InputSystem();
|
||||
m_inputModule = new InputSystem();
|
||||
}
|
||||
else if (LegacyInput.TInput != null || TryLoadModule("UnityEngine.InputLegacyModule", LegacyInput.TInput))
|
||||
else if (LegacyInput.TInput != null || (ReflectionHelpers.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
|
||||
{
|
||||
inputModule = new LegacyInput();
|
||||
m_inputModule = new LegacyInput();
|
||||
}
|
||||
|
||||
if (inputModule == null)
|
||||
if (m_inputModule == null)
|
||||
{
|
||||
ExplorerCore.LogWarning("Could not find any Input module!");
|
||||
inputModule = new NoInput();
|
||||
m_inputModule = new NoInput();
|
||||
}
|
||||
|
||||
inputModule.Init();
|
||||
|
||||
bool TryLoadModule(string dll, Type check) => ReflectionHelpers.LoadModule(dll) && check != null;
|
||||
m_inputModule.Init();
|
||||
}
|
||||
|
||||
public static Vector3 MousePosition => inputModule.MousePosition;
|
||||
public static Vector3 MousePosition => m_inputModule.MousePosition;
|
||||
|
||||
public static bool GetKeyDown(KeyCode key) => inputModule.GetKeyDown(key);
|
||||
public static bool GetKey(KeyCode key) => inputModule.GetKey(key);
|
||||
public static bool GetKeyDown(KeyCode key) => m_inputModule.GetKeyDown(key);
|
||||
public static bool GetKey(KeyCode key) => m_inputModule.GetKey(key);
|
||||
|
||||
public static bool GetMouseButtonDown(int btn) => inputModule.GetMouseButtonDown(btn);
|
||||
public static bool GetMouseButton(int btn) => inputModule.GetMouseButton(btn);
|
||||
public static bool GetMouseButtonDown(int btn) => m_inputModule.GetMouseButtonDown(btn);
|
||||
public static bool GetMouseButton(int btn) => m_inputModule.GetMouseButton(btn);
|
||||
|
||||
#if CPP
|
||||
internal delegate void d_ResetInputAxes();
|
||||
|
@ -7,7 +7,7 @@ using UnityEngine;
|
||||
|
||||
namespace Explorer.Input
|
||||
{
|
||||
public class InputSystem : AbstractInput
|
||||
public class InputSystem : IAbstractInput
|
||||
{
|
||||
public static Type TKeyboard => _keyboard ?? (_keyboard = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.Keyboard"));
|
||||
private static Type _keyboard;
|
||||
@ -43,9 +43,9 @@ namespace Explorer.Input
|
||||
private static PropertyInfo _positionProp;
|
||||
private static MethodInfo _readVector2InputMethod;
|
||||
|
||||
public override Vector2 MousePosition => (Vector2)_readVector2InputMethod.Invoke(MousePositionInfo, new object[0]);
|
||||
public Vector2 MousePosition => (Vector2)_readVector2InputMethod.Invoke(MousePositionInfo, new object[0]);
|
||||
|
||||
public override bool GetKeyDown(KeyCode key)
|
||||
public bool GetKeyDown(KeyCode key)
|
||||
{
|
||||
var parsedKey = Enum.Parse(TKey, key.ToString());
|
||||
var actualKey = _kbIndexer.GetValue(CurrentKeyboard, new object[] { parsedKey });
|
||||
@ -53,7 +53,7 @@ namespace Explorer.Input
|
||||
return (bool)_btnWasPressedProp.GetValue(actualKey, null);
|
||||
}
|
||||
|
||||
public override bool GetKey(KeyCode key)
|
||||
public bool GetKey(KeyCode key)
|
||||
{
|
||||
var parsed = Enum.Parse(TKey, key.ToString());
|
||||
var actualKey = _kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed });
|
||||
@ -61,7 +61,7 @@ namespace Explorer.Input
|
||||
return (bool)_btnIsPressedProp.GetValue(actualKey, null);
|
||||
}
|
||||
|
||||
public override bool GetMouseButtonDown(int btn)
|
||||
public bool GetMouseButtonDown(int btn)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
@ -72,7 +72,7 @@ namespace Explorer.Input
|
||||
}
|
||||
}
|
||||
|
||||
public override bool GetMouseButton(int btn)
|
||||
public bool GetMouseButton(int btn)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
@ -83,7 +83,7 @@ namespace Explorer.Input
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
public void Init()
|
||||
{
|
||||
ExplorerCore.Log("Initializing new InputSystem support...");
|
||||
|
||||
|
@ -7,7 +7,7 @@ using UnityEngine;
|
||||
|
||||
namespace Explorer.Input
|
||||
{
|
||||
public class LegacyInput : AbstractInput
|
||||
public class LegacyInput : IAbstractInput
|
||||
{
|
||||
public static Type TInput => _input ?? (_input = ReflectionHelpers.GetTypeByName("UnityEngine.Input"));
|
||||
private static Type _input;
|
||||
@ -18,17 +18,17 @@ namespace Explorer.Input
|
||||
private static MethodInfo _getMouseButtonMethod;
|
||||
private static MethodInfo _getMouseButtonDownMethod;
|
||||
|
||||
public override Vector2 MousePosition => (Vector3)_mousePositionProp.GetValue(null, null);
|
||||
public Vector2 MousePosition => (Vector3)_mousePositionProp.GetValue(null, null);
|
||||
|
||||
public override bool GetKey(KeyCode key) => (bool)_getKeyMethod.Invoke(null, new object[] { key });
|
||||
public 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 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 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 bool GetMouseButtonDown(int btn) => (bool)_getMouseButtonDownMethod.Invoke(null, new object[] { btn });
|
||||
|
||||
public override void Init()
|
||||
public void Init()
|
||||
{
|
||||
ExplorerCore.Log("Initializing Legacy Input support...");
|
||||
|
||||
|
@ -8,18 +8,16 @@ namespace Explorer.Input
|
||||
{
|
||||
// Just a stub for games where no Input module was able to load at all.
|
||||
|
||||
public class NoInput : AbstractInput
|
||||
public class NoInput : IAbstractInput
|
||||
{
|
||||
public override Vector2 MousePosition => Vector2.zero;
|
||||
public Vector2 MousePosition => Vector2.zero;
|
||||
|
||||
public override bool GetKey(KeyCode key) => false;
|
||||
public bool GetKey(KeyCode key) => false;
|
||||
public bool GetKeyDown(KeyCode key) => false;
|
||||
|
||||
public override bool GetKeyDown(KeyCode key) => false;
|
||||
public bool GetMouseButton(int btn) => false;
|
||||
public bool GetMouseButtonDown(int btn) => false;
|
||||
|
||||
public override bool GetMouseButton(int btn) => false;
|
||||
|
||||
public override bool GetMouseButtonDown(int btn) => false;
|
||||
|
||||
public override void Init() { }
|
||||
public void Init() { }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user