예제 #1
0
        /// <summary>
        ///   下载包资源
        /// </summary>
        IEnumerator StartDownloadPack()
        {
            if (ErrorCode != emErrorCode.None)
            {
                yield break;
            }

            UpdateCompleteValue(0f, 0f);

            if (packages_name_ == null)
            {
                Error(emErrorCode.InvalidPackageName);
                yield break;
            }

            //收集所有需要下载的AssetBundle
            List <string> ab_list = new List <string>();

            for (int i = 0; i < packages_name_.Count; ++i)
            {
                string        pack_name = packages_name_[i];
                List <string> list      = AssetBundleManager.Instance.FindAllAssetBundleFilesNameByPackage(pack_name);
                ab_list.AddRange(list);
            }
            if (ab_list == null)
            {
                Error(emErrorCode.NotFindAssetBundle);
                yield break;
            }

            //过滤已下载的资源
            ab_list.RemoveAll((assetbundle_name) =>
            {
                return(File.Exists(Common.GetFileFullName(assetbundle_name)));
            });
            if (ab_list.Count == 0)
            {
                yield break;
            }

            //载入资源信息描述文件
            ResourcesManifest resources_manifest = AssetBundleManager.Instance.ResourcesManifest;

            //开始下载
            ab_download_ = new AssetBundleDownloader(current_url_);
            ab_download_.Start(Common.PATH, ab_list, resources_manifest);
            while (!ab_download_.IsDone)
            {
                UpdateCompleteValue(ab_download_.CompletedSize, ab_download_.TotalSize);
                yield return(null);
            }
            if (ab_download_.IsFailed)
            {
                Error(emErrorCode.DownloadAssetBundleFailed);
                yield break;
            }
            ab_download_ = null;

            yield return(null);
        }
