2020-10-03 20:19:44 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
2020-11-03 20:59:13 +11:00
|
|
|
|
using UnityExplorer.Helpers;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
using UnityEngine;
|
2020-10-03 20:19:44 +10:00
|
|
|
|
|
2020-11-03 20:59:13 +11:00
|
|
|
|
namespace UnityExplorer.Input
|
2020-10-03 20:19:44 +10:00
|
|
|
|
{
|
2020-10-28 06:39:26 +11:00
|
|
|
|
public class LegacyInput : IHandleInput
|
2020-10-03 20:19:44 +10:00
|
|
|
|
{
|
2020-10-28 07:14:00 +11:00
|
|
|
|
public LegacyInput()
|
|
|
|
|
{
|
|
|
|
|
ExplorerCore.Log("Initializing Legacy Input support...");
|
|
|
|
|
|
|
|
|
|
m_mousePositionProp = TInput.GetProperty("mousePosition");
|
|
|
|
|
m_getKeyMethod = TInput.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
|
|
|
|
|
m_getKeyDownMethod = TInput.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
|
|
|
|
|
m_getMouseButtonMethod = TInput.GetMethod("GetMouseButton", new Type[] { typeof(int) });
|
|
|
|
|
m_getMouseButtonDownMethod = TInput.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) });
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 21:41:04 +11:00
|
|
|
|
public static Type TInput => m_tInput ?? (m_tInput = ReflectionHelpers.GetTypeByName("UnityEngine.Input"));
|
|
|
|
|
private static Type m_tInput;
|
2020-10-03 20:19:44 +10:00
|
|
|
|
|
2020-10-18 21:41:04 +11:00
|
|
|
|
private static PropertyInfo m_mousePositionProp;
|
|
|
|
|
private static MethodInfo m_getKeyMethod;
|
|
|
|
|
private static MethodInfo m_getKeyDownMethod;
|
|
|
|
|
private static MethodInfo m_getMouseButtonMethod;
|
|
|
|
|
private static MethodInfo m_getMouseButtonDownMethod;
|
2020-10-03 20:19:44 +10:00
|
|
|
|
|
2020-10-18 21:41:04 +11:00
|
|
|
|
public Vector2 MousePosition => (Vector3)m_mousePositionProp.GetValue(null, null);
|
2020-10-03 20:19:44 +10:00
|
|
|
|
|
2020-10-18 21:41:04 +11:00
|
|
|
|
public bool GetKey(KeyCode key) => (bool)m_getKeyMethod.Invoke(null, new object[] { key });
|
2020-10-03 20:19:44 +10:00
|
|
|
|
|
2020-10-18 21:41:04 +11:00
|
|
|
|
public bool GetKeyDown(KeyCode key) => (bool)m_getKeyDownMethod.Invoke(null, new object[] { key });
|
2020-10-03 20:19:44 +10:00
|
|
|
|
|
2020-10-18 21:41:04 +11:00
|
|
|
|
public bool GetMouseButton(int btn) => (bool)m_getMouseButtonMethod.Invoke(null, new object[] { btn });
|
2020-10-03 20:19:44 +10:00
|
|
|
|
|
2020-10-18 21:41:04 +11:00
|
|
|
|
public bool GetMouseButtonDown(int btn) => (bool)m_getMouseButtonDownMethod.Invoke(null, new object[] { btn });
|
2020-10-03 20:19:44 +10:00
|
|
|
|
}
|
|
|
|
|
}
|