Skip to content

Commit 549d10d

Browse files
authored
Build Hotfix
A simple Hotfix to make the system runs on Build
1 parent db2d045 commit 549d10d

File tree

2 files changed

+119
-27
lines changed

2 files changed

+119
-27
lines changed

Editor/KeyDrawer.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
1515

1616
// Set the position to draw fields
1717
Rect keyCodeRect = new Rect(position.x, position.y, position.width / 2 - 20, EditorGUIUtility.singleLineHeight);
18+
//Rect mouseButtonRect = new Rect(position.x + position.width / 4 - 20, position.y, position.width / 4 - 20, EditorGUIUtility.singleLineHeight);
19+
1820
Rect buttonRect = new Rect(position.x + position.width / 2 - 1, position.y, (position.width / 2) - 26, EditorGUIUtility.singleLineHeight);
1921
Rect cancelButtonRect = new Rect(position.x + position.width - 28, position.y, 20, EditorGUIUtility.singleLineHeight);
2022

@@ -23,6 +25,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
2325

2426
// Draw the fields
2527
EditorGUI.PropertyField(keyCodeRect, property.FindPropertyRelative("keyCode"), new GUIContent("Key"));
28+
//EditorGUI.PropertyField(mouseButtonRect, property.FindPropertyRelative("mouseButton"), new GUIContent("Mouse"));
2629

2730
// Draw Bind Button
2831
bool isBinding = currentBindingProperty == propertyPath;
@@ -34,6 +37,32 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
3437
currentBindingProperty = null;
3538
Event.current.Use();
3639
}
40+
else
41+
{
42+
if (Event.current.type == EventType.MouseDown)
43+
{
44+
if (Event.current.button == 0)
45+
{
46+
property.FindPropertyRelative("keyCode").intValue = (int)KeyCode.Mouse0;
47+
currentBindingProperty = null;
48+
Event.current.Use();
49+
}
50+
51+
if (Event.current.button == 1)
52+
{
53+
property.FindPropertyRelative("keyCode").intValue = (int)KeyCode.Mouse1;
54+
currentBindingProperty = null;
55+
Event.current.Use();
56+
}
57+
58+
if (Event.current.button == 2)
59+
{
60+
property.FindPropertyRelative("keyCode").intValue = (int)KeyCode.Mouse2;
61+
currentBindingProperty = null;
62+
Event.current.Use();
63+
}
64+
}
65+
}
3766
isBinding = GUI.Toggle(buttonRect, isBinding, "Press key to bind", GUI.skin.button);
3867
}
3968
else

Runtime/InputSystem.cs

Lines changed: 90 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using UnityEngine;
22
using UnityEngine.InputSystem;
3+
using System.Linq;
4+
35

