예제 #1
0
        /// <summary>
        /// 异步加载场景
        /// </summary>
        private async Task _LoadScene(string sceneAssetBundle, string levelName, bool isAdditive, Action <float> cbProgress)
        {
            float startTime = Time.realtimeSinceStartup;
            AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive);

            if (request != null)
            {
                while (request.Progress() < 1f)
                {
                    await waitFrame;
                    cbProgress?.Invoke(request.Progress());
                    if (request.IsDone())
                    {
                        break;
                    }
                }
                cbProgress?.Invoke(1f);
            }

            float elapsedTime = Time.realtimeSinceStartup - startTime;

            Utils.ResetShader(null);
            Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds");
            Debug.Log("当前场景 " + UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
        }
예제 #2
0
    // Use this for initialization
    public IEnumerator SetLoadingProgressBar(AssetBundleLoadOperation operation)
    {
        string fullPercent = "100";

        if (canvas.gameObject.activeInHierarchy == false)
        {
            SetShow(canvas.gameObject);
        }

        loadingtext.text = ((int)(operation.Progress() * 100f)).ToString();
        sliderbar.value  = 0.0f;

        while (operation.Progress() < 0.9f)
        {
            float timer = 0f;
            while (timer < 1f)
            {
                loadingtext.text = ((int)(operation.Progress() * 100f)).ToString();
                sliderbar.value  = Mathf.Lerp(sliderbar.value, operation.Progress(), timer);
                timer           += Time.deltaTime;
                yield return(null);
            }
            if (timer >= 1f)
            {
                timer = 0f;
            }
            if (operation.Progress() >= 0.9f)
            {
                sliderbar.value  = 1.0f;
                loadingtext.text = fullPercent;
                break;
            }
            yield return(null);
        }

        yield return(new WaitForSeconds(1f));

        SetHide(canvas.gameObject);
    }