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

Commit 23483a6

Browse files
committed
Add aggressive mouse unlock option using WaitForEndOfFrame
1 parent a6c24f9 commit 23483a6

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/Core/Config/ConfigManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static class ConfigManager
1919

2020
public static ConfigElement<KeyCode> Main_Menu_Toggle;
2121
public static ConfigElement<bool> Force_Unlock_Mouse;
22+
public static ConfigElement<bool> Aggressive_Force_Unlock;
2223
public static ConfigElement<MenuPages> Default_Tab;
2324
public static ConfigElement<int> Default_Page_Limit;
2425
public static ConfigElement<string> Default_Output_Path;
@@ -78,6 +79,10 @@ private static void CreateConfigElements()
7879
"Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.",
7980
true);
8081

82+
Aggressive_Force_Unlock = new ConfigElement<bool>("Aggressive Mouse Unlock",
83+
"Use WaitForEndOfFrame to aggressively force the Mouse to be unlocked (requires game restart).",
84+
false);
85+
8186
Default_Page_Limit = new ConfigElement<int>("Default Page Limit",
8287
"The default maximum number of elements per 'page' in UnityExplorer.",
8388
25);

src/Core/Input/CursorUnlocker.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using UnityExplorer.Core.Config;
88
using UnityExplorer.Core;
99
using UnityExplorer.UI;
10+
using System.Collections;
1011
#if ML
1112
using Harmony;
1213
#else
@@ -48,6 +49,36 @@ public static void Init()
4849

4950
Unlock = ConfigManager.Force_Unlock_Mouse.Value;
5051
ConfigManager.Force_Unlock_Mouse.OnValueChanged += (bool val) => { Unlock = val; };
52+
53+
if (ConfigManager.Aggressive_Force_Unlock.Value)
54+
SetupAggressiveUnlock();
55+
}
56+
57+
public static void SetupAggressiveUnlock()
58+
{
59+
try
60+
{
61+
RuntimeProvider.Instance.StartCoroutine(AggressiveUnlockCoroutine());
62+
}
63+
catch (Exception ex)
64+
{
65+
ExplorerCore.LogWarning($"Exception setting up Camera.onPostRender callback: {ex}");
66+
}
67+
}
68+
69+
private static readonly WaitForEndOfFrame _waitForEndOfFrame = new WaitForEndOfFrame();
70+
71+
private static IEnumerator AggressiveUnlockCoroutine()
72+
{
73+
while (true)
74+
{
75+
ExplorerCore.Log("Yielding end of frame");
76+
yield return _waitForEndOfFrame;
77+
ExplorerCore.Log("Yielded");
78+
79+
if (UIManager.ShowMenu)
80+
UpdateCursorControl();
81+
}
5182
}
5283

5384
public static void UpdateCursorControl()

src/ExplorerCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace UnityExplorer
1414
public class ExplorerCore
1515
{
1616
public const string NAME = "UnityExplorer";
17-
public const string VERSION = "3.3.12";
17+
public const string VERSION = "3.3.13";
1818
public const string AUTHOR = "Sinai";
1919
public const string GUID = "com.sinai.unityexplorer";
2020

0 commit comments

Comments
 (0)