LoadSceneAsync() private method

private LoadSceneAsync ( int sceneBuildIndex ) : AsyncOperation
sceneBuildIndex int
return UnityEngine.AsyncOperation
Beispiel #1
0
    void Update()
    {
        bool  swap       = false;
        float dv         = this.delta * UnityEngine.Time.deltaTime;
        Color deltaColor = new Color(0.0f, 0.0f, 0.0f, dv);

        foreach (UiText txt in this.blink)
        {
            if (txt.color.a + dv > 1.0f)
            {
                swap = true;
            }
            else if (txt.color.a + dv < 0.0f)
            {
                swap = true;
            }
            else
            {
                txt.color = txt.color + deltaColor;
            }
        }

        if (swap)
        {
            this.delta *= -1.0f;
        }

        if (this.allowChange && Input.CheckAnyKeyDown())
        {
            SceneMng.LoadSceneAsync("Loader", SceneMode.Single);
            this.allowChange = false;
        }
    }
Beispiel #2
0
    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;
            }
        }
    }
        private static IEnumerator LoadSubsInternal(LoadContext context, LoadContext prev)
        {
            yield return(context.AdditiveScenes
                         .Where(x => {
                if (prev == null)
                {
                    return true;
                }
                var cache = prev.AdditiveScenes.FirstOrDefault(y => x.Name == y.Name);
                if (cache == null)
                {
                    return true;
                }
                else
                {
                    x.Lifecycles = cache.Lifecycles;
                }
                return false;
            })
                         .Select(additiveScene => UnitySceneManager.LoadSceneAsync(additiveScene.Name, LoadSceneMode.Additive)
                                 .AsObservable()
                                 .Select(_ => FindSceneContext(additiveScene.Name))
                                 .SelectMany(x => new WaitUntil(() => x.Initialized)
                                             .ToObservable()
                                             .Select(_ => x))
                                 .Do(x => additiveScene.Lifecycles = x.Container.ResolveAll <ISceneLifecycle>().Where(y => !context.NextScene.Lifecycles.Any(z => y == z)))
                                 .FirstOrDefault())
                         .WhenAll()
                         .StartAsCoroutine());

            Resources.UnloadUnusedAssets();

            GC.Collect();
        }
Beispiel #4
0
    public static IEnumerator LoadSceneAsyncCo(string sceneName, float minDuration)
    {
        USM.sceneLoaded += OrientNewScene;

        var asyncOp = USM.LoadSceneAsync(sceneName);

        if (minDuration > 0)
        {
            asyncOp.allowSceneActivation = false;
            yield return(new WaitForSecondsRealtime(minDuration));

            for (float t = 0; t < minDuration; t += Time.unscaledDeltaTime)
            {
                Shader.SetGlobalFloat("_NormalisedProgress", t / minDuration);
                yield return(null);
            }
            Shader.SetGlobalFloat("_NormalisedProgress", 1);
            asyncOp.allowSceneActivation = true;
        }

        while (!asyncOp.isDone)
        {
            yield return(null);
        }
    }
        private static IEnumerator LoadInternal(LoadContext context)
        {
            if (context == null)
            {
                yield break;
            }

            var scene = UnitySceneManager.GetSceneByName(context.NextScene.Name);

            if (!scene.isLoaded)
            {
                yield return(UnitySceneManager.LoadSceneAsync(context.NextScene.Name, LoadSceneMode.Additive));
            }
            UnitySceneManager.SetActiveScene(UnitySceneManager.GetSceneByName(context.NextScene.Name));

            var sceneContext = FindSceneContext(context.NextScene.Name);

            if (sceneContext == null)
            {
                yield break;
            }

            yield return(new WaitUntil(() => sceneContext.Initialized));

            var sceneSettings = sceneContext.Container.TryResolve <SceneSettings>();

            if (sceneSettings != null)
            {
                sceneSettings.Subs.ForEach(x => context.AddAdditiveScene(x));
            }
            context.NextScene.Lifecycles = sceneContext.Container.ResolveAll <ISceneLifecycle>();
        }
Beispiel #6
0
        IEnumerator DoAddScene()
        {
            while (mScenesToAdd.Count > 0)
            {
                //wait for scene removes to finish
                while (mSceneRemoveRout != null)
                {
                    yield return(null);
                }

                var sceneName = mScenesToAdd.Dequeue();

                var sync = UnitySceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);

                while (!sync.isDone)
                {
                    yield return(null);
                }

                var sceneAdded = UnitySceneManager.GetSceneByName(sceneName);
                mScenesAdded.Add(sceneAdded);

                if (sceneAddedCallback != null)
                {
                    sceneAddedCallback(sceneAdded);
                }
            }

            mSceneAddRout = null;
        }
Beispiel #7
0
 static public void LoadLevel(int idx)
 {
     Loader.currentLevel = idx;
     Loader.checkpoint   = 0;
     Loader.onLoadLevel.exec(idx);
     SceneMng.LoadSceneAsync("Loader", SceneMode.Single);
 }
        public static void LoadSceneByName(String name, bool force = false)
        {
            Scene scene = SCM.GetSceneByName(name);

            if (force)
            {
                if (!scene.isLoaded)
                {
                    SCM.LoadScene(name);
                }
                else
                {
                    SCM.LoadScene(scene.name);
                }
            }
            else
            if (!scene.isLoaded)
            {
                SCM.LoadSceneAsync(name);
            }
            else
            {
                SCM.LoadSceneAsync(scene.name);
            }
        }
