2020-10-03 20:19:44 +10:00
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
2020-10-18 21:41:04 +11:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2020-11-20 17:12:40 +11:00
|
|
|
|
using UnityEngine.EventSystems;
|
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-11-20 17:12:40 +11:00
|
|
|
|
public enum InputType
|
|
|
|
|
{
|
|
|
|
|
InputSystem,
|
|
|
|
|
Legacy,
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-03 20:19:44 +10:00
|
|
|
|
public static class InputManager
|
|
|
|
|
{
|
2020-11-20 17:12:40 +11:00
|
|
|
|
public static InputType CurrentType { get; private set; }
|
|
|
|
|
|
2020-10-28 06:39:26 +11:00
|
|
|
|
private static IHandleInput m_inputModule;
|
2020-10-03 20:19:44 +10:00
|
|
|
|
|
2020-11-19 16:47:18 +11:00
|
|
|
|
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);
|
|
|
|
|
|
2020-11-20 17:12:40 +11:00
|
|
|
|
public static BaseInputModule UIInput => m_inputModule.UIModule;
|
|
|
|
|
public static PointerEventData InputPointerEvent => m_inputModule.InputPointerEvent;
|
|
|
|
|
|
|
|
|
|
public static void ActivateUIModule() => m_inputModule.ActivateModule();
|
|
|
|
|
|
|
|
|
|
public static void AddUIModule()
|
|
|
|
|
{
|
|
|
|
|
m_inputModule.AddUIInputModule();
|
|
|
|
|
ActivateUIModule();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-03 20:19:44 +10:00
|
|
|
|
public static void Init()
|
|
|
|
|
{
|
2021-03-18 17:17:29 +11:00
|
|
|
|
if (InputSystem.TKeyboard != null || (ReflectionUtility.LoadModule("Unity.InputSystem") && InputSystem.TKeyboard != null))
|
2020-10-03 20:19:44 +10:00
|
|
|
|
{
|
2020-10-12 20:15:41 +11:00
|
|
|
|
m_inputModule = new InputSystem();
|
2020-11-20 17:12:40 +11:00
|
|
|
|
CurrentType = InputType.InputSystem;
|
2020-10-03 20:19:44 +10:00
|
|
|
|
}
|
2021-03-18 17:17:29 +11:00
|
|
|
|
else if (LegacyInput.TInput != null || (ReflectionUtility.LoadModule("UnityEngine.InputLegacyModule") && LegacyInput.TInput != null))
|
2020-10-03 20:19:44 +10:00
|
|
|
|
{
|
2020-10-12 20:15:41 +11:00
|
|
|
|
m_inputModule = new LegacyInput();
|
2020-11-20 17:12:40 +11:00
|
|
|
|
CurrentType = InputType.Legacy;
|
2020-10-03 20:19:44 +10:00
|
|
|
|
}
|
2020-10-08 06:15:42 +11:00
|
|
|
|
|
2020-10-12 20:15:41 +11:00
|
|
|
|
if (m_inputModule == null)
|
2020-10-03 20:19:44 +10:00
|
|
|
|
{
|
|
|
|
|
ExplorerCore.LogWarning("Could not find any Input module!");
|
2020-10-12 20:15:41 +11:00
|
|
|
|
m_inputModule = new NoInput();
|
2020-11-20 17:12:40 +11:00
|
|
|
|
CurrentType = InputType.None;
|
2020-10-03 20:19:44 +10:00
|
|
|
|
}
|
2021-03-30 19:50:04 +11:00
|
|
|
|
|
|
|
|
|
CursorUnlocker.Init();
|
2020-10-03 20:19:44 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-09 21:11:15 +11:00
|
|
|
|
}
|