Beispiel #1
0
        public IEnumerator LoadSceneAsync(string sceneName, string sceneAssetBundle, bool isAdditive = false, Action <float> progressListener = null)
        {
            AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, sceneName, isAdditive);

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


            if (progressListener == null)
            {
                // 方案一
                yield return(StartCoroutine(request));
            }
            else
            {
                // 方案二 TODO 可能有BUG
                {
                    int maxTry = 0;
                    while (request.Process() < 0.9f)
                    {
                        if (request.Process() < 0.001f && maxTry++ > 100)
                        {
                            Debug.LogError("网络无法获得资源:" + sceneAssetBundle + " " + sceneName);
                        }
                        // TODO 进度条处理
                        Debug.Log("加载:" + request.Process() * 100 + "/100");
                        yield return(new WaitForEndOfFrame());
                    }

                    while (!request.IsDone())
                    {
                        Debug.Log("加载:" + request.Process() * 100 + "/100");
                        yield return(new WaitForEndOfFrame());
                    }

                    Debug.Log("加载:100/100");
                }
            }
        }
Beispiel #2
0
    protected IEnumerator InitializeLevelAsync(string levelName, bool isAdditive)
    {
        // This is simply to get the elapsed time for this phase of AssetLoading.
        float startTime = Time.realtimeSinceStartup;

        // Load level from assetBundle.
        AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(sceneAssetBundle, levelName, isAdditive);

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

        // 方案一
        // yield return StartCoroutine(request);

        // 方案二
        {
            while (request.Process() < 0.9f)
            {
                // TODO 进度条处理
                Debug.Log("加载:" + request.Process() * 100 + "/100");
                yield return(new WaitForEndOfFrame());
            }

            while (!request.IsDone())
            {
                Debug.Log("加载:" + request.Process() * 100 + "/100");
                yield return(new WaitForEndOfFrame());
            }

            Debug.Log("加载:100/100");
        }

        // Calculate and display the elapsed time.
        float elapsedTime = Time.realtimeSinceStartup - startTime;

        Debug.Log("Finished loading scene " + levelName + " in " + elapsedTime + " seconds");
    }