Better InputSystem Key enum resolving

This commit is contained in:
Sinai 2021-04-07 20:54:08 +10:00
parent 95e8b3aa58
commit d39fea69c3
2 changed files with 18 additions and 5 deletions

View File

@ -6,6 +6,7 @@ using UnityEngine.EventSystems;
using UnityExplorer.UI;
using System.Collections.Generic;
using UnityExplorer.UI.Inspectors;
using System.Linq;
namespace UnityExplorer.Core.Input
{
@ -84,16 +85,28 @@ namespace UnityExplorer.Core.Input
}
internal static Dictionary<KeyCode, object> ActualKeyDict = new Dictionary<KeyCode, object>();
internal static Dictionary<string, string> enumNameFixes = new Dictionary<string, string>
{
{ "Control", "Ctrl" },
{ "Return", "Enter" },
{ "Alpha", "Digit" },
{ "Keypad", "Numpad" },
{ "Numlock", "NumLock" },
{ "Print", "PrintScreen" },
{ "BackQuote", "Backquote" }
};
internal object GetActualKey(KeyCode key)
{
if (!ActualKeyDict.ContainsKey(key))
{
var s = key.ToString();
if (s.Contains("Control"))
s = s.Replace("Control", "Ctrl");
else if (s.Contains("Return"))
s = "Enter";
try
{
if (enumNameFixes.First(it => s.Contains(it.Key)) is KeyValuePair<string, string> entry)
s = s.Replace(entry.Key, entry.Value);
}
catch { }
var parsed = Enum.Parse(TKey, s);
var actualKey = m_kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed });

View File

@ -48,7 +48,7 @@ namespace UnityExplorer
Log($"{NAME} {VERSION} initialized.");
InspectorManager.Instance.Inspect(typeof(TestClass));
//InspectorManager.Instance.Inspect(typeof(TestClass));
}
public static void Update()