Add aggressive mouse unlock option using WaitForEndOfFrame

This commit is contained in:
Sinai 2021-04-29 21:45:45 +10:00
parent a6c24f91e4
commit 23483a6108
3 changed files with 37 additions and 1 deletions

View File

@ -19,6 +19,7 @@ namespace UnityExplorer.Core.Config
public static ConfigElement<KeyCode> Main_Menu_Toggle;
public static ConfigElement<bool> Force_Unlock_Mouse;
public static ConfigElement<bool> Aggressive_Force_Unlock;
public static ConfigElement<MenuPages> Default_Tab;
public static ConfigElement<int> Default_Page_Limit;
public static ConfigElement<string> Default_Output_Path;
@ -78,6 +79,10 @@ namespace UnityExplorer.Core.Config
"Force the Cursor to be unlocked (visible) when the UnityExplorer menu is open.",
true);
Aggressive_Force_Unlock = new ConfigElement<bool>("Aggressive Mouse Unlock",
"Use WaitForEndOfFrame to aggressively force the Mouse to be unlocked (requires game restart).",
false);
Default_Page_Limit = new ConfigElement<int>("Default Page Limit",
"The default maximum number of elements per 'page' in UnityExplorer.",
25);

View File

@ -7,6 +7,7 @@ using BF = System.Reflection.BindingFlags;
using UnityExplorer.Core.Config;
using UnityExplorer.Core;
using UnityExplorer.UI;
using System.Collections;
#if ML
using Harmony;
#else
@ -48,6 +49,36 @@ namespace UnityExplorer.Core.Input
Unlock = ConfigManager.Force_Unlock_Mouse.Value;
ConfigManager.Force_Unlock_Mouse.OnValueChanged += (bool val) => { Unlock = val; };
if (ConfigManager.Aggressive_Force_Unlock.Value)
SetupAggressiveUnlock();
}
public static void SetupAggressiveUnlock()
{
try
{
RuntimeProvider.Instance.StartCoroutine(AggressiveUnlockCoroutine());
}
catch (Exception ex)
{
ExplorerCore.LogWarning($"Exception setting up Camera.onPostRender callback: {ex}");
}
}
private static readonly WaitForEndOfFrame _waitForEndOfFrame = new WaitForEndOfFrame();
private static IEnumerator AggressiveUnlockCoroutine()
{
while (true)
{
ExplorerCore.Log("Yielding end of frame");
yield return _waitForEndOfFrame;
ExplorerCore.Log("Yielded");
if (UIManager.ShowMenu)
UpdateCursorControl();
}
}
public static void UpdateCursorControl()

View File

@ -14,7 +14,7 @@ namespace UnityExplorer
public class ExplorerCore
{
public const string NAME = "UnityExplorer";
public const string VERSION = "3.3.12";
public const string VERSION = "3.3.13";
public const string AUTHOR = "Sinai";
public const string GUID = "com.sinai.unityexplorer";