From a6c24f91e4ac738f4054a704c1526005594664b8 Mon Sep 17 00:00:00 2001 From: Sinai Date: Sun, 11 Apr 2021 20:45:02 +1000 Subject: [PATCH] Add startup delay --- src/Core/Config/ConfigManager.cs | 5 +++++ src/ExplorerCore.cs | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Core/Config/ConfigManager.cs b/src/Core/Config/ConfigManager.cs index 8413fdc..44d1ee0 100644 --- a/src/Core/Config/ConfigManager.cs +++ b/src/Core/Config/ConfigManager.cs @@ -24,6 +24,7 @@ namespace UnityExplorer.Core.Config public static ConfigElement Default_Output_Path; public static ConfigElement Log_Unity_Debug; public static ConfigElement Hide_On_Startup; + public static ConfigElement Startup_Delay_Time; public static ConfigElement Last_Window_Anchors; public static ConfigElement Last_Window_Position; @@ -85,6 +86,10 @@ namespace UnityExplorer.Core.Config "The default output path when exporting things from UnityExplorer.", Path.Combine(ExplorerCore.Loader.ExplorerFolder, "Output")); + Startup_Delay_Time = new ConfigElement("Startup Delay Time", + "The delay on startup before the UI is created.", + 1f); + // Internal configs Last_Window_Anchors = new ConfigElement("Last_Window_Anchors", diff --git a/src/ExplorerCore.cs b/src/ExplorerCore.cs index a96a6bc..47b7cff 100644 --- a/src/ExplorerCore.cs +++ b/src/ExplorerCore.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.IO; using UnityEngine; using UnityExplorer.Core.Config; @@ -13,7 +14,7 @@ namespace UnityExplorer public class ExplorerCore { public const string NAME = "UnityExplorer"; - public const string VERSION = "3.3.11"; + public const string VERSION = "3.3.12"; public const string AUTHOR = "Sinai"; public const string GUID = "com.sinai.unityexplorer"; @@ -44,10 +45,24 @@ namespace UnityExplorer InputManager.Init(); - UIManager.Init(); - Log($"{NAME} {VERSION} initialized."); + RuntimeProvider.Instance.StartCoroutine(SetupCoroutine()); + } + + // Do a delayed setup so that objects aren't destroyed instantly. + // This can happen for a multitude of reasons. + // Default delay is 1 second which is usually enough. + private static IEnumerator SetupCoroutine() + { + float f = Time.realtimeSinceStartup; + float delay = ConfigManager.Startup_Delay_Time.Value; + while (Time.realtimeSinceStartup - f < delay) + yield return null; + + Log($"Creating UI, after delay of {delay} second(s)."); + UIManager.Init(); + //InspectorManager.Instance.Inspect(typeof(TestClass)); }