mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-01-10 19:02:08 +08:00
Better InputSystem Key enum resolving
This commit is contained in:
parent
95e8b3aa58
commit
d39fea69c3
@ -6,6 +6,7 @@ using UnityEngine.EventSystems;
|
|||||||
using UnityExplorer.UI;
|
using UnityExplorer.UI;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityExplorer.UI.Inspectors;
|
using UnityExplorer.UI.Inspectors;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace UnityExplorer.Core.Input
|
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<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)
|
internal object GetActualKey(KeyCode key)
|
||||||
{
|
{
|
||||||
if (!ActualKeyDict.ContainsKey(key))
|
if (!ActualKeyDict.ContainsKey(key))
|
||||||
{
|
{
|
||||||
var s = key.ToString();
|
var s = key.ToString();
|
||||||
if (s.Contains("Control"))
|
try
|
||||||
s = s.Replace("Control", "Ctrl");
|
{
|
||||||
else if (s.Contains("Return"))
|
if (enumNameFixes.First(it => s.Contains(it.Key)) is KeyValuePair<string, string> entry)
|
||||||
s = "Enter";
|
s = s.Replace(entry.Key, entry.Value);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
var parsed = Enum.Parse(TKey, s);
|
var parsed = Enum.Parse(TKey, s);
|
||||||
var actualKey = m_kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed });
|
var actualKey = m_kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed });
|
||||||
|
@ -48,7 +48,7 @@ namespace UnityExplorer
|
|||||||
|
|
||||||
Log($"{NAME} {VERSION} initialized.");
|
Log($"{NAME} {VERSION} initialized.");
|
||||||
|
|
||||||
InspectorManager.Instance.Inspect(typeof(TestClass));
|
//InspectorManager.Instance.Inspect(typeof(TestClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Update()
|
public static void Update()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user