Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

fix ScenePlaybackDetector.IsPlaying is still false when disable Domain Reloading #491

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,12 @@ public static IObservable<bool> OnApplicationPauseAsObservable()

Subject<Unit> onApplicationQuit;

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
public static void OnRuntimeInitializeOnLoadMethod()
{
isQuitting = false;
}

void OnApplicationQuit()
{
isQuitting = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -77,6 +100,7 @@ static ScenePlaybackDetector()
IsPlaying = false;
}
};
#endif
}
}
}
Expand Down