From 048c12e8baee43e2c77e17e470ed68518030169f Mon Sep 17 00:00:00 2001 From: kyubuns Date: Mon, 10 May 2021 18:35:49 +0900 Subject: [PATCH] fix ScenePlaybackDetector.IsPlaying is still false when disable Domain Reloading --- .../UnityEngineBridge/MainThreadDispatcher.cs | 6 +++++ .../ScenePlaybackDetector.cs | 26 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs b/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs index 91cc8c459..180101110 100644 --- a/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs +++ b/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs @@ -669,6 +669,12 @@ public static IObservable OnApplicationPauseAsObservable() Subject onApplicationQuit; + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] + public static void OnRuntimeInitializeOnLoadMethod() + { + isQuitting = false; + } + void OnApplicationQuit() { isQuitting = true; diff --git a/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ScenePlaybackDetector.cs b/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ScenePlaybackDetector.cs index ba1b4ab57..047476bd8 100644 --- a/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ScenePlaybackDetector.cs +++ b/Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ScenePlaybackDetector.cs @@ -38,6 +38,15 @@ public static bool IsPlaying } } + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] + public static void OnRuntimeInitializeOnLoadMethod() + { + if (AboutToStartScene) + { + IsPlaying = true; + } + } + // This callback is notified after scripts have been reloaded. [DidReloadScripts] public static void OnDidReloadScripts() @@ -54,9 +63,23 @@ static ScenePlaybackDetector() { #if UNITY_2017_2_OR_NEWER EditorApplication.playModeStateChanged += e => + { + if (e == PlayModeStateChange.ExitingEditMode) + { + AboutToStartScene = true; + } + else + { + AboutToStartScene = false; + } + + if (e == PlayModeStateChange.ExitingPlayMode) + { + IsPlaying = false; + } + }; #else EditorApplication.playmodeStateChanged += () => -#endif { // Before scene start: isPlayingOrWillChangePlaymode = false; isPlaying = false // Pressed Playback button: isPlayingOrWillChangePlaymode = true; isPlaying = false @@ -77,6 +100,7 @@ static ScenePlaybackDetector() IsPlaying = false; } }; +#endif } } }