* Merged the two builds into one, there is now only one release. Using Reflection for UnityEngine.Input
* A few small fixes and cleanups
This commit is contained in:
sinaioutlander
2020-09-08 06:21:45 +10:00
parent 4aefe1c5a3
commit 4bb0811b2c
10 changed files with 98 additions and 153 deletions

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using UnityEngine;
namespace Explorer
{
/// <summary>
/// Version-agnostic UnityEngine.Input module using Reflection
/// </summary>
public class InputHelper
{
private static readonly Type input = ReflectionHelpers.GetTypeByName("UnityEngine.Input");
private static readonly PropertyInfo mousePositionInfo = input.GetProperty("mousePosition");
private static readonly MethodInfo getKey = input.GetMethod("GetKey", new Type[] { typeof(KeyCode) });
private static readonly MethodInfo getKeyDown = input.GetMethod("GetKeyDown", new Type[] { typeof(KeyCode) });
private static readonly MethodInfo getMouseButtonDown = input.GetMethod("GetMouseButtonDown", new Type[] { typeof(int) });
private static readonly MethodInfo getMouseButton = input.GetMethod("GetMouseButton", new Type[] { typeof(int) });
#pragma warning disable IDE1006 // Camel-case property (Unity style)
public static Vector3 mousePosition => (Vector3)mousePositionInfo.GetValue(null);
#pragma warning restore IDE1006
public static bool GetKeyDown(KeyCode key)
{
return (bool)getKeyDown.Invoke(null, new object[] { key });
}
public static bool GetKey(KeyCode key)
{
return (bool)getKey.Invoke(null, new object[] { key });
}
/// <param name="btn">1 = left, 2 = middle, 3 = right, etc</param>
public static bool GetMouseButtonDown(int btn)
{
return (bool)getMouseButtonDown.Invoke(null, new object[] { btn });
}
/// <param name="btn">1 = left, 2 = middle, 3 = right, etc</param>
public static bool GetMouseButton(int btn)
{
return (bool)getMouseButton.Invoke(null, new object[] { btn });
}
}
}

View File

@ -113,13 +113,13 @@ namespace Explorer
}
}
public static Type GetTypeByName(string typeName)
public static Type GetTypeByName(string fullName)
{
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in GetTypesSafe(asm))
{
if (type.FullName == typeName)
if (type.FullName == fullName)
{
return type;
}

View File

@ -15,7 +15,7 @@ namespace Explorer
{
get
{
if (m_mainCamera == null)
if (!m_mainCamera)
{
m_mainCamera = Camera.main;
}