2020-10-03 20:19:44 +10:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
2020-10-28 06:39:26 +11:00
|
|
|
|
using UnityEngine;
|
2020-11-20 17:12:40 +11:00
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
using UnityExplorer.UI;
|
2020-10-03 20:19:44 +10:00
|
|
|
|
|
2021-03-18 17:17:29 +11:00
|
|
|
|
namespace UnityExplorer.Core.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()
|
|
|
|
|
{
|
|
|
|
|
m_mousePositionProp = TInput.GetProperty("mousePosition");
|
2021-04-22 03:57:11 +10:00
|
|
|
|
m_mouseDeltaProp = TInput.GetProperty("mouseScrollDelta");
|
2020-10-28 07:14:00 +11:00
|
|
|
|
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) });
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 17:17:29 +11:00
|
|
|
|
public static Type TInput => m_tInput ?? (m_tInput = ReflectionUtility.GetTypeByName("UnityEngine.Input"));
|
2020-10-18 21:41:04 +11:00
|
|
|
|
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;
|
2021-04-22 03:57:11 +10:00
|
|
|
|
private static PropertyInfo m_mouseDeltaProp;
|
2020-10-18 21:41:04 +11:00
|
|
|
|
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
|
|
|
|
|
2021-04-22 03:57:11 +10:00
|
|
|
|
public Vector2 MouseScrollDelta => (Vector2)m_mouseDeltaProp.GetValue(null, null);
|
|
|
|
|
|
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-11-20 17:12:40 +11:00
|
|
|
|
|
|
|
|
|
// UI Input module
|
|
|
|
|
|
|
|
|
|
public BaseInputModule UIModule => m_inputModule;
|
|
|
|
|
internal StandaloneInputModule m_inputModule;
|
|
|
|
|
|
|
|
|
|
public void AddUIInputModule()
|
|
|
|
|
{
|
|
|
|
|
m_inputModule = UIManager.CanvasRoot.gameObject.AddComponent<StandaloneInputModule>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ActivateModule()
|
|
|
|
|
{
|
|
|
|
|
m_inputModule.ActivateModule();
|
|
|
|
|
}
|
2020-10-03 20:19:44 +10:00
|
|
|
|
}
|
2021-04-07 17:20:09 +10:00
|
|
|
|
}
|