Exemplo n.º 1
0
        private IEnumerator LoadSceneAsync(SceneProperties _scene)
        {
            previousScene = currentScene;
            currentScene  = _scene;
            LoadingScreenProperties _loadingScreen = null;

            // if this scene have loading screen
            if (_scene.isLoadingScreen)
            {
                // if is anything in loading screens array
                if (loadingScreens.Count > 0)
                {
                    // if scane loading screen indeks is in this array
                    if (_scene.loadingScreenIndex < loadingScreens.Count)
                    {
                        _loadingScreen = loadingScreens[_scene.loadingScreenIndex];
                    }
                    else // if not then set first loading screen
                    {
                        _loadingScreen = loadingScreens[0];
                    }
                }
                // if this scene is first in game dont fade out from previouse
                if (previousScene.scene != null)
                {
                    // if nextscene has loading screen fadeOut from scene
                    FadeOut(_loadingScreen);
                    yield return(new WaitForSeconds(_loadingScreen.fadeOutDuration));
                }
            }

            // load scene asynch
            AsyncOperation ao = SceneManager.LoadSceneAsync(_scene.buildIndex, _scene.loadSceneMode);

            // while loading
            while (!ao.isDone)
            {
                float progress = Mathf.Clamp01(ao.progress / 0.9f);
                //Debug.Log("Loading progress: " + (progress * 100) + "%");
                // if is loading screen then push there progress e.g for progress bars
                if (_scene.isLoadingScreen)
                {
                    _loadingScreen.OnLoading(progress);
                }
                yield return(null);
            }
            // if scene is loaded and has loading screen then FadeIn to scene
            if (_scene.isLoadingScreen)
            {
                FadeIn(_loadingScreen);
            }
            // close opened ui when loaded new scene
            if (_scene.closeAllUIScreenImmediately)
            {
                UIManager.Instance.CloseAllUIScreenImmediately();
            }
            UIDebug.PrintDebug(UIDebug.DebugType.SCENE, transform, "UISceneManager", "LoadSceneAsync", "Scene loaded build index " + _scene.buildIndex + ".");
            // invoke event on loaded scene (open some new ui or something)
            _scene.OnSceneLoaded();
        }
Exemplo n.º 2
0
 private IEnumerator _FadeOut(LoadingScreenProperties _loadingScreen)
 {
     if (_loadingScreen.fadeInDuration == 0)
     {
         _loadingScreen.canvasGroup.alpha = 1f;
         yield return(null);
     }
     else
     {
         _loadingScreen.OnLoading(0f);
         float lerpTime = 0f;
         while (lerpTime < _loadingScreen.fadeInDuration)
         {
             _loadingScreen.canvasGroup.alpha = Mathf.Lerp(0f, 1f, (lerpTime / _loadingScreen.fadeInDuration));
             lerpTime += Time.deltaTime;
             yield return(null);
         }
         _loadingScreen.canvasGroup.alpha = 1f;
     }
 }