Add proper support for InputSystem

This commit is contained in:
Sinai 2021-04-05 16:28:30 +10:00
parent 6ca117b070
commit 09dae6f1d3
8 changed files with 74 additions and 44 deletions

View File

@ -15,8 +15,6 @@ namespace UnityExplorer.Core.Input
BaseInputModule UIModule { get; }
PointerEventData InputPointerEvent { get; }
void AddUIInputModule();
void ActivateModule();
}

View File

@ -27,7 +27,6 @@ namespace UnityExplorer.Core.Input
public static bool GetMouseButton(int btn) => m_inputModule.GetMouseButton(btn);
public static BaseInputModule UIInput => m_inputModule.UIModule;
public static PointerEventData InputPointerEvent => m_inputModule.InputPointerEvent;
public static void ActivateUIModule() => m_inputModule.ActivateModule();
@ -52,7 +51,7 @@ namespace UnityExplorer.Core.Input
if (m_inputModule == null)
{
ExplorerCore.LogWarning("Could not find any Input module!");
ExplorerCore.LogWarning("Could not find any Input Module Type!");
m_inputModule = new NoInput();
CurrentType = InputType.None;
}

View File

@ -5,6 +5,10 @@ using UnityEngine;
using UnityEngine.EventSystems;
using UnityExplorer.UI;
using System.Collections.Generic;
using UnityExplorer.UI.Inspectors;
#if CPP
using UnhollowerRuntimeLib;
#endif
namespace UnityExplorer.Core.Input
{
@ -131,41 +135,74 @@ namespace UnityExplorer.Core.Input
// UI Input
//public Type TInputSystemUIInputModule
// => m_tUIInputModule
// ?? (m_tUIInputModule = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.UI.InputSystemUIInputModule"));
//internal Type m_tUIInputModule;
public Type TInputSystemUIInputModule
=> m_tUIInputModule
?? (m_tUIInputModule = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.UI.InputSystemUIInputModule"));
internal Type m_tUIInputModule;
public BaseInputModule UIModule => null; // m_newInputModule;
//internal BaseInputModule m_newInputModule;
public PointerEventData InputPointerEvent => null;
public BaseInputModule UIModule => m_newInputModule;
internal BaseInputModule m_newInputModule;
public void AddUIInputModule()
{
// if (TInputSystemUIInputModule != null)
// {
//#if CPP
// // m_newInputModule = UIManager.CanvasRoot.AddComponent(Il2CppType.From(TInputSystemUIInputModule)).TryCast<BaseInputModule>();
//#else
// m_newInputModule = (BaseInputModule)UIManager.CanvasRoot.AddComponent(TInputSystemUIInputModule);
//#endif
// }
// else
// {
// ExplorerCore.LogWarning("New input system: Could not find type by name 'UnityEngine.InputSystem.UI.InputSystemUIInputModule'");
// }
if (TInputSystemUIInputModule == null)
{
ExplorerCore.LogWarning("Unable to find UI Input Module Type, Input will not work!");
return;
}
var assetType = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionAsset");
#if CPP
m_newInputModule = UIManager.CanvasRoot.AddComponent(Il2CppType.From(TInputSystemUIInputModule)).TryCast<BaseInputModule>();
var asset = ScriptableObject.CreateInstance(Il2CppType.From(assetType));
#else
m_newInputModule = (BaseInputModule)UIManager.CanvasRoot.AddComponent(TInputSystemUIInputModule);
var asset = ScriptableObject.CreateInstance(assetType);
#endif
inputExtensions = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionSetupExtensions");
var addMap = inputExtensions.GetMethod("AddActionMap", new Type[] { assetType, typeof(string) });
var map = addMap.Invoke(null, new object[] { asset, "UI" });
CreateAction(map, "point", new[] { "<Mouse>/position" }, "point");
CreateAction(map, "click", new[] { "<Mouse>/leftButton" }, "leftClick");
CreateAction(map, "rightClick", new[] { "<Mouse>/rightButton" }, "rightClick");
CreateAction(map, "scrollWheel", new[] { "<Mouse>/scroll" }, "scrollWheel");
UI_Enable = map.GetType().GetMethod("Enable");
UI_Enable.Invoke(map, new object[0]);
UI_ActionMap = map;
}
private Type inputExtensions;
private object UI_ActionMap;
private MethodInfo UI_Enable;
private void CreateAction(object map, string actionName, string[] bindings, string propertyName)
{
var addAction = inputExtensions.GetMethod("AddAction");
var pointAction = addAction.Invoke(null, new object[] { map, actionName, default, null, null, null, null, null });
var inputActionType = pointAction.GetType();
var addBinding = inputExtensions.GetMethod("AddBinding",
new Type[] { inputActionType, typeof(string), typeof(string), typeof(string), typeof(string) });
foreach (string binding in bindings)
addBinding.Invoke(null, new object[] { pointAction, binding, null, null, null });
var inputRef = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionReference")
.GetMethod("Create")
.Invoke(null, new object[] { pointAction });
TInputSystemUIInputModule
.GetProperty(propertyName)
.SetValue(m_newInputModule, inputRef, null);
}
public void ActivateModule()
{
//#if CPP
// // m_newInputModule.ActivateModule();
//#else
// m_newInputModule.ActivateModule();
//#endif
m_newInputModule.ActivateModule();
UI_Enable.Invoke(UI_ActionMap, new object[0]);
}
}
}

