From a3cddc02095dd5f9422c7fa9c74e7df8b7c06dcb Mon Sep 17 00:00:00 2001 From: in0finite Date: Sun, 23 Jan 2022 07:04:08 +0100 Subject: [PATCH] start thread also in edit mode --- Assets/Scripts/Utilities/LoadingThread.cs | 26 +++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Utilities/LoadingThread.cs b/Assets/Scripts/Utilities/LoadingThread.cs index 00a9245c..cd44cce8 100644 --- a/Assets/Scripts/Utilities/LoadingThread.cs +++ b/Assets/Scripts/Utilities/LoadingThread.cs @@ -75,12 +75,21 @@ namespace SanAndreasUnity.Behaviours public ushort maxTimePerFrameMs = 0; + +#if UNITY_EDITOR + [UnityEditor.InitializeOnLoadMethod] + static void InitOnLoadInEditor() + { + if (null == Singleton) + return; + + Singleton.StartThread(); + } +#endif + protected override void OnSingletonStart() { - - _thread = new Thread (ThreadFunction); - _thread.Start(_threadParameters); - + this.StartThread(); } protected override void OnSingletonDisable() @@ -97,6 +106,15 @@ namespace SanAndreasUnity.Behaviours } } + void StartThread() + { + if (_thread != null) + return; + + _thread = new Thread(ThreadFunction); + _thread.Start(_threadParameters); + } + void Update() { this.UpdateJobsInternal();