46
#if UNITY_EDITOR
57
using UnityEditor;
@@ -263,7 +265,7 @@ public static button SearchButton(string name)
263265
button r = null;
264266
for (int i = 0; i < main.settings.m_Inputs.Buttons.Length; i++)
265267
{
266-
if (main.settings.m_Inputs.Buttons[i].m_name == name)
268+
if (main.settings.m_Inputs.Buttons[i].m_name.ToLower() == name.ToLower())
267269
{
268270
r = main.settings.m_Inputs.Buttons[i];
269271
break;
@@ -299,6 +301,10 @@ public static bool GetButton(string name)
299301
}
300302
public static bool GetButtonDown(string name)
301303
{
304+
if (string.IsNullOrEmpty(name))
305+
{
306+
return false;
307+
}
302308
return SearchButton(name).isDown;
303309
}
304310
public static bool GetButtonUp(string name)
@@ -309,10 +315,90 @@ public static Vector2 GetAxis(string name)
309315
{
310316
return SearchAxis(name).value;
311317
}
318+
public static string GetButtonName(string name)
319+
{
320+
string r = "<h1>[" + GetButtonNameRaw(name) + "]</h1>";
321+
322+
if (r == "<h1>[Mouse0]</h1>")
323+
{
324+
r = "<h1>[LMB]</h1>";
325+
}
326+
327+
if (r == "<h1>[Mouse1]</h1>")
328+
{
329+
r = "<h1>[RMB]</h1>";
330+
}
331+
332+
if (r == "<h1>[Mouse2]</h1>")
333+
{
334+
r = "<h1>[Scroll Button]</h1>";
335+
}
336+
337+
return r;
338+
}
339+
public static string GetButtonNameRaw(string name)
340+
{
341+
return SearchButton(name).keys[0].keyCode.ToString();
342+
}
343+
344+
345+
public void SetButtonNames()
346+
{
347+
//Set Button Names
348+
for (int i = 0; i < settings.m_Inputs.Buttons.Length; i++)
349+
{
350+
if (string.IsNullOrEmpty(settings.m_Inputs.Buttons[i].Name))
351+
{
352+
settings.m_Inputs.Buttons[i].m_name = settings.m_Inputs.Buttons[i].keys[0].keyCode.ToString();
353+
}
354+
else
355+
{
356+
settings.m_Inputs.Buttons[i].m_name = settings.m_Inputs.Buttons[i].Name;
357+
}
358+
}
359+
}
360+
public void SetAxisNames()
361+
{
362+
//Set Axis Names
363+
for (int i = 0; i < settings.m_Inputs.Axis.Length; i++)
364+
{
365+
if (string.IsNullOrEmpty(settings.m_Inputs.Axis[i].Name))
366+
{
367+
settings.m_Inputs.Axis[i].m_name = settings.m_Inputs.Axis[i].type.ToString();
368+
}
369+
else
370+
{
371+
settings.m_Inputs.Axis[i].m_name = settings.m_Inputs.Axis[i].Name;
372+
}
373+
}
374+
}
312375

313376
//Mono
377+
public void Awake()
378+
{
379+
Debug.Log("InputSettings: " + settings.name);
380+
DontDestroyOnLoad(gameObject);
381+
}
382+
private void Start()
383+
{
384+
SetButtonNames();
385+
SetAxisNames();
386+
}
314387
private void Update()
315388
{
389+
DebugVar.Log("Current InputSystem", settings.name, this);
390+
DebugVar.Log("Current InputSystem Axis", settings.m_Inputs.Axis.Length, this);
391+
392+
string axisBtns = "";
393+
for (int i = 0; i < settings.m_Inputs.Axis.Length; i++)
394+
{
395+
axisBtns += settings.m_Inputs.Axis[i].m_name + "\n";
396+
}
397+
DebugVar.Log("Current InputSystem Axis", settings.m_Inputs.Axis.Length + "\n" + axisBtns, this);
398+
399+
DebugVar.Log("Current InputSystem Btns", settings.m_Inputs.Buttons.Length, this);
400+
401+
316402
//Update Buttons
317403
for (int i = 0; i < settings.m_Inputs.Buttons.Length; i++)
318404
{
@@ -326,6 +412,7 @@ private void Update()
326412
}
327413
}
328414

415+
329416
public void OnValidate()
330417
{
331418
if (!settings)
@@ -338,32 +425,8 @@ public void OnValidate()
338425
{
339426
inputs = settings.m_Inputs;
340427
}
341-
342-
//Set Button Names
343-
for (int i = 0; i < settings.m_Inputs.Buttons.Length; i++)
344-
{
345-
if (string.IsNullOrEmpty(settings.m_Inputs.Buttons[i].Name))
346-
{
347-
settings.m_Inputs.Buttons[i].m_name = settings.m_Inputs.Buttons[i].keys[0].keyCode.ToString();
348-
}
349-
else
350-
{
351-
settings.m_Inputs.Buttons[i].m_name = settings.m_Inputs.Buttons[i].Name;
352-
}
353-
}
354-
355-
//Set Axis Names
356-
for (int i = 0; i < settings.m_Inputs.Axis.Length; i++)
357-
{
358-
if (string.IsNullOrEmpty(settings.m_Inputs.Axis[i].Name))
359-
{
360-
settings.m_Inputs.Axis[i].m_name = settings.m_Inputs.Axis[i].type.ToString();
361-
}
362-
else
363-
{
364-
settings.m_Inputs.Axis[i].m_name = settings.m_Inputs.Axis[i].Name;
365-
}
366-
}
428+
SetButtonNames();
429+
SetAxisNames();
367430
}
368431
}
369432
}

0 commit comments

Comments
 (0)