mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-07 18:13:35 +08:00
add MouseScrollDelta support to InputManager
This commit is contained in:
parent
29b453dc91
commit
31fa786574
@ -6,6 +6,7 @@ namespace UnityExplorer.Core.Input
|
|||||||
public interface IHandleInput
|
public interface IHandleInput
|
||||||
{
|
{
|
||||||
Vector2 MousePosition { get; }
|
Vector2 MousePosition { get; }
|
||||||
|
Vector2 MouseScrollDelta { get; }
|
||||||
|
|
||||||
bool GetKeyDown(KeyCode key);
|
bool GetKeyDown(KeyCode key);
|
||||||
bool GetKey(KeyCode key);
|
bool GetKey(KeyCode key);
|
||||||
|
@ -28,6 +28,8 @@ namespace UnityExplorer.Core.Input
|
|||||||
|
|
||||||
public static BaseInputModule UIInput => m_inputModule.UIModule;
|
public static BaseInputModule UIInput => m_inputModule.UIModule;
|
||||||
|
|
||||||
|
public static Vector2 MouseScrollDelta => m_inputModule.MouseScrollDelta;
|
||||||
|
|
||||||
public static void ActivateUIModule() => m_inputModule.ActivateModule();
|
public static void ActivateUIModule() => m_inputModule.ActivateModule();
|
||||||
|
|
||||||
public static void AddUIModule()
|
public static void AddUIModule()
|
||||||
|
@ -24,15 +24,18 @@ namespace UnityExplorer.Core.Input
|
|||||||
m_mouseCurrentProp = TMouse.GetProperty("current");
|
m_mouseCurrentProp = TMouse.GetProperty("current");
|
||||||
m_leftButtonProp = TMouse.GetProperty("leftButton");
|
m_leftButtonProp = TMouse.GetProperty("leftButton");
|
||||||
m_rightButtonProp = TMouse.GetProperty("rightButton");
|
m_rightButtonProp = TMouse.GetProperty("rightButton");
|
||||||
|
m_scrollDeltaProp = TMouse.GetProperty("scroll");
|
||||||
|
|
||||||
m_positionProp = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Pointer")
|
m_positionProp = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Pointer")
|
||||||
.GetProperty("position");
|
.GetProperty("position");
|
||||||
|
|
||||||
m_readVector2InputMethod = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputControl`1")
|
ReadV2ControlMethod = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputControl`1")
|
||||||
.MakeGenericType(typeof(Vector2))
|
.MakeGenericType(typeof(Vector2))
|
||||||
.GetMethod("ReadValue");
|
.GetMethod("ReadValue");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region reflection cache
|
||||||
|
|
||||||
public static Type TKeyboard => m_tKeyboard ?? (m_tKeyboard = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Keyboard"));
|
public static Type TKeyboard => m_tKeyboard ?? (m_tKeyboard = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Keyboard"));
|
||||||
private static Type m_tKeyboard;
|
private static Type m_tKeyboard;
|
||||||
|
|
||||||
@ -62,10 +65,17 @@ namespace UnityExplorer.Core.Input
|
|||||||
private static object m_rmb;
|
private static object m_rmb;
|
||||||
private static PropertyInfo m_rightButtonProp;
|
private static PropertyInfo m_rightButtonProp;
|
||||||
|
|
||||||
|
private static MethodInfo ReadV2ControlMethod;
|
||||||
|
|
||||||
private static object MousePositionInfo => m_pos ?? (m_pos = m_positionProp.GetValue(CurrentMouse, null));
|
private static object MousePositionInfo => m_pos ?? (m_pos = m_positionProp.GetValue(CurrentMouse, null));
|
||||||
private static object m_pos;
|
private static object m_pos;
|
||||||
private static PropertyInfo m_positionProp;
|
private static PropertyInfo m_positionProp;
|
||||||
private static MethodInfo m_readVector2InputMethod;
|
|
||||||
|
private static object MouseScrollInfo => m_scrollInfo ?? (m_scrollInfo = m_scrollDeltaProp.GetValue(CurrentMouse, null));
|
||||||
|
private static object m_scrollInfo;
|
||||||
|
private static PropertyInfo m_scrollDeltaProp;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public Vector2 MousePosition
|
public Vector2 MousePosition
|
||||||
{
|
{
|
||||||
@ -73,12 +83,21 @@ namespace UnityExplorer.Core.Input
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (Vector2)m_readVector2InputMethod.Invoke(MousePositionInfo, new object[0]);
|
return (Vector2)ReadV2ControlMethod.Invoke(MousePositionInfo, new object[0]);
|
||||||
}
|
}
|
||||||
catch
|
catch { return Vector2.zero; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector2 MouseScrollDelta
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return Vector2.zero;
|
return (Vector2)ReadV2ControlMethod.Invoke(MouseScrollInfo, new object[0]);
|
||||||
}
|
}
|
||||||
|
catch { return Vector2.zero; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ namespace UnityExplorer.Core.Input
|
|||||||
ExplorerCore.Log("Initializing Legacy Input support...");
|
ExplorerCore.Log("Initializing Legacy Input support...");
|
||||||
|
|
||||||
m_mousePositionProp = TInput.GetProperty("mousePosition");
|
m_mousePositionProp = TInput.GetProperty("mousePosition");
|
||||||
|
m_mouseDeltaProp = TInput.GetProperty("mouseScrollDelta");
|
||||||
m_getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
|
m_getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
|
||||||
m_getKeyDownMethod = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
|
m_getKeyDownMethod = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
|
||||||
m_getMouseButtonMethod = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) });
|
m_getMouseButtonMethod = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) });
|
||||||
@ -23,6 +24,7 @@ namespace UnityExplorer.Core.Input
|
|||||||
private static Type m_tInput;
|
private static Type m_tInput;
|
||||||
|
|
||||||
private static PropertyInfo m_mousePositionProp;
|
private static PropertyInfo m_mousePositionProp;
|
||||||
|
private static PropertyInfo m_mouseDeltaProp;
|
||||||
private static MethodInfo m_getKeyMethod;
|
private static MethodInfo m_getKeyMethod;
|
||||||
private static MethodInfo m_getKeyDownMethod;
|
private static MethodInfo m_getKeyDownMethod;
|
||||||
private static MethodInfo m_getMouseButtonMethod;
|
private static MethodInfo m_getMouseButtonMethod;
|
||||||
@ -30,6 +32,8 @@ namespace UnityExplorer.Core.Input
|
|||||||
|
|
||||||
public Vector2 MousePosition => (Vector3)m_mousePositionProp.GetValue(null, null);
|
public Vector2 MousePosition => (Vector3)m_mousePositionProp.GetValue(null, null);
|
||||||
|
|
||||||
|
public Vector2 MouseScrollDelta => (Vector2)m_mouseDeltaProp.GetValue(null, null);
|
||||||
|
|
||||||
public bool GetKey(KeyCode key) => (bool)m_getKeyMethod.Invoke(null, new object[] { key });
|
public bool GetKey(KeyCode key) => (bool)m_getKeyMethod.Invoke(null, new object[] { key });
|
||||||
|
|
||||||
public bool GetKeyDown(KeyCode key) => (bool)m_getKeyDownMethod.Invoke(null, new object[] { key });
|
public bool GetKeyDown(KeyCode key) => (bool)m_getKeyDownMethod.Invoke(null, new object[] { key });
|
||||||
|
@ -8,6 +8,7 @@ namespace UnityExplorer.Core.Input
|
|||||||
public class NoInput : IHandleInput
|
public class NoInput : IHandleInput
|
||||||
{
|
{
|
||||||
public Vector2 MousePosition => Vector2.zero;
|
public Vector2 MousePosition => Vector2.zero;
|
||||||
|
public Vector2 MouseScrollDelta => Vector2.zero;
|
||||||
|
|
||||||
public bool GetKey(KeyCode key) => false;
|
public bool GetKey(KeyCode key) => false;
|
||||||
public bool GetKeyDown(KeyCode key) => false;
|
public bool GetKeyDown(KeyCode key) => false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user