예제 #2
0
        /// <summary>
        ///   中止下载
        /// </summary>
        public void AbortDownload()
        {
            StopAllCoroutines();

            if (verifier_ != null)
            {
                verifier_.Abort();
                verifier_ = null;
            }
            if (ab_download_ != null)
            {
                ab_download_.Abort();
                ab_download_ = null;
            }

            UpdateState(emState.Abort);
            Done();
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        public void AbortUpdate()
        {
            StopAllCoroutines();

            if (verifier_ != null)
            {
                verifier_.Abort();
                verifier_ = null;
            }
            if (file_download_ != null)
            {
                file_download_.Abort();
                file_download_ = null;
            }
            if (ab_download_ != null)
            {
                ab_download_.Abort();
                ab_download_ = null;
            }
            SaveDownloadCacheData();
            UpdateState(emState.Abort);
            Done();
        }
예제 #4
0
        /// <summary>
        ///   更新AssetBundle
        /// </summary>
        IEnumerator StartUpdateAssetBundle()
        {
            if (ErrorCode != emErrorCode.None)
            {
                yield break;
            }

            UpdateCompleteValue(0f, 0f);

            //载入新的ResourcesManifest
            ResourcesManifest old_resource_manifest = AssetBundleManager.Instance.ResourcesManifest;
            string            file = Common.GetCacheFileFullName(Common.RESOURCES_MANIFEST_FILE_NAME);
            ResourcesManifest new_resources_manifest = Common.LoadResourcesManifestByPath(file);

            if (new_resources_manifest == null)
            {
                Error(emErrorCode.LoadNewResourcesManiFestFailed, "Can't load new verion ResourcesManifest!");
                yield break;
            }

            //载入MainManifest
            AssetBundleManifest manifest = AssetBundleManager.Instance.MainManifest;

            file = Common.GetCacheFileFullName(Common.MAIN_MANIFEST_FILE_NAME);
            AssetBundleManifest new_manifest = Common.LoadMainManifestByPath(file);

            if (new_manifest == null)
            {
                Error(emErrorCode.LoadNewMainManifestFailed, "Can't find new version MainManifest!");
                yield break;
            }

            //获取需下载的资源列表与删除的资源的列表
            List <string> download_files = new List <string>();
            List <string> delete_files   = new List <string>();

            CompareAssetBundleDifference(ref download_files, ref delete_files, manifest, new_manifest, old_resource_manifest, new_resources_manifest);

            //删除已废弃的文件
            if (delete_files.Count > 0)
            {
                for (int i = 0; i < delete_files.Count; ++i)
                {
                    string full_name = Common.GetFileFullName(delete_files[i]);
                    if (File.Exists(full_name))
                    {
                        File.Delete(full_name);
                        yield return(0);
                    }
                }
            }

            //更新所有需下载的资源
            ab_download_ = new AssetBundleDownloader(current_url_);
            ab_download_.Start(Common.PATH, download_files, new_resources_manifest);
            while (!ab_download_.IsDone)
            {
                UpdateCompleteValue(ab_download_.CompletedSize, ab_download_.TotalSize);
                yield return(0);
            }
            if (ab_download_.IsFailed)
            {
                Error(emErrorCode.DownloadAssetBundleFailed);
                yield break;
            }
        }
예제 #5
0
        /// <summary>
        ///   更新AssetBundle
        /// </summary>
        IEnumerator UpdatingUpdateAssetBundle()
        {
            if (ErrorCode != emErrorCode.None)
            {
                yield break;
            }

            UpdateCompleteValue(0f, 0f);

            //载入新的ResourcesManifest
            ResourcesManifest old_resource_manifest = AssetBundleManager.Instance.ResManifest;
            string            file = Common.UPDATER_CACHE_PATH + "/" + Common.RESOURCES_MANIFEST_FILE_NAME;
            ResourcesManifest new_resources_manifest = Common.LoadResourcesManifestByPath(file);

            if (new_resources_manifest == null)
            {
                Error(emErrorCode.LoadNewResourcesManiFestFailed
                      , "Can't load new verion ResourcesManifest!");
                yield break;
            }

            //载入MainManifest
            AssetBundleManifest manifest = AssetBundleManager.Instance.MainManifest;

            file = Common.UPDATER_CACHE_PATH + "/" + Common.MAIN_MANIFEST_FILE_NAME;
            AssetBundleManifest new_manifest = Common.LoadMainManifestByPath(file);

            if (new_manifest == null)
            {
                Error(emErrorCode.LoadNewMainManifestFailed
                      , "Can't find new version MainManifest!");
                yield break;
            }

            //获取需下载的资源列表与删除的资源的列表
            List <string> download_files = new List <string>();
            List <string> delete_files   = new List <string>();

            ComparisonUtils.CompareAndCalcDifferenceFiles(ref download_files, ref delete_files
                                                          , manifest, new_manifest
                                                          , old_resource_manifest, new_resources_manifest
                                                          , ComparisonUtils.emCompareMode.All);

            // 进度控制
            float totalProgress   = delete_files.Count + download_files.Count;
            float currentProgress = 0;

            //载入下载缓存数据, 过滤缓存中已下载的文件
            DownloadCache download_cache = new DownloadCache();

            download_cache.Load(Common.DOWNLOADCACHE_FILE_PATH);
            if (!download_cache.HasData())
            {
                download_cache = null;
            }
            if (download_cache != null)
            {
                var cache_itr = download_cache.Data.AssetBundles.GetEnumerator();
                while (cache_itr.MoveNext())
                {
                    DownloadCacheData.AssetBundle elem = cache_itr.Current.Value;
                    string name      = elem.AssetBundleName;
                    string full_name = Common.GetFileFullName(name);
                    if (File.Exists(full_name))
                    {
                        string cache_hash = elem.Hash;
                        string new_hash   = new_manifest.GetAssetBundleHash(name).ToString();
                        if (!string.IsNullOrEmpty(cache_hash) &&
                            cache_hash.CompareTo(new_hash) == 0)
                        {
                            download_files.Remove(name);
                            ++currentProgress;
                            UpdateCompleteValue(currentProgress, totalProgress);
                            yield return(null);
                        }
                    }
                }
            }

            //删除已废弃的文件
            if (delete_files.Count > 0)
            {
                for (int i = 0; i < delete_files.Count; ++i)
                {
                    string full_name = Common.GetFileFullName(delete_files[i]);
                    if (File.Exists(full_name))
                    {
                        File.Delete(full_name);
                        ++currentProgress;
                        UpdateCompleteValue(currentProgress, totalProgress);
                        yield return(null);
                    }
                }
            }

            //更新所有需下载的资源
            ab_download_ = new AssetBundleDownloader(current_url_);
            ab_download_.Start(Common.PATH, download_files, new_resources_manifest);
            while (!ab_download_.IsDone)
            {
                UpdateCompleteValue(currentProgress + ab_download_.CompleteDownloadList.Count, totalProgress);
                yield return(null);
            }
            if (ab_download_.IsFailed)
            {
                Error(ab_download_.ErrorCode);
                yield break;
            }
        }