From 0dd19345eda1396871dd9813a912f8c48a5d5805 Mon Sep 17 00:00:00 2001 From: Sinai <49360850+sinai-dev@users.noreply.github.com> Date: Tue, 28 Dec 2021 23:24:44 +1100 Subject: [PATCH] Fix FPS drop with MelonLoader --- src/ExplorerCore.cs | 2 +- src/ObjectExplorer/SceneExplorer.cs | 16 ++++++++++++++++ src/ObjectExplorer/SceneHandler.cs | 5 +++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index c63170d5..74597968 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -16,7 +16,7 @@ namespace UnityExplorer public static class ExplorerCore { public const string NAME = "UnityExplorer"; - public const string VERSION = "4.4.1"; + public const string VERSION = "4.4.2"; public const string AUTHOR = "Sinai"; public const string GUID = "com.sinai.unityexplorer"; diff --git a/src/ObjectExplorer/SceneExplorer.cs b/src/ObjectExplorer/SceneExplorer.cs index 17b141ac..c1c8041c 100644 --- a/src/ObjectExplorer/SceneExplorer.cs +++ b/src/ObjectExplorer/SceneExplorer.cs @@ -14,6 +14,7 @@ using UnityExplorer.UI.Widgets; using UniverseLib.UI; using UniverseLib; +using System.Collections; namespace UnityExplorer.ObjectExplorer { @@ -254,6 +255,21 @@ public override void ConstructUI(GameObject content) // Scene Loader ConstructSceneLoader(); + + RuntimeProvider.Instance.StartCoroutine(TempFixCoro()); + } + + // To "fix" a strange FPS drop issue with MelonLoader. + private IEnumerator TempFixCoro() + { + float start = Time.realtimeSinceStartup; + + while (Time.realtimeSinceStartup - start < 2.5f) + yield return null; + + // Select "HideAndDontSave" and then go back to first scene. + this.sceneDropdown.value = sceneDropdown.options.Count - 1; + this.sceneDropdown.value = 0; } private const string DEFAULT_LOAD_TEXT = "[Select a scene]"; diff --git a/src/ObjectExplorer/SceneHandler.cs b/src/ObjectExplorer/SceneHandler.cs index 9261145b..a566a6d3 100644 --- a/src/ObjectExplorer/SceneHandler.cs +++ b/src/ObjectExplorer/SceneHandler.cs @@ -133,10 +133,11 @@ internal static void Update() LoadedScenes.Add(scene); } - bool anyChange = confirmedCount != LoadedScenes.Count; - LoadedScenes.Add(DontDestroyScene); LoadedScenes.Add(default); + + bool anyChange = confirmedCount != LoadedScenes.Count; + previousLoadedScenes = new HashSet(LoadedScenes); // Default to first scene if none selected or previous selection no longer exists.