Beispiel #1
0
        void Update()
        {
            if (assetsToLoad.Count > 0)
            {
                for (int i = (assetsToLoad.Count - 1); i >= 0; i--)
                {
                    LoadAssetFromBundle asset = assetsToLoad[i];
                    if (asset.IsDownloadDone)
                    {
                        //The download is done, instantiate the asset from the bundle
                        //다운로드가 완료 되면 번들에 있는 에셋을 생성한다
                        asset.InstantiateAsset();
                        //Remove the asset from the loading list
                        //다운로드 목록에 있는 에셋을 제거한다
                        assetsToLoad.RemoveAt(i);
                        //Destroy the LoadAssetFromBundle Script
                        //다운로드가 완료되었으므로 다운로드에 사용한 다운로드 스크립트를 제거한다
                        Destroy(asset);
                        //This means an asset is downloaded, which means you can start on the next one
                        //하나의 에셋이 다운로드 완료 되었으므로 다음 것을 다운 받을 준비가 되었다
                        isDownloaded = true;
                    }
                }

                if (isDownloaded) //The download is complete //에셋이 하나 다운로드되었다
                {
                    //Start the next download
                    //다음 에셋을 다운로드한다
                    foreach (LoadAssetFromBundle asset in assetsToLoad)
                    {
                        if (!asset.HasDownloadStarted)
                        {
                            //Start the download
                            //다운로드를 시작한다
                            asset.DownloadAsset();

                            //set the isDownloaded to false again
                            //다시 다운로드 플래그를 False로 바꾼다
                            isDownloaded = false;

                            //break the loop
                            //루프를 벗어난다
                            break;
                        }
                    }
                }
            }
            else //If there is nothing left to load, then destroy this game object //더이상 다운 받을 것이 없다면, 이 오브젝트를 제거한다
            {
                Destroy(this.gameObject);
            }
        }
        IEnumerator LoadContents()
        {
            while (assetsToLoad.Count > 0)
            {
                Dictionary <string, int> dicAssetForDownload = new Dictionary <string, int>();

                string strCurrentDnBundleName = "";

                int nDnFileSize     = 0;
                int nDnFileProgress = 0;

                for (int i = (assetsToLoad.Count - 1); i >= 0; i--)
                {
                    LoadAssetFromBundle asset = assetsToLoad[i];
                    if (asset.IsDownloadDone)
                    {
                        //다운로드가 완료 되면 번들에 있는 에셋을 생성한다
                        asset.InstantiateAsset();
                        //다운로드 목록에 있는 에셋을 제거한다
                        assetsToLoad.RemoveAt(i);
                        //다운로드가 완료되었으므로 다운로드에 사용한 다운로드 스크립트를 제거한다
                        Destroy(asset);
                        //하나의 에셋이 다운로드 완료 되었으므로 다음 것을 다운 받을 준비가 되었다
                        isDownloaded = true;
                    }
                    else
                    {
                        int nFileSize = dicBundleSize[asset.AssetBundleName];
                        nFileSize = (int)(nFileSize * (1.0f - asset.DownloadProgress));

                        if (dicAssetForDownload.ContainsKey(asset.AssetBundleName))
                        {
                            dicAssetForDownload[asset.AssetBundleName] = nFileSize;
                        }
                        else
                        {
                            dicAssetForDownload.Add(asset.AssetBundleName, nFileSize);
                        }


                        if (asset.HasDownloadStarted)
                        {
                            strCurrentDnBundleName = asset.AssetBundleName;
                            nDnFileSize            = nFileSize;
                            nDnFileProgress        = (int)(asset.DownloadProgress * 100.0f);
                        }
                    }
                }

                if (isDownloaded) //에셋이 하나 다운로드되었다
                {
                    //다음 에셋을 다운로드한다
                    foreach (LoadAssetFromBundle asset in assetsToLoad)
                    {
                        if (!asset.HasDownloadStarted)
                        {
                            //다운로드를 시작한다
                            asset.DownloadAsset();

                            //다시 다운로드 플래그를 False로 바꾼다
                            isDownloaded = false;

                            //루프를 벗어난다
                            break;
                        }
                    }
                }

                int nTotalRemainSize = 0;
                foreach (int nFilesize in dicAssetForDownload.Values)
                {
                    nTotalRemainSize += nFilesize;
                }

                //Broadcast to listener that progress changed
                DispatchEvent(UPDATE_DOWNLOADER, new FrameWork.Event.BasicEventArgs(totalSize, nTotalRemainSize, strCurrentDnBundleName, nDnFileProgress));
                Debug.Log(nTotalRemainSize);
                yield return(new WaitForSeconds(updateInterval));
            }

            //Destroy(this.gameObject);
        }