Beispiel #9
0
        IEnumerator LoadSceneAsync(int sceneName)
        {
            float alpha = splashScreen.alpha;

            // fadeIn splashScreen
            for (float t = 0.0f; t < 1.0f; t += Time.deltaTime)
            {
                splashScreen.alpha = t;
                yield return(null);
            }

            splashScreen.alpha = 1.0f;
            AsyncOperation loading = UnitySceneManger.LoadSceneAsync(sceneName);

            while (!loading.isDone)
            {
                yield return(null);
            }

            // fadeOut splashScreen
            for (float t = 1.0f; t > 0.0f; t -= Time.deltaTime)
            {
                splashScreen.alpha = t;
                yield return(null);
            }

            splashScreen.alpha = 0.0f;
        }
        public static void LoadSceneById(int id, bool force = false)
        {
            if (id >= GetSceneCount())
            {
                throw new Exception("Scene Index outisde of Range");
            }

            int   index = 1 + id;
            Scene scene = SCM.GetSceneByBuildIndex(index);

            if (force)
            {
                if (!scene.isLoaded)
                {
                    SCM.LoadScene(index);
                }
                else
                {
                    SCM.LoadScene(scene.name);
                }
            }
            else
            if (!scene.isLoaded)
            {
                SCM.LoadSceneAsync(index);
            }
            else
            {
                SCM.LoadSceneAsync(scene.name);
            }
        }
Beispiel #11
0
    /// <summary>
    /// 読込開始
    /// </summary>
    /// <param name="id"></param>
    /// <param name="addtive"></param>
    /// <param name="async"></param>
    public SceneLoader(SceneDefine.SCENE_ID id, bool addtive, bool async)
    {
        SceneID      = id;
        Name         = SceneDefine.SceneNames[(int)id];
        this.addtive = addtive;
        this.async   = async;

        if (async)
        {
            var param = new UnityEngine.SceneManagement.LoadSceneParameters();
            if (addtive)
            {
                param.loadSceneMode = UnityEngine.SceneManagement.LoadSceneMode.Additive;
            }
            else
            {
                param.loadSceneMode = UnityEngine.SceneManagement.LoadSceneMode.Single;
            }

            asyncOperation = UnitySceneManager.LoadSceneAsync(Name, param);
        }
        else
        {
            if (addtive)
            {
                UnitySceneManager.LoadScene(Name, UnityEngine.SceneManagement.LoadSceneMode.Additive);
            }
            else
            {
                UnitySceneManager.LoadScene(Name, UnityEngine.SceneManagement.LoadSceneMode.Single);
            }
        }
    }
Beispiel #12
0
 void Update()
 {
     if (this.allowReset && Input.CheckAnyKeyDown())
     {
         SceneMng.LoadSceneAsync(this.MainMenuScene, SceneMode.Single);
         this.allowReset = false;
     }
 }
Beispiel #13
0
        /// <summary>
        /// 异步加载场景
        /// </summary>
        /// <param name="sceneName"></param>
        public Task <AsyncOperation> LoadSceneAsync(string assetBundleName, string sceneName, LoadSceneMode mode = LoadSceneMode.Additive)
        {
            TaskCompletionSource <AsyncOperation> task = new TaskCompletionSource <AsyncOperation>();

            task.SetResult(UnitySceneManager.LoadSceneAsync(sceneName, mode));
            //Debug.Log("szfsdfsd");
            return(task.Task);
            //  return UnitySceneManager.LoadSceneAsync(sceneName, mode);
        }
Beispiel #14
0
    /// <summary>
    /// Loads scene only if not already loaded
    /// </summary>
    /// <param name="scene"></param>
    public void LoadAdditiveScene(Scene scene)
    {
        if (!additiveScenes.Contains(scene))
        {
            UnitySceneManager.LoadSceneAsync((int)scene, LoadSceneMode.Additive);

            additiveScenes.Push(scene);
        }
    }
    IEnumerator LoadSceneAsync(string sceneName)
    {
        AsyncOperation asyncLoad = Manager.LoadSceneAsync(sceneName);

        // Wait until the asynchronous scene fully loads
        while (!asyncLoad.isDone)
        {
            yield return(null);
        }
    }
    public void LoadLevel()
    {
        if (this.isLoading)
        {
            return;
        }

        this.isLoading = true;
        SceneMng.LoadSceneAsync(this.scene, SceneMode.Single);
    }
Beispiel #17
0
    IEnumerator RestartScene()
    {
        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);

        //Wait until the last operation fully loads to return anything
        while (!asyncLoad.isDone)
        {
            yield return(null);
        }
    }
