public async UniTask AddingAsync(Scenes scene, Action <DiContainer> extraBindings = null) { var sceneData = list.Get(scene); await UniTask.SwitchToMainThread(); await sceneLoader.LoadSceneAsync(sceneData.mainScene, LoadSceneMode.Additive, extraBindings); if (!sceneData.backgroundScene.IsEmpty()) { await sceneLoader.LoadSceneAsync(sceneData.backgroundScene, LoadSceneMode.Additive, extraBindings); } }
public void Launch( string scene, bool unloadCurrent = true, Action <DiContainer> extraBindings = null) { if (unloadCurrent && !string.IsNullOrEmpty(currentScene)) { SceneManager.UnloadSceneAsync(currentScene); } currentScene = scene; if (IsBuildInScene(scene)) { loadOperation = new AsyncOperationLoadOperation( zenjectSceneLoader.LoadSceneAsync(scene, LoadSceneMode.Additive, extraBindings)); } else { loadOperation = new AssetBundleLoadOperation( zenjectAssetBundleSceneLoader.LoadSceneAsync(scene, LoadSceneMode.Additive, extraBindings)); } preloaderController.Display(); tickableManager.Add(this); }
private async UniTaskVoid LoadSceneAsync(GameType gameType, SceneName sceneName, int level, CancellationToken token) { // シーン遷移中にボタンを押下させない _buttonContainerUseCase.ActivateButton(false); _buttonContainerUseCase.ClearAllButton(); OnBeginTransition(gameType, sceneName); await _transitionMaskView.FadeInAsync(token); await _zenjectSceneLoader.LoadSceneAsync(sceneName.ToString(), LoadSceneMode.Single, container => { container.BindInstance(level); container.BindInstance(gameType); }); // トランジションが完了するまでボタンを押下させない _buttonContainerUseCase.ActivateButton(false); await UniTask.Delay(TimeSpan.FromSeconds(CommonViewConfig.LOAD_INTERVAL), cancellationToken : token); await OnEndTransitionAsync(gameType, sceneName, token); _buttonContainerUseCase.ActivateButton(true); }
private IEnumerator TestCoroutine() { for (var i = 0; i < 10; i++) { yield return(_sceneLoader.LoadSceneAsync(1, LoadSceneMode.Single)); yield return(_sceneLoader.LoadSceneAsync(0, LoadSceneMode.Single)); } yield return(new WaitForSeconds(0.1f)); GC.Collect(); yield return(new WaitForSeconds(0.1f)); Debug.Log("There should be zero instances."); }
IEnumerator LoadSceneRoutine(int sceneIndex, Player player) { crossFadeAnimator.SetTrigger("Start"); yield return(new WaitForSeconds(transitionTime)); sceneLoader.LoadSceneAsync(sceneIndex, LoadSceneMode.Single, (container) => { container.BindInstance(player).WhenInjectedInto <GameInstaller>(); }); }
public override IEnumerator Execute() { _signalBus.Fire(new GamePausedChangedSignal() { DidBecomePaused = false }); if (_restartScene) { yield return(SceneManager.UnloadSceneAsync(_unloadSceneIndex)); } var op = _sceneLoader.LoadSceneAsync(_loadSceneIndex, LoadSceneMode.Additive, null, _loadAdditive ? LoadSceneRelationship.Child : LoadSceneRelationship.Sibling); op.allowSceneActivation = true; yield return(op); SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(_loadSceneIndex)); if (!_restartScene && _unloadSceneIndex > 0) { yield return(SceneManager.UnloadSceneAsync(_unloadSceneIndex)); } _signalBus.Fire(new ActiveSceneChangedSignal { OldSceneIndex = _unloadSceneIndex, NewSceneIndex = _loadSceneIndex }); }
/// <summary> /// Under-the-hood loading /// </summary> /// <param name="target"></param> /// <param name="isAdditive"></param> /// <param name="sceneData"></param> /// <returns>UniTask</returns> private async UniTask LoadSceneAsync <T>(IScene target, bool isAdditive, T sceneData) { if (IsLoaded(target) && isAdditive) { Debug.LogWarning( "UniSwitcher currently does not fully support additively loading the same scene multiple times. Unloading functionality may break." ); } var loadedLevel = _sceneLoader.LoadSceneAsync( target.GetRawValue(), isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single, c => { c.Bind <T>().FromInstance(sceneData).AsSingle(); } ); while (!loadedLevel.isDone) { _progressUpdateDelegates?.Invoke(loadedLevel.progress); await UniTask.Yield(); } SceneManager.SetActiveScene(SceneManager.GetSceneByPath(target.GetRawValue())); SetLoaded(target, true); _currentScene = target.GetRawValue(); #if UNITY_ANALYTICS if (Analytics.enabled && (!(target as IReportable)?.DoNotReport() ?? false)) { AnalyticsEvent.ScreenVisit(target.GetRawValue()); } #endif }
public async Task <IGameType> LoadGame(int buildIndex, CancellationToken cancellationToken) { var tcs = new TaskCompletionSource <IGameType>(); void onSceneLoaded(Scene scene, LoadSceneMode mode) { if (tcs.Task.IsCompleted || tcs.Task.IsCanceled || tcs.Task.IsFaulted) { return; } if (scene.buildIndex == buildIndex) { currentScene = scene; SceneManager.SetActiveScene(scene); var gameType = scene.GetRootGameObjects().FirstOrDefault().GetComponent <IGameType>(); tcs.SetResult(gameType); } } SceneManager.sceneLoaded += onSceneLoaded; _ = sceneLoader.LoadSceneAsync(buildIndex, LoadSceneMode.Additive); await tcs.Task; SceneManager.sceneLoaded -= onSceneLoaded; if (tcs.Task.IsCompleted && !tcs.Task.IsCanceled && !tcs.Task.IsFaulted) { return(tcs.Task.Result); } tcs = null; return(null); }
private async UniTaskVoid Transition( string nextScene, Action <DiContainer> bindAction, CancellationToken token) { // 0 -> 1 var startTime = Time.time; while ((Time.time - startTime) < _transisionSeconds) { var rate = ((Time.time - startTime)) / _transisionSeconds; _coverImage.color = _coverImage.color.SetA(rate); await UniTask.Yield(); } _coverImage.color = _coverImage.color.SetA(1); await _zenjectSceneLoader.LoadSceneAsync( nextScene, LoadSceneMode.Single, bindAction); // 1 -> 0 startTime = Time.time; while ((Time.time - startTime) < _transisionSeconds) { var rate = 1 - ((Time.time - startTime)) / _transisionSeconds; _coverImage.color = _coverImage.color.SetA(rate); await UniTask.Yield(); } _coverImage.color = _coverImage.color.SetA(0); _isTransition.Value = true; }
public void OnBack() { // Нажата кнопка возврата к предыдущей сцене. switch (_backSceneId) { case Const.EditorSceneID: // Игра вызывалась из редактора. Вернуть в редактор модель уровня. _sceneLoader.LoadSceneAsync(Const.EditorSceneID, extraBindings: container => container.BindInterfacesAndSelfTo <EnvironmentModel>().FromInstance(_environment).AsSingle()); break; default: // Игра вызывалась из стартовой сцены. Вернуть результат. _sceneLoader.LoadSceneAsync(_backSceneId, extraBindings: container => container.Bind <IGameResult>().FromInstance(_gameResult).AsCached()); break; } }
void Start() { if (!SceneIsLoaded(sceneName)) { loader.LoadSceneAsync(sceneName, loadMode: LoadSceneMode.Additive); } else { Debug.Log("Scene already loaded"); } }
public IEnumerator LoadScene() { AsyncOperation asyncOperation = zenjectSceneLoader.LoadSceneAsync( SceneToLoad, UnityEngine.SceneManagement.LoadSceneMode.Additive, ProvideExtraBindings); yield return(asyncOperation); SceneManager.UnloadSceneAsync(SceneToUnload); }
private IEnumerator ShowLoadDialogCoroutine() { yield return(FileBrowser.WaitForLoadDialog(FileBrowser.PickMode.FilesAndFolders)); if (FileBrowser.Success) { var path = FileBrowser.Result[0]; if (File.Exists(path)) { // Перегрузить сцену редактора уровней с инъекцией модели загруженного уровня. var raw = File.ReadAllText(path, Encoding.UTF8); var environmentModel = Serializer.Deserialize <EnvironmentModel>(raw); _sceneLoader.LoadSceneAsync("EditorScene", extraBindings: container => container.BindInterfacesAndSelfTo <EnvironmentModel>() .FromInstance(environmentModel).AsSingle()); } } _coroutine = null; }
public void LoadSceneAsync(string sceneName, Action onSceneLoaded = null) { if (_loadedScenes.Contains(sceneName)) { return; } _sceneLoader.LoadSceneAsync(sceneName, LoadSceneMode.Additive); _onSceneLoaded = onSceneLoaded; SceneManager.sceneLoaded += SceneManager_OnSceneLoaded; }
public void LoadSceneAsync(string sceneName, Action onSceneLoaded = null) { if (_loadedScenes.Any(item => item.name == sceneName)) { return; } _sceneLoader.LoadSceneAsync(sceneName, LoadSceneMode.Additive); _onSceneLoaded = onSceneLoaded; UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneManager_OnSceneLoaded; }
public void LoadSceneAdditive(SceneID scene) { int handle; if (handleSearch.TryGetValue(scene, out handle)) { zenLoader.LoadSceneAsync(handle, LoadSceneMode.Additive); } else { Debug.Log($"Scene Loader: Error loading scene: {scene}"); } }
public IObservable <Unit> Run() { _modalViewController.Show("Loading Assets..."); // TODO: Commands to use unitask. this should just be all async / await MapStoreId mapStoreId = new MapStoreId(_data.mapIndex); IObservable <IMutableMapData> mapDataObservable = _mapStore.LoadMap(mapStoreId).ToObservable(); mapDataObservable.Subscribe(mapData => { _sceneLoader.LoadSceneAsync(_data.SceneName, LoadSceneMode.Additive, container => { HandleMapSceneLoaded(container, mapData, mapStoreId); }); }); return(_sceneLoadedSubject); }
IEnumerator AsynchronousLoad(string sceneName, Promise loadPromise, bool unload = false) { yield return(null); AsyncOperation ao; if (!unload) { ao = _sceneLoader.LoadSceneAsync(sceneName, LoadSceneMode.Additive); } else { ao = SceneManager.UnloadSceneAsync(sceneName); } while (!ao.isDone) { // [0, 0.9] > [0, 1] float loadProgress = Mathf.Clamp01(ao.progress); loadPromise.ReportProgress(loadProgress); Debug.Log(string.Format("{0} , Async load progress = {1}", this, loadProgress)); yield return(null); } if (loadPromise != null) { Debug.Log(string.Format("{0} , Async load complete, completing promise", this)); loadPromise.ReportProgress(1f); loadPromise.Resolve(); Scene scene; if (unload) { scene = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); } else { scene = SceneManager.GetSceneByName(sceneName); } SceneManager.SetActiveScene(scene); } }
private async UniTaskVoid FadeLoadAsync(string sceneName, int level, CancellationToken token) { _isTransition = true; var beforeSceneButtons = Object.FindObjectsOfType <ButtonActivator>(); beforeSceneButtons.ActivateButtons(false); SetUpFade(_alphaCutOffMax); await UniTask.WaitUntil(() => { _transitionProgress += Time.deltaTime *_fadeSpeedRate; var alphaCutOffValue = _alphaCutOffMax - _alphaCutOffMax *_transitionProgress / _transitionDuration; _transitionSpriteMask.SetAlphaCutOff(alphaCutOffValue); return(IsFadeComplete()); }, cancellationToken : token); await _zenjectSceneLoader.LoadSceneAsync(sceneName, LoadSceneMode.Single, container => { container.BindInstance(level); }); await UniTask.Delay(TimeSpan.FromSeconds(0.1f), cancellationToken : token); var afterSceneButtons = Object.FindObjectsOfType <ButtonActivator>(); afterSceneButtons.ActivateButtons(false); SetUpFade(_alphaCutOffMin); await UniTask.WaitUntil(() => { _transitionProgress += Time.deltaTime *_fadeSpeedRate; var alphaCutOffValue = _alphaCutOffMax *_transitionProgress / _transitionDuration; _transitionSpriteMask.SetAlphaCutOff(alphaCutOffValue); return(IsFadeComplete()); }, cancellationToken : token); afterSceneButtons.ActivateButtons(true); _isTransition = false; }
private IObservable <Unit> LoadMapSection(uint nextSection) { MapSectionWillLoad?.Invoke(); // While we change scenes, pause any commands from being processed. // This avoids race conditions with commands being instantiated in the wrong context. _pausableCommandQueue.Pause(); _previousSection = _mapSectionContext.CurrentSectionIndex; _mapSectionContext.CurrentSectionIndex = nextSection; if (_loadedScenes.ContainsKey(_previousSection)) { _loadedScenes[_previousSection].Deactivate(); } if (_loadedScenes.ContainsKey(nextSection)) { _pausableCommandQueue.Resume(); _loadedScenes[nextSection].Reactivate(); return(Observable.ReturnUnit()); } IMutableMapSectionData mapSectionData = _mapData.Sections[nextSection]; return(_sceneLoader.LoadSceneAsync(_data.mapCommandData.SectionSceneName, LoadSceneMode.Additive, container => { _loadedScenes[nextSection] = new SceneState(SceneManager.GetSceneAt(SceneManager.sceneCount - 1)); container.Bind <IGridData>().FromInstance(mapSectionData.GridData); container.Bind <IMapSectionData>().FromInstance(mapSectionData); if (_data.mapCommandData.isMapEditor) { container.Bind <IMutableMapSectionData>().FromInstance(mapSectionData); } _pausableCommandQueue.Resume(); }).ToUniTask().ToObservable()); }
public IEnumerator LoadLevelLoadScreen(string sceneName, bool usePlayerInput) { _instancedLoadScreen = RequestLoadingScreen(usePlayerInput); yield return(null); AsyncOperation ao = loader.LoadSceneAsync(sceneName); ao.allowSceneActivation = false; while (!ao.isDone) { _instancedLoadScreen.RefreshLoadingProgress(ao.progress); if (ao.progress >= 0.9f) { ao.allowSceneActivation = true; break; } yield return(null); } _instancedLoadScreen.RefreshLoadingProgress(1); // Temp wait system while waiting for 2017.4 StartCoroutine(_instancedLoadScreen.WaitForCompletion()); while (_instancedLoadScreen.InExecution) { yield return(null); } // yield return _instancedLoadScreen.WaitForCompletion(); ao.allowSceneActivation = true; RemoveLoadingScreen(); }
public void LoadSingle() { _sceneLoader.LoadSceneAsync(_sceneReference, LoadSceneMode.Single); }
public async void TransistionScene(EnumSceneName sceneName, CancellationToken token = default) { await imageFadeIn.rectTransform.DOScale(1, fadeDuration).SetEase(ease).ToAwaiter(token); await zenjctSceneLoader.LoadSceneAsync(sceneName.GetTypeName(), LoadSceneMode.Single); }
private async UniTask LoadAdditive(string sceneName, Action <DiContainer> extraBindings) { await loader.LoadSceneAsync(sceneName, LoadSceneMode.Additive, extraBindings); loadedSceneNames.Add(sceneName); }
/// <summary> /// シーン読み込み処理 /// 非同期で読み込み、完了後切り替える /// </summary> private IObservable <Base> LoadSceneAsync(Base parent, SceneData sceneData, LoadSceneMode mode = LoadSceneMode.Single, System.Action onLoaded = null) { var sceneName = sceneData.SceneID.GetName(); return(Observable.FromCoroutine <Unit>(observer_ => LoadSceneOperationAsync(_zenjectSceneLoader.LoadSceneAsync(sceneName, mode, sceneData.BindAction), observer_)) .Select(scene_ => { // LoadSceneOperationAsync内のOnNextが呼び出されたときに来る var activeSceneInstance = loadedScene; var scene = default(Base); // 読み込んだシーンからシーンクラスのインスタンスを取得する foreach (var rootObject in activeSceneInstance.GetRootGameObjects()) { scene = rootObject.GetComponent <Base>(); if (scene != null) { break; } } if (scene == null) { Utility.Log.Error($"Scene.Base クラスが見つかりません {typeof(Base).ToString()}"); return null; } // シーンにUnityシーン情報をもたせる scene.Scene = activeSceneInstance; ///// scene.transform.SetParent(_sceneRoot); scene.SceneData = sceneData; scene.Argument = sceneData.Argument; // 準備が整うまで非アクティブ scene.gameObject.SetActive(false); // 必要なデータが読み込まれていない場合、読み込みを行う //Observable.FromCoroutine<Base>(observer_ => LoadScenePrepareAsync(observer_)); // Sceneに変換 return scene; }) .ContinueWith(scene_ => InitLoadPrepareAsync(scene_)) .SelectMany(scene_ => { // 別の処理に合成 return scene_.ScenePrepareAsync().Select(scene_ => { switch (mode) { case LoadSceneMode.Additive: // 親に関連付ける parent.AddChild(scene_); break; // AddSceneの場合は現在のシーンインスタンスとはしない default: _currentScene = scene_; break; } return scene_; }); })); }
public async void Initialize() { await _zenjectSceneLoader.LoadSceneAsync(nameof(SceneName.NearAnchorDemo), LoadSceneMode.Additive); }
private void OnScreenIsBlack() { _loader.LoadSceneAsync(sceneName, loadMode: UnityEngine.SceneManagement.LoadSceneMode.Single).completed += OnSceneLoaded; }
public void Initialize() { asyncOperation = zenjectSceneLoader.LoadSceneAsync( menuSceneName, UnityEngine.SceneManagement.LoadSceneMode.Additive); }