public static void Initialize() { if (initialized) { return; } MainThreadDispatcher mainThreadDispatcher = null; try { mainThreadDispatcher = UnityEngine.Object.FindObjectOfType <MainThreadDispatcher>(); } catch { Exception ex = new Exception("UniRx requires a MainThreadDispatcher component created on the main thread. Make sure it is added to the scene before calling UniRx from a worker thread."); UnityEngine.Debug.LogException(ex); throw ex; } if (!isQuitting) { if (mainThreadDispatcher == null) { new GameObject("MainThreadDispatcher").AddComponent <MainThreadDispatcher>(); } else { mainThreadDispatcher.Awake(); } } }
public static void Initialize() { if (!initialized) { if (RichUnity.IsAnyEditor()) { // Don't try to add a GameObject when the scene is not playing. Only valid in the Editor, EditorView. if (!ScenePlaybackDetector.IsPlaying) { return; } } MainThreadDispatcher dispatcher = null; try { dispatcher = GameObject.FindObjectOfType <MainThreadDispatcher>(); } catch { // Throw exception when calling from a worker thread. var ex = new Exception("UniRx requires a MainThreadDispatcher component created on the main thread. Make sure it is added to the scene before calling UniRx from a worker thread."); UnityEngine.Debug.LogException(ex); throw ex; } if (isQuitting) { // don't create new instance after quitting // avoid "Some objects were not cleaned up when closing the scene find target" error. return; } if (dispatcher == null) { // awake call immediately from UnityEngine new GameObject("MainThreadDispatcher").AddComponent <MainThreadDispatcher>(); } else { dispatcher.Awake(); // force awake } } }