protected IObservable <Unit> LoadAsObservable(ISceneStrategy sceneStrategy) { // Do nothing if duplicate loading if (!CanLoadScene(sceneStrategy)) { return(Observable.ReturnUnit()); } var sceneEntity = SceneEntityFactory.Create(sceneStrategy); // For blocking when a Load instruction flew in the same frame LoadDisposableMap[sceneStrategy.SceneName] = sceneEntity.DidLoadAsObservable().Take(1).Subscribe(); SceneEntityList.AddLast(sceneEntity); SceneStateEntity.WillLoadSubject.OnNext(sceneEntity.SceneStrategy.SceneName); return(SceneRepository .GetAsync(sceneStrategy) .ToObservable() .SelectMany( _ => sceneEntity .Load() .ToObservable() ) .ForEachAsync(_ => LoadDisposableMap.Remove(sceneStrategy.SceneName))); }
void IInitializable.Initialize() { PreInitialize(); RequestEntity.OnLoadRequestAsObservable().Select(GetOrCreateSceneStrategy).Subscribe(((ILoaderUseCase)this).Load); RequestEntity.OnUnloadRequestAsObservable().Select(GetOrCreateSceneStrategy).Subscribe(((ILoaderUseCase)this).Unload); RequestHandlerPresenter.RequestLoadSceneAsObservable().Subscribe(RequestEntity.RequestLoad); RequestHandlerPresenter.RequestUnloadSceneAsObservable().Subscribe(RequestEntity.RequestUnload); SceneManager.sceneLoaded += (scene, loadSceneMode) => SceneStateEntity.DidLoadSubject.OnNext(scene.name); SceneManager.sceneUnloaded += (scene) => SceneStateEntity.DidUnloadSubject.OnNext(scene.name); GenerateInitialSceneStrategyList().Select(SceneEntityFactory.Create).ToList().ForEach(x => SceneEntityList.AddLast(x)); PostInitialize(); }