예제 #1
0
        private IEnumerator LoadBundles(AssetBundlesConfig config)
        {
            if (config?.AssetBundleInfos != null)
            {
                float progressPerBundle = 1.0f / config.AssetBundleInfos.Length;

                for (int assetBundleIndex = 0; assetBundleIndex < config.AssetBundleInfos.Length; assetBundleIndex++)
                {
                    AssetBundleInfo assetBundleInfo = config.AssetBundleInfos[assetBundleIndex];

                    float progressBase = assetBundleIndex * progressPerBundle;
                    float overallProgress;

                    UnityWebRequest request =
                        UnityWebRequestAssetBundle.GetAssetBundle(assetBundleInfo.Uri, assetBundleInfo.Version, 0);

                    UnityWebRequestAsyncOperation asyncOperation = request.SendWebRequest();
                    while (asyncOperation.isDone == false)
                    {
                        overallProgress = progressBase + (asyncOperation.progress * progressPerBundle);
                        ReportLoadProgress(assetBundleInfo.Name, asyncOperation.progress, overallProgress);

                        yield return(null);
                    }

                    overallProgress = progressBase + progressPerBundle;
                    ReportLoadProgress(assetBundleInfo.Name, 1.0f, overallProgress);
                    assetBundles[assetBundleInfo.Name] = DownloadHandlerAssetBundle.GetContent(request);
                }

                ReportLoadComplete();
            }
        }
예제 #2
0
 public void LoadAssetBundles(AssetBundlesConfig config)
 {
     coroutineRunner.StartCoroutine(LoadBundles(config));
 }