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

Commit 1a26623

Browse files
committed
Add option to disable EventSystem override
1 parent 041f293 commit 1a26623

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

src/Core/Config/ConfigManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static class ConfigManager
2121
public static ConfigElement<bool> Force_Unlock_Mouse;
2222
public static ConfigElement<KeyCode> Force_Unlock_Toggle;
2323
public static ConfigElement<bool> Aggressive_Mouse_Unlock;
24+
public static ConfigElement<bool> Disable_EventSystem_Override;
2425
public static ConfigElement<string> Default_Output_Path;
2526
public static ConfigElement<bool> Log_Unity_Debug;
2627
public static ConfigElement<bool> Hide_On_Startup;
@@ -93,7 +94,11 @@ private static void CreateConfigElements()
9394
KeyCode.None);
9495

9596
Aggressive_Mouse_Unlock = new ConfigElement<bool>("Aggressive Mouse Unlock",
96-
"Use WaitForEndOfFrame to aggressively force the Mouse to be unlocked (requires game restart).",
97+
"Use WaitForEndOfFrame to aggressively force the Mouse to be unlocked.\n<b>Requires restart to take effect.</b>",
98+
false);
99+
100+
Disable_EventSystem_Override = new ConfigElement<bool>("Disable EventSystem override",
101+
"If enabled, UnityExplorer will not override the EventSystem from the game.\n<b>May require restart to take effect.</b>",
97102
false);
98103

99104
Log_Unity_Debug = new ConfigElement<bool>("Log Unity Debug",

src/Core/Input/CursorUnlocker.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ public static void Init()
3737
lastVisibleState = Cursor.visible;
3838

3939
SetupPatches();
40-
4140
UpdateCursorControl();
4241

42+
// Hook up config values
43+
44+
// Force Unlock Mouse
4345
Unlock = ConfigManager.Force_Unlock_Mouse.Value;
4446
ConfigManager.Force_Unlock_Mouse.OnValueChanged += (bool val) => { Unlock = val; };
4547

48+
// Aggressive Mouse Unlock
4649
if (ConfigManager.Aggressive_Mouse_Unlock.Value)
4750
SetupAggressiveUnlock();
4851
}
@@ -83,15 +86,15 @@ public static void UpdateCursorControl()
8386
Cursor.lockState = CursorLockMode.None;
8487
Cursor.visible = true;
8588

86-
if (UIManager.EventSys)
89+
if (!ConfigManager.Disable_EventSystem_Override.Value && UIManager.EventSys)
8790
SetEventSystem();
8891
}
8992
else
9093
{
9194
Cursor.lockState = lastLockMode;
9295
Cursor.visible = lastVisibleState;
9396

94-
if (UIManager.EventSys)
97+
if (!ConfigManager.Disable_EventSystem_Override.Value && UIManager.EventSys)
9598
ReleaseEventSystem();
9699
}
97100

@@ -160,26 +163,19 @@ private static void SetupPatches()
160163

161164
public static void Prefix_EventSystem_set_current(ref EventSystem value)
162165
{
163-
if (!UIManager.EventSys)
166+
if (!settingEventSystem && value)
164167
{
165-
if (value)
166-
{
167-
lastEventSystem = value;
168-
lastInputModule = value.currentInputModule;
169-
}
170-
return;
168+
lastEventSystem = value;
169+
lastInputModule = value.currentInputModule;
171170
}
172171

173-
if (!settingEventSystem && value != UIManager.EventSys)
174-
{
175-
lastEventSystem = value;
176-
lastInputModule = value?.currentInputModule;
172+
if (!UIManager.EventSys)
173+
return;
177174

178-
if (ShouldActuallyUnlock)
179-
{
180-
value = UIManager.EventSys;
181-
value.enabled = true;
182-
}
175+
if (!settingEventSystem && ShouldActuallyUnlock && !ConfigManager.Disable_EventSystem_Override.Value)
176+
{
177+
value = UIManager.EventSys;
178+
value.enabled = true;
183179
}
184180
}
185181

src/UI/UIManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public static void Update()
145145
if (InputManager.GetKeyDown(ConfigManager.Force_Unlock_Toggle.Value))
146146
CursorUnlocker.Unlock = !CursorUnlocker.Unlock;
147147

148-
if (EventSystem.current != EventSys)
148+
if (!ConfigManager.Disable_EventSystem_Override.Value && EventSystem.current != EventSys)
149149
CursorUnlocker.SetEventSystem();
150150

151151
UIPanel.UpdateFocus();

0 commit comments

Comments
 (0)