UnloadSceneAsync() public static method

Destroyes all GameObjects associated with the given scene and removes the scene from the SceneManager.

public static UnloadSceneAsync ( Scene scene ) : AsyncOperation
scene Scene Scene to unload.
return UnityEngine.AsyncOperation
コード例 #1
0
ファイル: GameStart.cs プロジェクト: linxscc/bnyx
    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;
            }
        }
    }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
    public void UnloadScene()
    {
        if (this.isRunning)
        {
            return;
        }

        this.isRunning = true;
        SceneMng.UnloadSceneAsync(this.gameObject.scene);
    }
コード例 #4
0
        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.");
        }
コード例 #5
0
        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);
        }
コード例 #6
0
    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;
    }
コード例 #7
0
ファイル: SceneManager.cs プロジェクト: syougun360/CutTrees
    /// <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;
            }
        }
    }
コード例 #8
0
    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);
        }
    }
コード例 #9
0
        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));
        }
コード例 #10
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #11
0
    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;
    }
コード例 #12
0
ファイル: SceneManager.cs プロジェクト: maple-yang/MateUnity
        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;
        }
コード例 #13
0
    /* 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());
    }
コード例 #14
0
ファイル: SceneManager.cs プロジェクト: maple-yang/MateUnity
        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();
            }
        }
コード例 #15
0
 /// <summary>
 /// 卸载场景
 /// </summary>
 /// <param name="sceneName"></param>
 public AsyncOperation UnloadSceneAsync(string sceneName)
 {
     return(UnitySceneManager.UnloadSceneAsync(sceneName));
 }
コード例 #16
0
        private async UniTask Unload(string sceneName)
        {
            await UnitySceneManager.UnloadSceneAsync(sceneName);

            loadedSceneNames.Remove(sceneName);
        }
コード例 #17
0
 private void UnloadScene(int buildIndex) => UnitySceneManager.UnloadSceneAsync(buildIndex);