Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit d39fea6

Browse files
committed
Better InputSystem Key enum resolving
1 parent 95e8b3a commit d39fea6

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/Core/Input/InputSystem.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityExplorer.UI;
77
using System.Collections.Generic;
88
using UnityExplorer.UI.Inspectors;
9+
using System.Linq;
910

1011
namespace UnityExplorer.Core.Input
1112
{
@@ -84,16 +85,28 @@ public Vector2 MousePosition
8485
}
8586

8687
internal static Dictionary<KeyCode, object> ActualKeyDict = new Dictionary<KeyCode, object>();
88+
internal static Dictionary<string, string> enumNameFixes = new Dictionary<string, string>
89+
{
90+
{ "Control", "Ctrl" },
91+
{ "Return", "Enter" },
92+
{ "Alpha", "Digit" },
93+
{ "Keypad", "Numpad" },
94+
{ "Numlock", "NumLock" },
95+
{ "Print", "PrintScreen" },
96+
{ "BackQuote", "Backquote" }
97+
};
8798

8899
internal object GetActualKey(KeyCode key)
89100
{
90101
if (!ActualKeyDict.ContainsKey(key))
91102
{
92103
var s = key.ToString();
93-
if (s.Contains("Control"))
94-
s = s.Replace("Control", "Ctrl");
95-
else if (s.Contains("Return"))
96-
s = "Enter";
104+
try
105+
{
106+
if (enumNameFixes.First(it => s.Contains(it.Key)) is KeyValuePair<string, string> entry)
107+
s = s.Replace(entry.Key, entry.Value);
108+
}
109+
catch { }
97110

98111
var parsed = Enum.Parse(TKey, s);
99112
var actualKey = m_kbIndexer.GetValue(CurrentKeyboard, new object[] { parsed });

src/ExplorerCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static void Init(IExplorerLoader loader)
4848

4949
Log($"{NAME} {VERSION} initialized.");
5050

51-
InspectorManager.Instance.Inspect(typeof(TestClass));
51+
//InspectorManager.Instance.Inspect(typeof(TestClass));
5252
}
5353

5454
public static void Update()

0 commit comments

Comments
 (0)