View File

@ -44,13 +44,6 @@ namespace UnityExplorer.Core.Input
public BaseInputModule UIModule => m_inputModule;
internal StandaloneInputModule m_inputModule;
public PointerEventData InputPointerEvent =>
#if CPP
m_inputModule.m_InputPointerEvent;
#else
null;
#endif
public void AddUIInputModule()
{
m_inputModule = UIManager.CanvasRoot.gameObject.AddComponent<StandaloneInputModule>();

View File

@ -16,7 +16,6 @@ namespace UnityExplorer.Core.Input
public bool GetMouseButtonDown(int btn) => false;
public BaseInputModule UIModule => null;
public PointerEventData InputPointerEvent => null;
public void ActivateModule() { }
public void AddUIInputModule() { }
}

View File

@ -13,7 +13,7 @@ namespace UnityExplorer
public class ExplorerCore
{
public const string NAME = "UnityExplorer";
public const string VERSION = "3.3.6";
public const string VERSION = "3.3.7";
public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.unityexplorer";

View File

@ -31,8 +31,8 @@ namespace UnityExplorer.UI.InteractiveValues
// arbitrarily check some types, fastest methods first.
if (type == typeof(bool))
return typeof(InteractiveBool);
// if type is primitive then it must be a number if its not a bool
else if (type.IsPrimitive)
// if type is primitive then it must be a number if its not a bool. Also check for decimal.
else if (type.IsPrimitive || type == typeof(decimal))
return typeof(InteractiveNumber);
// check for strings
else if (type == typeof(string))

View File

@ -140,6 +140,8 @@ namespace UnityExplorer.UI
ExplorerCore.Log("This game does not ship with the 'UI/Default' shader, using manual Default Shader...");
Graphic.defaultGraphicMaterial.shader = BackupShader;
}
else
BackupShader = Graphic.defaultGraphicMaterial.shader;
ConsoleFont = bundle.LoadAsset<Font>("CONSOLA");
@ -148,9 +150,11 @@ namespace UnityExplorer.UI
private static AssetBundle LoadExplorerUi(string id)
{
var data = ReadFully(typeof(ExplorerCore)
var stream = typeof(ExplorerCore)
.Assembly
.GetManifestResourceStream($"UnityExplorer.Resources.explorerui.{id}.bundle"));
.GetManifestResourceStream($"UnityExplorer.Resources.explorerui.{id}.bundle");
var data = ReadFully(stream);
return AssetBundle.LoadFromMemory(data);
}