UnityExplorer/src/Input/InputManager.cs

84 lines
2.9 KiB
C#
Raw Normal View History

using System;
using UnityEngine;
using ExplorerBeta.Helpers;
using System.Diagnostics.CodeAnalysis;
#if CPP
using UnhollowerBaseLib;
#endif
namespace ExplorerBeta.Input
{
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Unity style")]
public static class InputManager
{
private static IHandleInput m_inputModule;
public static void Init()
{
if (InputSystem.TKeyboard != null || (ReflectionHelpers.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
{
m_inputModule = new InputSystem();
}
else if (LegacyInput.TInput != null || (ReflectionHelpers.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
{
m_inputModule = new LegacyInput();
}
2020-10-08 06:15:42 +11:00
if (m_inputModule == null)
{
ExplorerCore.LogWarning("Could not find any Input module!");
m_inputModule = new NoInput();
}
}
public static Vector3 MousePosition => m_inputModule.MousePosition;
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) => m_inputModule.GetMouseButtonDown(btn);
public static bool GetMouseButton(int btn) => m_inputModule.GetMouseButton(btn);
#if CPP
internal delegate void d_ResetInputAxes();
2020-10-16 19:40:01 +11:00
public static void ResetInputAxes() => ICallHelper.GetICall<d_ResetInputAxes>("UnityEngine.Input::ResetInputAxes").Invoke();
#else
public static void ResetInputAxes() => UnityEngine.Input.ResetInputAxes();
#endif
2020-10-14 20:47:19 +11:00
#if CPP
// public extern static string compositionString { get; }
2020-10-14 20:47:19 +11:00
internal delegate IntPtr d_get_compositionString();
2020-10-16 19:40:01 +11:00
public static string compositionString
{
get
{
var iCall = ICallHelper.GetICall<d_get_compositionString>("UnityEngine.Input::get_compositionString");
return IL2CPP.Il2CppStringToManaged(iCall.Invoke());
}
}
2020-10-14 20:47:19 +11:00
// public extern static Vector2 compositionCursorPos { get; set; }
2020-10-14 20:47:19 +11:00
internal delegate void d_get_compositionCursorPos(out Vector2 ret);
2020-10-16 19:40:01 +11:00
internal delegate void d_set_compositionCursorPos(ref Vector2 value);
2020-10-14 20:47:19 +11:00
public static Vector2 compositionCursorPos
{
get
{
2020-10-16 19:40:01 +11:00
var iCall = ICallHelper.GetICall<d_get_compositionCursorPos>("UnityEngine.Input::get_compositionCursorPos_Injected");
iCall.Invoke(out Vector2 ret);
2020-10-14 20:47:19 +11:00
return ret;
}
2020-10-16 19:40:01 +11:00
set
{
var iCall = ICallHelper.GetICall<d_set_compositionCursorPos>("UnityEngine.Input::set_compositionCursorPos_Injected");
iCall.Invoke(ref value);
}
2020-10-14 20:47:19 +11:00
}
#endif
}
}