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

Commit f1b83e7

Browse files
committed
Cleanup
1 parent 44c6503 commit f1b83e7

File tree

1 file changed

+31
-43
lines changed

1 file changed

+31
-43
lines changed

src/Core/Input/CursorUnlocker.cs

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,16 @@ public static bool Unlock
2626

2727
public static bool ShouldActuallyUnlock => UIManager.ShowMenu && Unlock;
2828

29-
private static CursorLockMode m_lastLockMode;
30-
private static bool m_lastVisibleState;
29+
private static CursorLockMode lastLockMode;
30+
private static bool lastVisibleState;
3131

32-
private static bool m_currentlySettingCursor = false;
33-
34-
private static Type CursorType
35-
=> m_cursorType
36-
?? (m_cursorType = ReflectionUtility.GetTypeByName("UnityEngine.Cursor"));
37-
private static Type m_cursorType;
32+
private static bool currentlySettingCursor = false;
3833

3934
public static void Init()
4035
{
36+
lastLockMode = Cursor.lockState;
37+
lastVisibleState = Cursor.visible;
38+
4139
SetupPatches();
4240

4341
UpdateCursorControl();
@@ -78,7 +76,7 @@ public static void UpdateCursorControl()
7876
{
7977
try
8078
{
81-
m_currentlySettingCursor = true;
79+
currentlySettingCursor = true;
8280

8381
if (ShouldActuallyUnlock)
8482
{
@@ -90,14 +88,14 @@ public static void UpdateCursorControl()
9088
}
9189
else
9290
{
93-
Cursor.lockState = m_lastLockMode;
94-
Cursor.visible = m_lastVisibleState;
91+
Cursor.lockState = lastLockMode;
92+
Cursor.visible = lastVisibleState;
9593

9694
if (UIManager.EventSys)
9795
ReleaseEventSystem();
9896
}
9997

100-
m_currentlySettingCursor = false;
98+
currentlySettingCursor = false;
10199
}
102100
catch (Exception e)
103101
{
@@ -107,9 +105,9 @@ public static void UpdateCursorControl()
107105

108106
// Event system overrides
109107

110-
private static bool m_settingEventSystem;
111-
private static EventSystem m_lastEventSystem;
112-
private static BaseInputModule m_lastInputModule;
108+
private static bool settingEventSystem;
109+
private static EventSystem lastEventSystem;
110+
private static BaseInputModule lastInputModule;
113111

114112
public static void SetEventSystem()
115113
{
@@ -118,31 +116,31 @@ public static void SetEventSystem()
118116

119117
if (EventSystem.current && EventSystem.current != UIManager.EventSys)
120118
{
121-
m_lastEventSystem = EventSystem.current;
122-
m_lastEventSystem.enabled = false;
119+
lastEventSystem = EventSystem.current;
120+
lastEventSystem.enabled = false;
123121
}
124122

125123
// Set to our current system
126-
m_settingEventSystem = true;
124+
settingEventSystem = true;
127125
UIManager.EventSys.enabled = true;
128126
EventSystem.current = UIManager.EventSys;
129127
InputManager.ActivateUIModule();
130-
m_settingEventSystem = false;
128+
settingEventSystem = false;
131129
}
132130

133131
public static void ReleaseEventSystem()
134132
{
135133
if (InputManager.CurrentType == InputType.InputSystem)
136134
return;
137135

138-
if (m_lastEventSystem && m_lastEventSystem.gameObject.activeSelf)
136+
if (lastEventSystem && lastEventSystem.gameObject.activeSelf)
139137
{
140-
m_lastEventSystem.enabled = true;
138+
lastEventSystem.enabled = true;
141139

142-
m_settingEventSystem = true;
143-
EventSystem.current = m_lastEventSystem;
144-
m_lastInputModule?.ActivateModule();
145-
m_settingEventSystem = false;
140+
settingEventSystem = true;
141+
EventSystem.current = lastEventSystem;
142+
lastInputModule?.ActivateModule();
143+
settingEventSystem = false;
146144
}
147145
}
148146

@@ -152,30 +150,20 @@ private static void SetupPatches()
152150
{
153151
try
154152
{
155-
if (CursorType == null)
156-
throw new Exception("Could not load Type 'UnityEngine.Cursor'!");
157-
158-
// Get current cursor state and enable cursor
159-
m_lastLockMode = (CursorLockMode?)CursorType.GetProperty("lockState", BF.Public | BF.Static)?.GetValue(null, null)
160-
?? CursorLockMode.None;
161-
162-
m_lastVisibleState = (bool?)CursorType.GetProperty("visible", BF.Public | BF.Static)?.GetValue(null, null)
163-
?? false;
164-
165153
ExplorerCore.Loader.SetupCursorPatches();
166154
}
167155
catch (Exception e)
168156
{
169-
ExplorerCore.Log($"Error on CursorUnlocker.Init! {e.GetType()}, {e.Message}");
157+
ExplorerCore.Log($"Exception setting up Cursor patches: {e.GetType()}, {e.Message}");
170158
}
171159
}
172160

173161
public static void Prefix_EventSystem_set_current(ref EventSystem value)
174162
{
175-
if (!m_settingEventSystem && value != UIManager.EventSys)
163+
if (!settingEventSystem && value != UIManager.EventSys)
176164
{
177-
m_lastEventSystem = value;
178-
m_lastInputModule = value?.currentInputModule;
165+
lastEventSystem = value;
166+
lastInputModule = value?.currentInputModule;
179167

180168
if (ShouldActuallyUnlock)
181169
{
@@ -191,9 +179,9 @@ public static void Prefix_EventSystem_set_current(ref EventSystem value)
191179

192180
public static void Prefix_set_lockState(ref CursorLockMode value)
193181
{
194-
if (!m_currentlySettingCursor)
182+
if (!currentlySettingCursor)
195183
{
196-
m_lastLockMode = value;
184+
lastLockMode = value;
197185

198186
if (ShouldActuallyUnlock)
199187
value = CursorLockMode.None;
@@ -202,9 +190,9 @@ public static void Prefix_set_lockState(ref CursorLockMode value)
202190

203191
public static void Prefix_set_visible(ref bool value)
204192
{
205-
if (!m_currentlySettingCursor)
193+
if (!currentlySettingCursor)
206194
{
207-
m_lastVisibleState = value;
195+
lastVisibleState = value;
208196

209197
if (ShouldActuallyUnlock)
210198
value = true;

0 commit comments

Comments
 (0)