From 77f792bd9c33294fbb7884b199b6333fe310227a Mon Sep 17 00:00:00 2001 From: "REVISION-PC\\Loord" Date: Thu, 2 Feb 2023 13:10:22 +0300 Subject: [PATCH] Fix: When domain reload disabled dispatchers doesnt work as expected. This fixes the situation. --- .../UnityEngineBridge/MainThreadDispatcher.cs | 9 ++++ .../UnityEngineBridge/MainThreadScheduler.cs | 12 ++++++ .../ScenePlaybackDetector.cs | 41 +++---------------- 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs b/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs index 91cc8c459..7ba73a32c 100644 --- a/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs +++ b/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Threading; using UniRx.InternalUtil; +using UnityEditor; using UnityEngine; namespace UniRx @@ -408,6 +409,14 @@ public static void RegisterUnhandledExceptionCallback(Action exceptio static bool initialized; static bool isQuitting = false; +#if UNITY_EDITOR + [InitializeOnEnterPlayMode] + private static void OnEnterPlayMode() + { + isQuitting = false; + } +#endif + public static string InstanceName { get diff --git a/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadScheduler.cs b/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadScheduler.cs index 03de6f352..5beb40a58 100644 --- a/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadScheduler.cs +++ b/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadScheduler.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text; using System.Threading; +using UnityEditor; using UnityEngine; namespace UniRx @@ -22,6 +23,17 @@ public static void SetDefaultForUnity() Scheduler.DefaultSchedulers.AsyncConversions = Scheduler.ThreadPool; } #endif + +#if UNITY_EDITOR + [InitializeOnEnterPlayMode] + private static void OnEnterPlayMode() + { + mainThread = null; + mainThreadIgnoreTimeScale = null; + mainThreadEndOfFrame = null; + mainThreadFixedUpdate = null; + } +#endif static IScheduler mainThread; /// diff --git a/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ScenePlaybackDetector.cs b/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ScenePlaybackDetector.cs index ba1b4ab57..7afa9d8fd 100644 --- a/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ScenePlaybackDetector.cs +++ b/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ScenePlaybackDetector.cs @@ -1,8 +1,6 @@ #if UNITY_EDITOR using UnityEditor; -using UnityEditor.Callbacks; -using UnityEngine; namespace UniRx { @@ -11,25 +9,11 @@ public class ScenePlaybackDetector { private static bool _isPlaying = false; - private static bool AboutToStartScene - { - get - { - return EditorPrefs.GetBool("AboutToStartScene"); - } - set - { - EditorPrefs.SetBool("AboutToStartScene", value); - } - } public static bool IsPlaying { - get - { - return _isPlaying; - } - set + get => _isPlaying; + private set { if (_isPlaying != value) { @@ -38,15 +22,11 @@ public static bool IsPlaying } } - // This callback is notified after scripts have been reloaded. - [DidReloadScripts] - public static void OnDidReloadScripts() + + [InitializeOnEnterPlayMode] + public static void OnDidReloadScriptsA() { - // Filter DidReloadScripts callbacks to the moment where playmodeState transitions into isPlaying. - if (AboutToStartScene) - { - IsPlaying = true; - } + IsPlaying = true; } // InitializeOnLoad ensures that this constructor is called when the Unity Editor is started. @@ -62,16 +42,7 @@ static ScenePlaybackDetector() // Pressed Playback button: isPlayingOrWillChangePlaymode = true; isPlaying = false // Playing: isPlayingOrWillChangePlaymode = false; isPlaying = true // Pressed stop button: isPlayingOrWillChangePlaymode = true; isPlaying = true - if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying) - { - AboutToStartScene = true; - } - else - { - AboutToStartScene = false; - } - // Detect when playback is stopped. if (!EditorApplication.isPlaying) { IsPlaying = false;