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

Fix: When domain reload disabled dispatchers doesnt work as expected.… #529

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 @@ -8,6 +8,7 @@
using System.Reflection;
using System.Threading;
using UniRx.InternalUtil;
using UnityEditor;
using UnityEngine;

namespace UniRx
Expand Down Expand Up @@ -408,6 +409,14 @@ public static void RegisterUnhandledExceptionCallback(Action<Exception> exceptio
static bool initialized;
static bool isQuitting = false;

#if UNITY_EDITOR
[InitializeOnEnterPlayMode]
private static void OnEnterPlayMode()
{
isQuitting = false;
}
#endif

public static string InstanceName
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Text;
using System.Threading;
using UnityEditor;
using UnityEngine;

namespace UniRx
Expand All @@ -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;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#if UNITY_EDITOR

using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

namespace UniRx
{
Expand All @@ -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)
{
Expand All @@ -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.
Expand All @@ -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;
Expand Down