/// <summary> /// 拷贝初始目录所有文件 /// </summary> IEnumerator CopyAllInitialFiles() { //拷贝所有配置文件 yield return(DownLoadCommon.StartCopyInitialFile(DownLoadCommon.MAIN_MANIFEST_FILE_NAME)); string mainifestFullName = DownLoadCommon.GetFileFullName(DownLoadCommon.MAIN_MANIFEST_FILE_NAME); AssetBundleManifest initial = DownLoadCommon.LoadMainManifestByPath(mainifestFullName); if (initial == null) { yield break; } //拷贝AssetBundle文件 string[] all_assetbundle = initial.GetAllAssetBundles(); this.InitTotal = all_assetbundle.Length; for (int i = 0; i < all_assetbundle.Length; ++i) { this.InitCurrent = i; string name = all_assetbundle[i]; yield return(DownLoadCommon.StartCopyInitialFile(name)); } //拷贝结束资源 保证安装包拷贝结束 yield return(DownLoadCommon.StartCopyInitialFile(DownLoadCommon.END_RESOUCES_FILE_NAME)); }
/// <summary> /// 更新AssetBundle /// </summary> IEnumerator StartUpdateAssetBundle() { Debug.Log("AssetUpdater:StartUpdateAssetBundle"); if (ErrorCode != EmErrorCode.None) { yield break; } UpdateCompleteValue(0f, 0f); ////载入MainManifest AssetBundleManifest manifest = ZTAssetBundleManager.GetInstance().MainManifest; //载入新的ResourcesManifest string file = DownLoadCommon.GetCacheFileFullName(DownLoadCommon.MAIN_MANIFEST_FILE_NAME); AssetBundleManifest new_manifest = DownLoadCommon.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); //删除已废弃的文件 if (delete_files.Count > 0) { for (int i = 0; i < delete_files.Count; ++i) { string full_name = DownLoadCommon.GetFileFullName(delete_files[i]); if (File.Exists(full_name)) { File.Delete(full_name); yield return(0); } } } //更新所有需下载的资源 _ab_download = new AssetBundleDownloader(_current_ab_url); _ab_download.Start(DownLoadCommon.PATH, download_files); while (!_ab_download.IsDone) { UpdateCompleteValue(_ab_download.CompletedSize, _ab_download.TotalSize); yield return(0); } if (_ab_download.IsFailed) { Error(EmErrorCode.DownloadAssetBundleFailed); yield break; } }
/// <summary> /// 写入下载缓存信息,用于断点续传 /// </summary> void SaveDownloadCacheData() { if (CurrentState < EmState.UpdateAssetBundle) { return; } if (!Directory.Exists(DownLoadCommon.CACHE_PATH)) { return; } //载入新的Manifest string new_manifest_name = DownLoadCommon.GetCacheFileFullName(DownLoadCommon.MAIN_MANIFEST_FILE_NAME); AssetBundleManifest new_manifest = DownLoadCommon.LoadMainManifestByPath(new_manifest_name); if (new_manifest == null) { return; } //先尝试读取旧的缓存信息,再保存现在已经下载的数据 //PS:由于只有版本完整更新完才会移动Cache目录,且玩家可能多次尝试下载更新,所以必须保留旧的缓存信息 DownloadCache cache = new DownloadCache(); cache.Load(DownLoadCommon.DOWNLOADCACHE_FILE_PATH); if (_ab_download != null && _ab_download.CompleteDownloads != null && _ab_download.CompleteDownloads.Count > 0) { for (int i = 0; i < _ab_download.CompleteDownloads.Count; ++i) { string assetbundle_name = _ab_download.CompleteDownloads[i]; Hash128 hash_code = new_manifest.GetAssetBundleHash(assetbundle_name); if (hash_code.isValid && !cache.Data.AssetBundles.ContainsKey(assetbundle_name)) { DownloadCacheData.AssetBundle elem = new DownloadCacheData.AssetBundle() { AssetBundleName = assetbundle_name, Hash = hash_code.ToString(), }; Debug.Log(cache.Data.AssetBundles.Count + " - Cache Add:" + assetbundle_name); cache.Data.AssetBundles.Add(assetbundle_name, elem); } } } if (cache.HasData()) { cache.Save(DownLoadCommon.DOWNLOADCACHE_FILE_PATH); } }
/// <summary> /// 拷贝初始目录所有文件 /// </summary> IEnumerator CopyAllInitialFiles() { //拷贝所有配置文件 yield return(DownLoadCommon.StartCopyInitialFile(DownLoadCommon.MAIN_MANIFEST_FILE_NAME)); string initial_full_name = DownLoadCommon.GetFileFullName(DownLoadCommon.MAIN_MANIFEST_FILE_NAME); AssetBundleManifest initial = DownLoadCommon.LoadMainManifestByPath(initial_full_name); if (initial == null) { yield break; } //拷贝AssetBundle文件 string[] all_assetbundle = initial.GetAllAssetBundles(); for (int i = 0; i < all_assetbundle.Length; ++i) { string name = all_assetbundle[i]; yield return(DownLoadCommon.StartCopyInitialFile(name)); } //ResourcesManifest resources_manifest = DownLoadCommon.LoadResourcesManifest(); //if (resources_manifest == null) //{ // Debug.LogWarning("Can't load ResourcesManifest file!"); // yield break; //} //var itr = resources_manifest.Data.AssetBundles.GetEnumerator(); //while (itr.MoveNext()) //{ // if (itr.Current.Value.IsNative) // { // string assetbundlename = itr.Current.Value.AssetBundleName; // string dest = DownLoadCommon.GetFileFullName(assetbundlename); // //保证路径存在 // string directory = Path.GetDirectoryName(dest); // if (!Directory.Exists(directory)) // Directory.CreateDirectory(directory); // //拷贝数据 // yield return DownLoadCommon.StartCopyInitialFile(assetbundlename); // } //} //itr.Dispose(); }