/// <summary> /// 开始下载 /// </summary> public bool Start(string root , List <string> assetbundles , ResourcesManifest resources_manifest) { Abort(); if (resources_manifest == null) { Error(emErrorCode.ParameterError); return(false); } if (assetbundles == null || assetbundles.Count == 0) { IsDone = true; return(true); } IsDone = false; ErrorCode = emErrorCode.None; Root = root; resources_manifest_ = resources_manifest; UncompleteDownloadList = assetbundles; CompleteDownloadList.Clear(); FailedDownloadList.Clear(); //统计下载数据 TotalSize = 0; CompletedSize = 0; for (int i = 0; i < UncompleteDownloadList.Count; ++i) { var ab = resources_manifest_.Find(UncompleteDownloadList[i]); if (ab != null) { if (ab.IsCompress) { TotalSize += ab.CompressSize; } else { TotalSize += ab.Size; } } } //开始下载 for (int i = 0; i < System.Net.ServicePointManager.DefaultConnectionLimit; ++i) { HttpAsyDownload d = new HttpAsyDownload(URL); downloads_.Add(d); var assetbundlename = GetImcomplete(); if (!string.IsNullOrEmpty(assetbundlename)) { Download(downloads_[i], assetbundlename); } } return(true); }
/// <summary> /// 下载完成 /// </summary> void DownloadSucceed(string file_name) { lock (lock_obj_) { bool is_compress = Compress.IsCompressFile(file_name); string assetbundlename = is_compress ? Compress.GetDefaultFileName(file_name) : file_name; CompleteDownloadList.Add(assetbundlename); DownloadingList.Remove(assetbundlename); //判断是否需要解压文件 if (is_compress) { // 解压文件 string in_file = Root + "/" + file_name; string out_file = Root + "/" + assetbundlename; Compress.DecompressFile(in_file, out_file); // 删除压缩包 System.IO.File.Delete(in_file); } } }