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

Commit bc5d160

Browse files
committed
Fix issue with InputSystem
1 parent f81822f commit bc5d160

File tree

6 files changed

+48
-28
lines changed

6 files changed

+48
-28
lines changed

src/Core/Input/CursorUnlocker.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ public static void UpdateCursorControl()
113113

114114
public static void SetEventSystem()
115115
{
116-
if (InputManager.CurrentType == InputType.InputSystem)
117-
return;
118-
119116
if (EventSystem.current && EventSystem.current != UIManager.EventSys)
120117
{
121118
lastEventSystem = EventSystem.current;
@@ -132,14 +129,12 @@ public static void SetEventSystem()
132129

133130
public static void ReleaseEventSystem()
134131
{
135-
if (InputManager.CurrentType == InputType.InputSystem)
136-
return;
137-
138132
if (lastEventSystem && lastEventSystem.gameObject.activeSelf)
139133
{
140134
lastEventSystem.enabled = true;
141135

142136
settingEventSystem = true;
137+
UIManager.EventSys.enabled = false;
143138
EventSystem.current = lastEventSystem;
144139
lastInputModule?.ActivateModule();
145140
settingEventSystem = false;

src/Core/Input/IHandleInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public interface IHandleInput
1414
bool GetMouseButtonDown(int btn);
1515
bool GetMouseButton(int btn);
1616

17-
BaseInputModule UIModule { get; }
17+
BaseInputModule UIInputModule { get; }
1818

1919
void AddUIInputModule();
2020
void ActivateModule();

src/Core/Input/InputManager.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Diagnostics.CodeAnalysis;
33
using UnityEngine;
44
using UnityEngine.EventSystems;
5+
using UnityExplorer.UI;
56

67
namespace UnityExplorer.Core.Input
78
{
@@ -16,37 +17,42 @@ public static class InputManager
1617
{
1718
public static InputType CurrentType { get; private set; }
1819

19-
private static IHandleInput m_inputModule;
20+
private static IHandleInput m_inputHandler;
2021

21-
public static Vector3 MousePosition => m_inputModule.MousePosition;
22+
public static Vector3 MousePosition => m_inputHandler.MousePosition;
2223

2324
public static bool GetKeyDown(KeyCode key)
2425
{
2526
if (key == KeyCode.None)
2627
return false;
27-
return m_inputModule.GetKeyDown(key);
28+
return m_inputHandler.GetKeyDown(key);
2829
}
2930

3031
public static bool GetKey(KeyCode key)
3132
{
3233
if (key == KeyCode.None)
3334
return false;
34-
return m_inputModule.GetKey(key);
35+
return m_inputHandler.GetKey(key);
3536
}
3637

37-
public static bool GetMouseButtonDown(int btn) => m_inputModule.GetMouseButtonDown(btn);
38-
public static bool GetMouseButton(int btn) => m_inputModule.GetMouseButton(btn);
38+
public static bool GetMouseButtonDown(int btn) => m_inputHandler.GetMouseButtonDown(btn);
39+
public static bool GetMouseButton(int btn) => m_inputHandler.GetMouseButton(btn);
3940

40-
public static BaseInputModule UIInput => m_inputModule.UIModule;
41+
public static BaseInputModule UIInput => m_inputHandler.UIInputModule;
4142

42-
public static Vector2 MouseScrollDelta => m_inputModule.MouseScrollDelta;
43-
44-
public static void ActivateUIModule() => m_inputModule.ActivateModule();
43+
public static Vector2 MouseScrollDelta => m_inputHandler.MouseScrollDelta;
4544

4645
public static void AddUIModule()
4746
{
48-
m_inputModule.AddUIInputModule();
49-
ActivateUIModule();
47+
m_inputHandler.AddUIInputModule();
48+
//ActivateUIModule();
49+
CursorUnlocker.SetEventSystem();
50+
}
51+
52+
public static void ActivateUIModule()
53+
{
54+
UIManager.EventSys.m_CurrentInputModule = UIInput;
55+
m_inputHandler.ActivateModule();
5056
}
5157

5258
public static void Init()
@@ -65,7 +71,7 @@ private static void InitHandler()
6571
{
6672
try
6773
{
68-
m_inputModule = new LegacyInput();
74+
m_inputHandler = new LegacyInput();
6975
CurrentType = InputType.Legacy;
7076

7177
// make sure its working
@@ -84,7 +90,7 @@ private static void InitHandler()
8490
{
8591
try
8692
{
87-
m_inputModule = new InputSystem();
93+
m_inputHandler = new InputSystem();
8894
CurrentType = InputType.InputSystem;
8995
ExplorerCore.Log("Initialized new InputSystem support.");
9096
return;
@@ -96,7 +102,7 @@ private static void InitHandler()
96102
}
97103

98104
ExplorerCore.LogWarning("Could not find any Input Module Type!");
99-
m_inputModule = new NoInput();
105+
m_inputHandler = new NoInput();
100106
CurrentType = InputType.None;
101107
}
102108
}

src/Core/Input/InputSystem.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public Type TInputSystemUIInputModule
201201
?? (m_tUIInputModule = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.UI.InputSystemUIInputModule"));
202202
internal Type m_tUIInputModule;
203203

204-
public BaseInputModule UIModule => m_newInputModule;
204+
public BaseInputModule UIInputModule => m_newInputModule;
205205
internal BaseInputModule m_newInputModule;
206206

207207
public void AddUIInputModule()
@@ -239,6 +239,9 @@ public void AddUIInputModule()
239239

240240
private void CreateAction(object map, string actionName, string[] bindings, string propertyName)
241241
{
242+
var disable = map.GetType().GetMethod("Disable");
243+
disable.Invoke(map, ArgumentUtility.EmptyArgs);
244+
242245
var inputActionType = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputAction");
243246
var addAction = inputExtensions.GetMethod("AddAction");
244247
var action = addAction.Invoke(null, new object[] { map, actionName, default, null, null, null, null, null })
@@ -262,8 +265,16 @@ private void CreateAction(object map, string actionName, string[] bindings, stri
262265

263266
public void ActivateModule()
264267
{
265-
m_newInputModule.ActivateModule();
266-
UI_Enable.Invoke(UI_ActionMap, ArgumentUtility.EmptyArgs);
268+
try
269+
{
270+
m_newInputModule.m_EventSystem = UIManager.EventSys;
271+
m_newInputModule.ActivateModule();
272+
UI_Enable.Invoke(UI_ActionMap, ArgumentUtility.EmptyArgs);
273+
}
274+
catch (Exception ex)
275+
{
276+
ExplorerCore.LogWarning("Exception enabling InputSystem UI Input Module: " + ex);
277+
}
267278
}
268279
}
269280
}

src/Core/Input/LegacyInput.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,25 @@ public LegacyInput()
4242

4343
// UI Input module
4444

45-
public BaseInputModule UIModule => m_inputModule;
45+
public BaseInputModule UIInputModule => m_inputModule;
4646
internal StandaloneInputModule m_inputModule;
4747

4848
public void AddUIInputModule()
4949
{
5050
m_inputModule = UIManager.CanvasRoot.gameObject.AddComponent<StandaloneInputModule>();
51+
m_inputModule.m_EventSystem = UIManager.EventSys;
5152
}
5253

5354
public void ActivateModule()
5455
{
55-
m_inputModule.ActivateModule();
56+
try
57+
{
58+
m_inputModule.ActivateModule();
59+
}
60+
catch (Exception ex)
61+
{
62+
ExplorerCore.LogWarning($"Exception enabling StandaloneInputModule: {ex}");
63+
}
5664
}
5765
}
5866
}

src/Core/Input/NoInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class NoInput : IHandleInput
1616
public bool GetMouseButton(int btn) => false;
1717
public bool GetMouseButtonDown(int btn) => false;
1818

19-
public BaseInputModule UIModule => null;
19+
public BaseInputModule UIInputModule => null;
2020
public void ActivateModule() { }
2121
public void AddUIInputModule() { }
2222
}

0 commit comments

Comments
 (0)