Пример #1
0
        private IEnumerator LoadLevel(string sceneName)
        {
            loadingScreen.gameObject.SetActive(true);
            yield return(new WaitForEndOfFrame());

            var asyncOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);

            asyncOperation.allowSceneActivation = false;
            while (!asyncOperation.isDone)
            {
                loadingScreen.Progress = asyncOperation.progress;
                if (asyncOperation.progress >= 0.9f)
                {
                    asyncOperation.allowSceneActivation = true;
                }
                yield return(null);
            }

            var scene = SceneManager.GetSceneByName(sceneName);

            SceneManager.SetActiveScene(scene);
            loadingScreen.gameObject.SetActive(false);
        }
Пример #2
0
        private IEnumerator LoadGame()
        {
            yield return(SceneManager.LoadSceneAsync(scenes.GetSceneName(currentScene), LoadSceneMode.Additive));

            SceneManager.SetActiveScene(SceneManager.GetSceneByName(scenes.GetSceneName(currentScene)));
        }
Пример #3
0
            public virtual void All(IList <string> names)
            {
                if (IsProcessing)
                {
                    Debug.LogError("Trying to load scenes during a scene loading, please wait for current scenes to load");
                    return;
                }

                Coroutine = Core.SceneAcessor.StartCoroutine(Procedure());

                IEnumerator Procedure()
                {
                    Progress = 0f;

                    yield return(Fader.To(1f));

                    SceneManager.LoadScene(menu.name);
                    yield return(Fader.To(0f));

                    Operations = new List <AsyncOperation>();
                    for (int i = 0; i < names.Count; i++)
                    {
                        var operation = SceneManager.LoadSceneAsync(names[i], LoadSceneMode.Additive);
                        operation.allowSceneActivation = false;

                        Operations.Add(operation);

                        var ratio = 1f / names.Count;

                        while (true)
                        {
                            Progress = (Mathf.InverseLerp(0f, 0.9f, operation.progress) * ratio) + ((Operations.Count - 1) * ratio);

                            if (operation.progress == 0.9f)
                            {
                                break;
                            }

                            yield return(new WaitForEndOfFrame());
                        }
                    }

                    Progress = 1f;

                    yield return(new WaitForSecondsRealtime(0.6f));

                    yield return(Fader.To(1f));

                    yield return(new WaitForSecondsRealtime(0.2f));

                    void SceneLoadedCallback(Scene scene, LoadSceneMode mode)
                    {
                        var index = names.IndexOf(scene.name);

                        Operations[index] = null;

                        if (scene.name == names.First())
                        {
                            SceneManager.SetActiveScene(scene);
                        }

                        if (scene.name == names.Last())
                        {
                            SceneManager.sceneLoaded -= SceneLoadedCallback;

                            Operations.Clear();

#pragma warning disable CS0618 // Type or member is obsolete
                            SceneManager.UnloadScene(menu.name);
#pragma warning restore CS0618 // Type or member is obsolete
                        }
                    }

                    SceneManager.sceneLoaded += SceneLoadedCallback;

                    for (int i = 0; i < Operations.Count; i++)
                    {
                        Operations[i].allowSceneActivation = true;
                    }

                    yield return(new WaitForSeconds(0.25f));

                    yield return(Fader.To(0f));

                    End();
                }
            }
Пример #4
0
 private void SetActiveScene(SceneData sceneData)
 {
     SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(sceneData.BuildIndex));
     Debug.Log("ACTIVE SCENE SET: " + sceneData.name);
 }