mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-22 16:42:38 +08:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
adfa29e63c | |||
3ffdcea73b | |||
dfd55260a8 | |||
29c78dc5a6 |
@ -12,6 +12,8 @@ namespace UnityExplorer.Core.Input
|
|||||||
{
|
{
|
||||||
public InputSystem()
|
public InputSystem()
|
||||||
{
|
{
|
||||||
|
SetupSupportedDevices();
|
||||||
|
|
||||||
m_kbCurrentProp = TKeyboard.GetProperty("current");
|
m_kbCurrentProp = TKeyboard.GetProperty("current");
|
||||||
m_kbIndexer = TKeyboard.GetProperty("Item", new Type[] { TKey });
|
m_kbIndexer = TKeyboard.GetProperty("Item", new Type[] { TKey });
|
||||||
|
|
||||||
@ -32,7 +34,37 @@ namespace UnityExplorer.Core.Input
|
|||||||
.GetMethod("ReadValue");
|
.GetMethod("ReadValue");
|
||||||
}
|
}
|
||||||
|
|
||||||
#region reflection cache
|
internal static void SetupSupportedDevices()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// typeof(InputSystem)
|
||||||
|
Type TInputSystem = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputSystem");
|
||||||
|
// InputSystem.settings
|
||||||
|
var settings = TInputSystem.GetProperty("settings", BindingFlags.Public | BindingFlags.Static).GetValue(null, null);
|
||||||
|
// typeof(InputSettings)
|
||||||
|
Type TSettings = settings.GetActualType();
|
||||||
|
// InputSettings.supportedDevices
|
||||||
|
PropertyInfo supportedProp = TSettings.GetProperty("supportedDevices", BindingFlags.Public | BindingFlags.Instance);
|
||||||
|
var supportedDevices = supportedProp.GetValue(settings, null);
|
||||||
|
// An empty supportedDevices list means all devices are supported.
|
||||||
|
#if CPP
|
||||||
|
// weird hack for il2cpp, use the implicit operator and cast Il2CppStringArray to ReadOnlyArray<string>
|
||||||
|
var args = new object[] { new UnhollowerBaseLib.Il2CppStringArray(0) };
|
||||||
|
var method = supportedDevices.GetActualType().GetMethod("op_Implicit", BindingFlags.Static | BindingFlags.Public);
|
||||||
|
supportedProp.SetValue(settings, method.Invoke(null, args), null);
|
||||||
|
#else
|
||||||
|
supportedProp.SetValue(settings, Activator.CreateInstance(supportedDevices.GetActualType(), new object[] { new string[0] }), null);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ExplorerCore.LogWarning($"Exception setting up InputSystem.settings.supportedDevices list!");
|
||||||
|
ExplorerCore.Log(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region reflection cache
|
||||||
|
|
||||||
public static Type TKeyboard => m_tKeyboard ?? (m_tKeyboard = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Keyboard"));
|
public static Type TKeyboard => m_tKeyboard ?? (m_tKeyboard = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.Keyboard"));
|
||||||
private static Type m_tKeyboard;
|
private static Type m_tKeyboard;
|
||||||
@ -73,7 +105,7 @@ namespace UnityExplorer.Core.Input
|
|||||||
private static object m_scrollInfo;
|
private static object m_scrollInfo;
|
||||||
private static PropertyInfo m_scrollDeltaProp;
|
private static PropertyInfo m_scrollDeltaProp;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public Vector2 MousePosition
|
public Vector2 MousePosition
|
||||||
{
|
{
|
||||||
@ -138,6 +170,8 @@ namespace UnityExplorer.Core.Input
|
|||||||
|
|
||||||
public bool GetMouseButtonDown(int btn)
|
public bool GetMouseButtonDown(int btn)
|
||||||
{
|
{
|
||||||
|
if (CurrentMouse == null)
|
||||||
|
return false;
|
||||||
switch (btn)
|
switch (btn)
|
||||||
{
|
{
|
||||||
case 0: return (bool)m_btnWasPressedProp.GetValue(LeftMouseButton, null);
|
case 0: return (bool)m_btnWasPressedProp.GetValue(LeftMouseButton, null);
|
||||||
@ -149,6 +183,8 @@ namespace UnityExplorer.Core.Input
|
|||||||
|
|
||||||
public bool GetMouseButton(int btn)
|
public bool GetMouseButton(int btn)
|
||||||
{
|
{
|
||||||
|
if (CurrentMouse == null)
|
||||||
|
return false;
|
||||||
switch (btn)
|
switch (btn)
|
||||||
{
|
{
|
||||||
case 0: return (bool)m_btnIsPressedProp.GetValue(LeftMouseButton, null);
|
case 0: return (bool)m_btnIsPressedProp.GetValue(LeftMouseButton, null);
|
||||||
|
@ -20,7 +20,7 @@ namespace UnityExplorer
|
|||||||
public static class ExplorerCore
|
public static class ExplorerCore
|
||||||
{
|
{
|
||||||
public const string NAME = "UnityExplorer";
|
public const string NAME = "UnityExplorer";
|
||||||
public const string VERSION = "4.1.9";
|
public const string VERSION = "4.1.10";
|
||||||
public const string AUTHOR = "Sinai";
|
public const string AUTHOR = "Sinai";
|
||||||
public const string GUID = "com.sinai.unityexplorer";
|
public const string GUID = "com.sinai.unityexplorer";
|
||||||
|
|
||||||
|
@ -414,33 +414,29 @@ namespace UnityExplorer.UI
|
|||||||
|
|
||||||
private static void LoadBundle()
|
private static void LoadBundle()
|
||||||
{
|
{
|
||||||
AssetBundle bundle = null;
|
AssetBundle bundle;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Get the Unity version (without the 'f' suffix).
|
// Get the Major and Minor of the Unity version
|
||||||
// I'm not sure if Unity always includes the 'f' suffix.
|
var split = Application.unityVersion.Split('.');
|
||||||
int len;
|
int major = int.Parse(split[0]);
|
||||||
if (Application.unityVersion.Contains("f"))
|
int minor = int.Parse(split[1]);
|
||||||
len = Application.unityVersion.LastIndexOf("f");
|
|
||||||
else
|
|
||||||
len = Application.unityVersion.Length;
|
|
||||||
Version version = new Version(Application.unityVersion.Substring(0, len));
|
|
||||||
|
|
||||||
// Use appropriate AssetBundle for Unity version
|
// Use appropriate AssetBundle for Unity version
|
||||||
// >= 2017.3
|
// >= 2017.3
|
||||||
if (version.Major > 2017 || (version.Major == 2017 && version.Minor >= 3))
|
if (major > 2017 || (major == 2017 && minor >= 3))
|
||||||
bundle = LoadBundle("modern");
|
bundle = LoadBundle("modern");
|
||||||
// 5.6.0 to 2017.3
|
// 5.6.0 to 2017.3
|
||||||
else if (version.Major == 2017 || (version.Major == 5 && version.Minor >= 6))
|
else if (major == 2017 || (major == 5 && minor >= 6))
|
||||||
bundle = LoadBundle("legacy.5.6");
|
bundle = LoadBundle("legacy.5.6");
|
||||||
// < 5.6.0
|
// < 5.6.0
|
||||||
else
|
else
|
||||||
bundle = LoadBundle("legacy");
|
bundle = LoadBundle("legacy");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch
|
||||||
{
|
{
|
||||||
ExplorerCore.LogWarning($"Exception loading Explorer AssetBundle!");
|
ExplorerCore.LogWarning($"Exception parsing Unity version, falling back to old AssetBundle load method...");
|
||||||
ExplorerCore.Log(ex);
|
bundle = LoadBundle("modern") ?? LoadBundle("legacy.5.6") ?? LoadBundle("legacy");
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetBundle LoadBundle(string id)
|
AssetBundle LoadBundle(string id)
|
||||||
|
Reference in New Issue
Block a user