Beispiel #18
0
        /// <summary> Loads the next scene asynchronously </summary>
        public static bool TryLoadNextSceneAsync(LoadSceneMode loadSceneMode, out AsyncOperation asyncOperation)
        {
            if (!SceneExists(NextSceneIndex))
            {
                asyncOperation = null;
                return(false);
            }

            asyncOperation = SM.LoadSceneAsync(NextSceneIndex, loadSceneMode);
            return(true);
        }
Beispiel #19
0
        /// <summary>
        ///     Loads a scene
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="loadMode"></param>
        /// <returns></returns>
        public static AsyncOperation LoadScene(TCScene scene, LoadSceneMode loadMode = LoadSceneMode.Single)
        {
            PreparingSceneLoadEvent?.Invoke(scene);
            Debug.Log($"The scene `{scene.scene}` was requested to be loaded.");

            AsyncOperation sceneLoad = SceneManager.LoadSceneAsync(scene.scene, loadMode);

            StartSceneLoadEvent?.Invoke(sceneLoad);

            return(sceneLoad);
        }
        public static async Task LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode)
        {
            TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>();

            AsyncOperation asyncOperation = USceneManager.LoadSceneAsync(sceneName, loadSceneMode);

            asyncOperation.completed += (AsyncOperation ao) => taskCompletionSource.SetResult(ao.isDone);

            await taskCompletionSource.Task;

            FLog.Info(CLASS_TYPE.Name, $"Scene `{USceneManager.GetSceneByName(sceneName).name}` has been loaded.");
        }
Beispiel #21
0
 void OnTriggerEnter(UnityEngine.Collider c)
 {
     foreach (string s in this.killableTags)
     {
         if (c.tag == s)
         {
             SceneMng.LoadSceneAsync("YouLose", SceneMode.Additive);
             this.gameObject.SetActive(false);
             break;
         }
     }
 }
Beispiel #22
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;
    }
Beispiel #23
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);
        }
    }
Beispiel #24
0
        public IEnumerator Dump(string sceneName = null)
        {
            List <string> scenes = new List <string>();

            for (int j = 0; j < USceneManager.sceneCountInBuildSettings; j++)
            {
                string scenePath = SceneUtility.GetScenePathByBuildIndex(j);
                string name      = Path.GetFileNameWithoutExtension(scenePath);
                scenes.Add(name);
                var load = USceneManager.LoadSceneAsync(j, LoadSceneMode.Single);
                while (!load.isDone)
                {
                    yield return(new WaitForEndOfFrame());
                }
                yield return(new WaitForSeconds(0.2f));

                Scene         s  = USceneManager.GetActiveScene();
                StringBuilder sb = new StringBuilder();
                foreach (var g in s.GetRootGameObjects())
                {
                    Visit(g.transform, 0, null, sb);
                }
                try
                {
                    var          fs = File.Create($"Z:\\1\\{s.name}.txt");
                    StreamWriter sw = new StreamWriter(fs);
                    sw.Write(sb.ToString());
                    sw.Close();
                    fs.Close();
                }
                catch { }

                //
            }
            var load_ = USceneManager.LoadSceneAsync(2, LoadSceneMode.Single);

            while (!load_.isDone)
            {
                yield return(new WaitForEndOfFrame());
            }
            yield return(USceneManager.LoadSceneAsync("Quit_To_Menu"));

            while (USceneManager.GetActiveScene().name != Constants.MENU_SCENE)
            {
                yield return(new WaitForEndOfFrame());
            }
        }
Beispiel #25
0
    void Awake()
    {
        if (Instance != null)
        {
            Destroy(this);
        }
        else
        {
            Instance       = this;
            additiveScenes = new Stack <Scene>();

            SaveManager.Load();

            UnitySceneManager.LoadSceneAsync((int)Scene.MainMenu);
            CurrentScene = Scene.MainMenu;
        }
    }
Beispiel #26
0
    private void onCenter(bool enter, RelPos p, GO other)
    {
        Type otherType = Type.Error;

        this.issueEvent <RemoteGetType>(
            (x, y) => x.Get(out otherType), other);
        if (otherType != Type.Player && otherType != Type.Minion)
        {
            /* Avoid triggering the death scene while rendering the
             * level thumbnails */
            if (SceneMng.GetActiveScene().name != LevelSelectScene)
            {
                Global.Sfx.playPlayerCrushed(this.fastGetTr());
                SceneMng.LoadSceneAsync("YouLose", SceneMode.Additive);
            }
            this.gameObject.SetActive(false);
        }
    }
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #28
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;
    }
Beispiel #29
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());
    }
Beispiel #30
0
    void Update()
    {
        if (!this.resetting && this.doReset || Input.GetResetButton())
        {
            if (!this.doReset && !this.done)
            {
                this.doReset = true;
                /* TODO: Send in-game warning */
            }
            else if (this.done && !this.resetting)
            {
                this.reload();
            }
        }

        if (this.done && !this.loadingPause && !this.pauseUi.isLoaded &&
            Input.GetPauseJustPressed())
        {
            SceneMng.sceneLoaded += onLoadPause;
            this.loadingPause     = true;
            SceneMng.LoadSceneAsync(Loader.pauseUiScene,
                                    SceneMode.Additive);
        }
    }