public static UnloadSceneAsync ( |
||
scene | Scene to unload. | |
return |
IEnumerator LoadSceneGame(int weight) { Scene scene = SceneManager.GetSceneByName("Game"); if (scene.isLoaded) { _asyncOperation = SceneManager.UnloadSceneAsync(scene); while (!_asyncOperation.isDone) { yield return(0); } } _asyncOperation = SceneManager.LoadSceneAsync("Game", LoadSceneMode.Additive); _asyncOperation.allowSceneActivation = false; yield return(0); float progress = 0; while (!_asyncOperation.isDone) { progress = _asyncOperation.progress < 0.9f ? _asyncOperation.progress : 1; yield return(progress * weight); if (progress >= 0.9f) { _asyncOperation.allowSceneActivation = true; } } }
public async UniTask RemoveAsync(Scenes scene) { var sceneData = list.Get(scene); await UniSceneManager.UnloadSceneAsync(sceneData.mainScene); if (sceneData.backgroundScene != null) { await UniSceneManager.UnloadSceneAsync(sceneData.backgroundScene); } }
public void UnloadScene() { if (this.isRunning) { return; } this.isRunning = true; SceneMng.UnloadSceneAsync(this.gameObject.scene); }
public static async Task UnloadSceneAsycn(Scene scene) { TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>(); AsyncOperation asyncOperation = USceneManager.UnloadSceneAsync(scene); asyncOperation.completed += (AsyncOperation ao) => taskCompletionSource.SetResult(ao.isDone); await taskCompletionSource.Task; FLog.Info(CLASS_TYPE.Name, $"Scene `{scene.name}` has been unloaded."); }
private async UniTask Load(string sceneName, Action <DiContainer> extraBindings) { var currentScene = UnitySceneManager.GetActiveScene(); await LoadAdditive(sceneName, extraBindings); var nextScene = UnitySceneManager.GetSceneByName(sceneName); UnitySceneManager.SetActiveScene(nextScene); await UnitySceneManager.UnloadSceneAsync(currentScene); }
private System.Collections.IEnumerator load() { /* Retrieve all components from the loading scene */ do { AsyncOp op; SceneMng.sceneLoaded += getUiComponents; this.pb = null; op = SceneMng.LoadSceneAsync(Loader.uiScene, SceneMode.Additive); yield return(op); SceneMng.sceneLoaded -= getUiComponents; } while (false); do { AsyncOp op; op = SceneMng.LoadSceneAsync(currentLevel, SceneMode.Additive); while (op.progress < 1.0f) { /* Update a progress bar */ if (this.pb != null) { this.pb.progress = op.progress * 0.95f; } yield return(new UnityEngine.WaitForFixedUpdate()); } } while (false); /* Wait another frame, so this may get the position of every * checkpoint */ yield return(null); SceneMng.UnloadSceneAsync(this.loadingUi); do { AsyncOp op; SceneMng.sceneLoaded += setupGameUI; op = SceneMng.LoadSceneAsync(Loader.gameUiScene, SceneMode.Additive); yield return(op); SceneMng.sceneLoaded -= setupGameUI; } while (false); this.done = true; }
/// <summary> /// シーンを破棄する /// </summary> public static void UnloadScene(SceneDefine.SCENE_ID id) { List <SceneBase> sceneList = Instance.sceneList; for (int i = 0; i < sceneList.Count; i++) { if (sceneList[i].SceneID == id) { sceneList[i].StartUnload(); UnitySceneManager.UnloadSceneAsync(sceneList[i].UnityScene.name); break; } } }
private CoroutineRet waitAction() { string str = "Quiting in "; UiText text = this.quiting.GetComponentInChildren <UiText>(); for (int i = 0; i < 11 && Input.GetPauseDown(); i++) { quiting.localScale = new Vec3(1.0f, 0.1f * (float)i, 1.0f); yield return(new UnityEngine.WaitForSeconds(0.01f)); continue; } for (int i = 0; i < str.Length && Input.GetPauseDown(); i++) { text.text = str.Substring(0, i); yield return(new UnityEngine.WaitForSeconds(0.025f)); continue; } for (int j = 3; j >= 0 && Input.GetPauseDown(); j--) { for (int i = 0; i < 5 && Input.GetPauseDown(); i++) { switch (i) { case 0: text.text = str + $"{j}"; break; case 1: case 2: case 3: text.text += "."; break; } yield return(new UnityEngine.WaitForSeconds(0.15f)); continue; } } if (Input.GetPauseDown()) { SceneMng.LoadSceneAsync(0, SceneMode.Single); } else { SceneMng.UnloadSceneAsync(Pause.scene); } }
private static IEnumerator UnloadInternal(LoadContext context, LoadContext next) { if (context == null) { yield break; } yield return(context.AdditiveScenes .Where(x => next == null || !next.AdditiveScenes.Any(y => x.Name == y.Name)) .Select(x => UnitySceneManager.UnloadSceneAsync(x.Name) .ObserveEveryValueChanged(y => y.isDone) .FirstOrDefault()) .WhenAll() .StartAsCoroutine()); yield return(UnitySceneManager.UnloadSceneAsync(context.NextScene.Name)); }
private void RenderTabScenes() { using (new GUILayout.VerticalScope("Box")) { GUILayout.Label("All scenes", "header"); using (GUILayout.ScrollViewScope scroll = new GUILayout.ScrollViewScope(sceneScrollPos)) { sceneScrollPos = scroll.scrollPosition; for (int i = 0; i < USceneManager.sceneCountInBuildSettings; i++) { Scene currentScene = USceneManager.GetSceneByBuildIndex(i); string path = SceneUtility.GetScenePathByBuildIndex(i); bool isSelected = selectedScene.IsValid() && currentScene == selectedScene; bool isLoaded = currentScene.isLoaded; using (new GUILayout.HorizontalScope("Box")) { if (GUILayout.Button($"{(isSelected ? ">> " : "")}{i}: {path.TruncateLeft(35)}", isLoaded ? "sceneLoaded" : "label")) { selectedScene = currentScene; ActiveTab = GetTab("Hierarchy"); } if (isLoaded) { if (GUILayout.Button("Unload", "loadScene")) { USceneManager.UnloadSceneAsync(i); } } else { if (GUILayout.Button("Load", "loadScene")) { USceneManager.LoadSceneAsync(i); } } } } } } }
private System.Collections.IEnumerator _takeSS(GO caller, int sceneIdx) { AsyncOp op; SceneMng.sceneLoaded += this.sceneLoaded; op = SceneMng.LoadSceneAsync(sceneIdx, SceneMode.Additive); yield return(op); SceneMng.sceneLoaded -= this.sceneLoaded; TexBuffer tb = new TexBuffer(this.thumbWidth, this.thumbHeight, ScreenshotLevel.depth, ScreenshotLevel.fmt, ScreenshotLevel.texMode); tb.name = $"{sceneIdx}_screenshot.tex"; tb.filterMode = ScreenshotLevel.filterMode; tb.anisoLevel = ScreenshotLevel.anisoLevel; tb.antiAliasing = ScreenshotLevel.antiAliasing; tb.wrapMode = ScreenshotLevel.wrapMode; tb.depth = ScreenshotLevel.depth; tb.Create(); this.bbCamera.targetTexture = tb; this.bbCamera.enabled = true; yield return(null); Material mat = new Material(this.shader); mat.mainTexture = tb; mat.name = $"{sceneIdx}_screenshot.mat"; this.bbCamera.enabled = false; this.bbCamera.targetTexture = null; op = SceneMng.UnloadSceneAsync(sceneIdx); yield return(op); this.issueEvent <ScreenshotLevelController>( (x, y) => x.OnSSTaken(tb, mat), caller); this.running = false; }
IEnumerator DoRemoveScene() { while (mScenesToRemove.Count > 0) { var scene = mScenesToRemove.Dequeue(); var sync = UnitySceneManager.UnloadSceneAsync(scene); while (!sync.isDone) { yield return(null); } if (sceneRemovedCallback != null) { sceneRemovedCallback(scene); } } mSceneRemoveRout = null; }
/* Make sure this scene is unique, since the loader will actually load it * when in-game */ private System.Collections.IEnumerator makeSceneUnique() { Scene[] scenes; AsyncOp op; int mainIdx; scenes = new Scene[SceneMng.sceneCount]; mainIdx = -1; for (int i = 0; i < scenes.Length; i++) { scenes[i] = SceneMng.GetSceneAt(i); if (scenes[i].name == this.GameOverSceneName) { mainIdx = i; } } if (mainIdx == -1) { throw new System.Exception($"Didn't find the expected scene ({this.GameOverSceneName})"); } for (int i = 0; i < scenes.Length; i++) { if (i == mainIdx) { continue; } op = SceneMng.UnloadSceneAsync(scenes[i]); yield return(op); } SceneMng.SetActiveScene(scenes[mainIdx]); yield return(SceneMng.LoadSceneAsync( "scenes/000-game-controller/bg-scenes/GameOverBG", SceneMode.Additive)); yield return(runGameOverAnim()); }
IEnumerator DoLoadScene(string toScene, LoadSceneMode mode, bool unloadCurrent) { isLoading = true; //about to change scene if (sceneChangeStartCallback != null) { sceneChangeStartCallback(); } //play out transitions for (int i = 0; i < mTransitions.Count; i++) { yield return(mTransitions[i].Out()); } //wait for scene add to finish while (mSceneAddRout != null) { yield return(null); } //unload added scenes UnloadAddedScenes(); //wait for scene remove to finish while (mSceneRemoveRout != null) { yield return(null); } //scene is about to change if (sceneChangeCallback != null) { sceneChangeCallback(toScene); } bool doLoad = true; if (mode == LoadSceneMode.Additive) { bool isCurSceneRoot = _rootScene == mCurScene; //special case if we are loading the same scene we first instantiated, but is not the root if (!isCurSceneRoot && mFirstSceneLoaded == mCurScene) { mode = LoadSceneMode.Single; } else { //unload current scene if it's not the root //Debug.Log("unload: "+mCurScene); if (unloadCurrent && !isCurSceneRoot) { var sync = UnitySceneManager.UnloadSceneAsync(mCurScene); if (sync != null) { while (!sync.isDone) { yield return(null); } } } //load only if it doesn't exist doLoad = !UnitySceneManager.GetSceneByName(toScene).IsValid(); } } //load if (doLoad) { var sync = UnitySceneManager.LoadSceneAsync(toScene, mode); //something went wrong if (sync == null) { isLoading = false; yield break; } while (!sync.isDone) { yield return(null); } } else { yield return(null); } mCurScene = UnitySceneManager.GetSceneByName(toScene); UnitySceneManager.SetActiveScene(mCurScene); if (sceneChangePostCallback != null) { sceneChangePostCallback(); } //play in transitions for (int i = 0; i < mTransitions.Count; i++) { yield return(mTransitions[i].In()); } isLoading = false; if (sceneChangeEndCallback != null) { sceneChangeEndCallback(); } }
/// <summary> /// 卸载场景 /// </summary> /// <param name="sceneName"></param> public AsyncOperation UnloadSceneAsync(string sceneName) { return(UnitySceneManager.UnloadSceneAsync(sceneName)); }
private async UniTask Unload(string sceneName) { await UnitySceneManager.UnloadSceneAsync(sceneName); loadedSceneNames.Remove(sceneName); }
private void UnloadScene(int buildIndex) => UnitySceneManager.UnloadSceneAsync(buildIndex);