Ejemplo n.º 1
0
        IEnumerator AsyncLoad(int scene)
        {
            float          minLoadTime = 2.0f;
            float          steps       = 100f;
            float          stepWait    = minLoadTime / steps;
            WaitForSeconds wfsStepWait = new WaitForSeconds(stepWait);
            float          loadTime    = 0.0f;

            loadProgress = 0;
            if (simpleSlider && showLoader)
            {
                simpleSlider.value = loadProgress;
            }

            bool fin = false;

            if (LoadGroup && showLoader)
            {
                LoadGroup.gameObject.SetActive(true);
                LoadGroup.FadeIn(0, () => { fin = true; });
            }
            while (LoadGroup && showLoader && !fin)
            {
                yield return(new WaitForSeconds(0.1f));
            }

            AsyncOperation ao = SceneManager.LoadSceneAsync(scene);

            ao.allowSceneActivation = false;

            while (!ao.isDone && loadTime < minLoadTime)
            {
                loadTime    += stepWait;
                loadProgress = Mathf.Clamp01(loadProgress + 1.0f / steps);
                if (simpleSlider && showLoader)
                {
                    simpleSlider.value = loadProgress;
                }
                if (ao.progress >= 0.9f && !ao.allowSceneActivation && loadTime >= 0.9f * minLoadTime)
                {
                    ao.allowSceneActivation = true;
                }
                Debug.Log("waite scene: " + loadTime);
                yield return(wfsStepWait);
            }

            if (LoadGroup && showLoader)
            {
                LoadGroup.FadeOut(0, null);
            }
            if (LoadingCallBack != null)
            {
                LoadingCallBack();
            }
        }
Ejemplo n.º 2
0
        private IEnumerator AsyncLoadBeaty(int scene, Action <float> progresUpdate, Action completeCallBack)
        {
            float apprLoadTime = 1f;
            float steps        = 100f;
            float loadTime     = 0.0f;

            loadProgress = 0;
            if (simpleSlider && showLoader)
            {
                simpleSlider.value = loadProgress;
            }

            bool fin = false;

            if (LoadGroup && showLoader)
            {
                LoadGroup.gameObject.SetActive(true);
                LoadGroup.FadeIn(0, () => { fin = true; });
            }
            while (LoadGroup && showLoader && !fin)
            {
                yield return(null);
            }

            AsyncOperation ao = SceneManager.LoadSceneAsync(scene);

            ao.allowSceneActivation = false;
            float lastTime = Time.time;

            while (!ao.isDone && loadProgress < 0.99f)
            {
                loadTime    += (Time.time - lastTime);
                lastTime     = Time.time;
                loadProgress = Mathf.Clamp01(loadProgress + 0.01f);
                if (simpleSlider && showLoader)
                {
                    simpleSlider.value = loadProgress;
                }

                if (loadTime >= 0.5f * apprLoadTime && (ao.progress < 0.5f))
                {
                    apprLoadTime *= 1.1f;
                }
                else if (loadTime >= 0.5f * apprLoadTime && (ao.progress > 0.5f))
                {
                    apprLoadTime /= 1.1f;
                }

                if (ao.progress >= 0.90f && !ao.allowSceneActivation && loadProgress >= 0.99f)
                {
                    ao.allowSceneActivation = true;
                }
                progresUpdate?.Invoke(loadProgress);
                // Debug.Log("waite scene: " + loadTime + "ao.progress : " + ao.progress);
                yield return(new WaitForSeconds(apprLoadTime / steps));;
            }
            if (LoadGroup && showLoader)
            {
                LoadGroup.FadeOut(0, null);
            }
            completeCallBack?.Invoke();
        }