// 开始一个下载任务 private void StartTask(DownloadInfo taskinfo) { if (this.m_DownloadingTasks.ContainsKey(taskinfo.fileName)) { DebugUtil.Log("task already in progress :{0}", taskinfo.fileName); } else { DownloadingTask value = new DownloadingTask(taskinfo); this.m_DownloadingTasks[taskinfo.fileName] = value; if (!File.Exists(taskinfo.tempPath)) { FilePathTools.CreateFolderByFilePath(taskinfo.tempPath); File.Create(taskinfo.tempPath).Dispose(); } using (var sw = new FileStream(taskinfo.tempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { taskinfo.downloadedSize = (int)sw.Length; } HttpDownload(value); } }
/// <summary> /// 获得可以使用的图集路径 /// 高清图集如果不存在,就自动加载低清的 /// 保底是低清必须存在 /// </summary> /// <returns></returns> private string GetExistingSpriteAtlasPath(string atlasName) { AtlasPathNode atlasPathNode = AtlasConfigController.Instance.GetAtlasPath(atlasName); if (atlasPathNode == null) { DebugUtil.LogError("SpriteAtlas Path Error:" + atlasName); return(null); } if (!AssetConfigController.Instance.UseAssetBundle)// 不使用ab的情况下,恒定使用hd图集 { return(atlasPathNode.HdPath); } if (!IsSdVariant)// 要求使用高清 { string abPath = string.Format("{0}.ab", atlasPathNode.HdPath.Substring(0, atlasPathNode.HdPath.Length - atlasName.Length - 1).ToLower()); if (FilePathTools.IsFileExists(abPath))// 高清图集存在 { return(atlasPathNode.HdPath); } } return(atlasPathNode.SdPath);// 返回低清图集 }
// 下载运营活动/礼包的资源 public DownloadInfo DownloadInSeconds(string directoryName, string fileNameWithMd5, ActivityResType resType, Action <DownloadInfo> onComplete) { fileNameWithMd5 = FilePathTools.NormalizePath(fileNameWithMd5); DownloadInfo info = new DownloadInfo(directoryName, fileNameWithMd5, resType, onComplete); pendingDownloads.Enqueue(info); return(info); }
// 添加一个下载任务 public DownloadInfo DownloadInSeconds(string filename, string md5, Action <DownloadInfo> onComplete) { filename = FilePathTools.NormalizePath(filename); DownloadInfo info = new DownloadInfo(filename, md5, onComplete); pendingDownloads.Enqueue(info); return(info); }
public DownloadInfo DownloadInSeconds(string directoryName, string filename, string md5, Action <DownloadInfo> onComplete, Action <int, int> onProgressChange = null) { filename = FilePathTools.NormalizePath(filename); DownloadInfo info = new DownloadInfo(directoryName, filename, md5, onComplete, onProgressChange); pendingDownloads.Enqueue(info); return(info); }
protected virtual IEnumerator LoadFromCachedFile() { if (state != LoadState.State_Error) { string bundleFilePath = FilePathTools.GetBundleLoadPath(assetBundleInfo.AssetBundleName); AssetBundleCreateRequest req = AssetBundle.LoadFromFileAsync(bundleFilePath); yield return(req); _bundle = req.assetBundle; this.Complete(); } }
public AssetBundleAsyncLoader LoadAssetBundleAsync(string path, AssetBundleAsyncLoader.LoaderCompleteHandler handler = null) { string normalizepath = FilePathTools.NormalizePath(path.ToLower()); AssetBundleAsyncLoader loader = this.CreateLoader(normalizepath); loader.onComplete += handler; if (!_isCurrentLoading) { _isCurrentLoading = true; //Application.backgroundLoadingPriority = ThreadPriority.High; } _nonCompleteLoaderSet.Add(loader); return(loader); }
public void Modify(AssetConfigController assetConfigController) { HashSet <string> activityResSet = new HashSet <string>(assetConfigController.ActivityResPaths); string root = "Assets/Export/"; for (int i = 0; i < Groups.Length; i++) { BundleGroup group = Groups[i]; var newGroup = new BundleGroup(); newGroup.GroupName = group.GroupName; newGroup.Version = group.Version; newGroup.GroupIndex = group.GroupIndex; newGroup.Paths = new List <BundleState>(); newGroup.UpdateWholeAB = group.UpdateWholeAB; var dict = new Dictionary <string, BundleState>(); var datas = new List <BundleState>(group.Paths); datas.Sort((a, b) => Convert.ToInt32(a.InInitialPacket) - Convert.ToInt32(b.InInitialPacket)); foreach (var data in datas) { string dir = Path.GetDirectoryName(data.Path); string name = Path.GetFileName(data.Path); string[] subDirs = FilePathTools.GetDirectories(root + dir, "^" + name + "$"); foreach (string subDir in subDirs) { string path = subDir.Replace(root, ""); if (activityResSet.Contains(path) || FilePathTools.GetFiles(subDir, "^(?!\\.)").Length == 0) { continue; } BundleState bundleState = new BundleState { Path = path, InInitialPacket = data.InInitialPacket }; dict[bundleState.Path] = bundleState; } } newGroup.Paths.AddRange(dict.Values); newGroup.Paths.Sort((a, b) => string.Compare(a.Path, b.Path)); if (i < assetConfigController.Groups.Length) { assetConfigController.Groups[i] = newGroup; } } }
public static void CheckPatchDiff() { string path1 = ""; string path2 = ""; string[] allPatch1 = FilePathTools.GetFiles(path1, @"(.*)(\.patch)$", SearchOption.AllDirectories); string[] allPatch2 = FilePathTools.GetFiles(path2, @"(.*)(\.patch)$", SearchOption.AllDirectories); foreach (var p1 in allPatch1) { JObject jobj1 = JObject.Parse(File.ReadAllText(p1)); string hash1 = jobj1["hash"].ToString(); int index = allPatch2.IndexOfEx((x) => x.Substring(path2.Length).Equals(p1.Substring(path1.Length))); if (index >= 0) { JObject jobj2 = JObject.Parse(File.ReadAllText(allPatch2[index])); string hash2 = jobj2["hash"].ToString(); if (!hash1.Equals(hash2)) { Debug.Log(string.Format("dif : {0}", p1)); } } else { Debug.Log(string.Format("only 1 : {0}", p1)); } } foreach (var p1 in allPatch2) { JObject jobj1 = JObject.Parse(File.ReadAllText(p1)); string hash1 = jobj1["hash"].ToString(); int index = allPatch1.IndexOfEx((x) => x.Substring(path1.Length).Equals(p1.Substring(path2.Length))); if (index >= 0) { JObject jobj2 = JObject.Parse(File.ReadAllText(allPatch1[index])); string hash2 = jobj2["hash"].ToString(); if (!hash1.Equals(hash2)) { Debug.Log(string.Format("dif : {0}", p1)); } } else { Debug.Log(string.Format("only 2 : {0}", p1)); } } Debug.Log("finish"); }
private T SubLoadResource <T>(string path, bool forceBundle = false, bool addToCache = true) where T : Object { if (!AssetConfigController.Instance.UseAssetBundle && !forceBundle) //使用编辑器里资源 { #if UNITY_EDITOR path = FilePathTools.GetAssetEditorPath(path); Object Obj = UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(T)); if (Obj == null) { //DebugUtil.LogError("Asset not found at path:" + path); return(null); } return((T)Obj); #endif } // 记录本次加载到内存的所有ab包 List <string> loadedBundles = new List <string>(); // 加载目标资源 Object obj = null; string bundlePath = Path.GetDirectoryName(path) + ".ab"; AssetBundle targetAB = LoadBundle(bundlePath, ref loadedBundles); if (targetAB == null) { DebugUtil.LogError("Asset not found at path:" + path); return(null); } string tempFileName = Path.GetFileName(path); obj = targetAB.LoadAsset <T>(tempFileName); if (addToCache) { AddCache(path, obj); } // 释放加载到内存的ab if (!alwaysCache) { StartCoroutine(UnloadAssetbundle(loadedBundles)); } return((T)obj); }
static void DownloadCommonInitialAB(BaseResFakeInfo rrInfo) { string fileUrl = rrInfo.GetDownLoadUrlForInitial(); string savePath = FilePathTools.streamingAssetsPath_Platform + "/" + rrInfo.LocalABPath.ToLower(); CommonResLog("qushuang -----> Start DownloadHomeInitialAB {0}", fileUrl); if (File.Exists(savePath)) { File.Delete(savePath); } FilePathTools.CreateFolderByFilePath(savePath); try { Stream outStream; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fileUrl); WebResponse response = request.GetResponse(); Stream inStream = response.GetResponseStream(); //获取http byte[] b = new byte[1024 * 1024]; //每一次获取的长度 FileInfo fi = new FileInfo(savePath); outStream = fi.Create(); //创建文件 int num = 0; int readCount = inStream.Read(b, 0, b.Length); //读流 num += readCount; while (readCount > 0) { outStream.Write(b, 0, readCount); //写流 readCount = inStream.Read(b, 0, b.Length); //再读流 num += readCount; } outStream.Close(); inStream.Close(); response.Close(); CommonResLog("qushuang -----> Download successfully! {0}, total size is {1}", fileUrl, num); } catch (Exception ex) { CommonResLog("qushuang -----> An error occured while downloading {0} due to {1}. try again!", fileUrl, ex); DownloadCommonInitialAB(rrInfo); return; } }
public void ReleaseRes(string path, bool free = false) { var norm_path = FilePathTools.NormalizePath(path); if (dicCacheObject.TryGetValue(norm_path, out CacheObject oc)) { dicCacheObject.Remove(norm_path); if (free) { if (oc.obj is Sprite) { var sp = oc.obj as Sprite; Resources.UnloadAsset(sp.texture); } else { Resources.UnloadAsset(oc.obj); } } } string bundlePath = Path.GetDirectoryName(path) + ".ab"; AssetBundleCache.Unload(bundlePath); }
//path 一定要是bundle的path private AssetBundle LoadBundle(string path, ref List <string> bundles, int stackSizeForCheck = 0) { if (stackSizeForCheck > MAX_DEPENDENCY_DEEP) { DebugUtil.LogError($"{GetType()}.LoadBundle, path = {path}, dependency stack reach max count({MAX_DEPENDENCY_DEEP}, check if its a bad bundle strategy or a dead code cycle!)"); return(null); } string abKey = path; AssetBundle targetAb; targetAb = AssetBundleCache.GetAssetBundle(abKey); AssetBundleInfo abInfo = VersionManager.Instance.GetAssetBundleInfo(abKey); string[] dependencies = abInfo.DependenciesBundleNames; // 加载自己 if (targetAb == null) { string bundleFilePath = FilePathTools.GetBundleLoadPath(abKey); if (File.Exists(bundleFilePath)) { targetAb = AssetBundle.LoadFromFile(bundleFilePath); } if (targetAb != null) { bundles.Add(abKey); // if (HomeRoomConfigController.Instance != null) // { // var info = HomeRoomConfigController.Instance.GetRoomResInfoByABPath(abKey); // if (info != null) // { // //homeroom 公共库的ab包名字是带versioncode的,需要去掉 // targetAb.name = abKey; // } // } // if (CookingGameConfigController.Instance != null) // { // var info = CookingGameConfigController.Instance.GetRoomResInfoByABPath(abKey); // if (info != null) // { // //cookinggame 公共库的ab包名字是带versioncode的,需要去掉 // targetAb.name = abKey; // } // } // if (ColorResConfigController.Instance != null) // { // var info = ColorResConfigController.Instance.GetRoomResInfoByABPath(abKey); // if (info != null) // { // //colorRes公共库的ab包名字是带versioncode的,需要去掉 // targetAb.name = abKey; // } // } AssetBundleCache.AddAssetBundle(targetAb, abInfo); } else { return(null); } } // 加载依赖包 if (dependencies != null && dependencies.Length > 0) { ++stackSizeForCheck; foreach (string fileName in dependencies) { if (!bundles.Contains(fileName)) { LoadBundle(fileName, ref bundles, stackSizeForCheck); } } } return(targetAb); }
public T LoadResource <T>(string name, bool forceBundle = false, bool addToCache = true) where T : Object { #if DEVELOPMENT_BUILD || UNITY_EDITOR stopWatch.Restart(); #endif try { List <string> path = new List <string>(); if (AssetConfigController.Instance.UseAssetBundle || forceBundle) { string normalizepath = FilePathTools.NormalizePath(name.ToLower()); CacheObject co; T outValue; if (dicCacheObject.TryGetValue(normalizepath, out co) && co != null && co.obj != null && TryGetCoValue <T>(co, out outValue) && outValue != null) { return(outValue); } else { if (!alwaysCache) { TryClearCache(); } object obj = SubLoadResource <T>(normalizepath, forceBundle, addToCache); if (obj != null) { return(obj as T); } } } else { if (typeof(T) == typeof(Sprite)) { path.Add(name + ".png"); path.Add(name + ".jpg"); path.Add(name + ".tga"); } else if (typeof(T) == typeof(Texture2D)) { path.Add(name + ".png"); path.Add(name + ".jpg"); } else if (typeof(T) == typeof(GameObject)) { path.Add(name + ".prefab"); } else if (typeof(T) == typeof(AudioClip)) { path.Add(name + ".mp3"); path.Add(name + ".wav"); } else if (typeof(T) == typeof(Material)) { path.Add(name + ".mat"); } else if (typeof(T) == typeof(TextAsset)) { path.Add(name + ".txt"); path.Add(name + ".json"); path.Add(name + ".xml"); path.Add(name + ".bytes"); } else if (typeof(T) == typeof(SpriteAtlas)) { path.Add(name + ".spriteatlas"); } else if (typeof(T) == typeof(TMPro.TMP_FontAsset)) { path.Add(name + ".asset"); } else if (typeof(T) == typeof(Material)) { path.Add(name + ".mat"); } else if (typeof(T) == typeof(RuntimeAnimatorController)) { path.Add(name + ".controller"); } #if CK_CLIENT else if (typeof(T) == typeof(Spine.Unity.SkeletonDataAsset)) { path.Add(name + ".asset"); } #endif foreach (string itempath in path) { string normalizepath = FilePathTools.NormalizePath(itempath); object obj = SubLoadResource <T>(normalizepath, false, addToCache); if (obj != null) { return(obj as T); } } } } catch (Exception e) { DebugUtil.LogError(e); } #if DEVELOPMENT_BUILD || UNITY_EDITOR finally { stopWatch.Stop(); long time_delta = stopWatch.ElapsedMilliseconds; loadTimes += time_delta; loadTimeMarks.Add(new LoadTimeMark(name, time_delta)); } #endif return(null); }
static void DownloadCommonInitialABWithHttpRequest(BaseResFakeInfo rrInfo) { string fileUrl = rrInfo.GetDownLoadUrl(); string savePath = FilePathTools.streamingAssetsPath_Platform + "/" + rrInfo.LocalABPath.ToLower(); CommonResLog("qushuang -----> Start DownloadHomeInitialAB {0}", fileUrl); if (File.Exists(savePath)) { File.Delete(savePath); } FilePathTools.CreateFolderByFilePath(savePath); new HTTPRequest(new Uri(fileUrl), HTTPMethods.Get, (req, rep) => { if (rep == null) { CommonResLog("qushuang -----> Response null. try again! {0}", fileUrl); DownloadCommonInitialABWithHttpRequest(rrInfo); } else if (rep.StatusCode >= 200 && rep.StatusCode < 300) { string localfile = savePath; try { List <byte[]> streamedFragments = rep.GetStreamedFragments(); if (streamedFragments != null) { int num = 0; using (FileStream fileStream = new FileStream(localfile, FileMode.Append)) { foreach (byte[] array in streamedFragments) { num += array.Length; fileStream.Write(array, 0, array.Length); } } CommonResLog("qushuang -----> Download successfully! {0}, total size is {1}", fileUrl, num); } else { CommonResLog("qushuang -----> No streamedFragments! try again! {0}", localfile); DownloadCommonInitialABWithHttpRequest(rrInfo); } } catch (Exception ex) { CommonResLog("qushuang -----> An error occured while downloading {0} due to {1}. try again!", localfile, ex); DownloadCommonInitialABWithHttpRequest(rrInfo); return; } } else { CommonResLog("qushuang -----> Unexpected response from server: {0}, StatusCode = {1}, try again!", fileUrl, rep.StatusCode); DownloadCommonInitialABWithHttpRequest(rrInfo); } }) { DisableCache = true, IsCookiesEnabled = false, UseStreaming = true, StreamFragmentSize = 1 * 1024 * 1024 * 100, // 1k 1Mb 100Mb ConnectTimeout = TimeSpan.FromSeconds(5), Timeout = TimeSpan.FromSeconds(10) }.Send(); }
/// <summary> /// 通过组名,ab包名,获得需要下载的ab包 /// </summary> /// <returns>The update files dict.[name,md5]</returns> /// <param name="groupName">Group name.</param> /// <param name="assetbundleName">Assetbundle name.</param> public Dictionary <string, string> GetUpdateFilesDict(string groupName, string assetbundleName = null) { Dictionary <string, string> updateFileNames = new Dictionary <string, string>(); if (localVersionFile == null || remoteVersionFile == null) { DebugUtil.LogError("Version文件出错"); return(updateFileNames); } VersionItemInfo item = null; if (localVersionFile.ResGroups.ContainsKey(groupName)) { item = localVersionFile.ResGroups[groupName]; if (item.UpdateWholeGroup)//强制更新整个组里的ab包 { List <string> remoteAB = remoteVersionFile.GetAssetBundlesByKey(groupName); List <string> localAB = localVersionFile.GetAssetBundlesByKey(groupName); Dictionary <string, string> localFilesHash = new Dictionary <string, string>(); foreach (string assetname in localAB) { localFilesHash.Add(assetname, localVersionFile.GetAssetBundleHash(groupName, assetname)); } foreach (string assetname in remoteAB) { string remoteHash = remoteVersionFile.GetAssetBundleHash(groupName, assetname); string remoteMd5 = remoteVersionFile.GetAssetBundleMd5(groupName, assetname); string localPath = FilePathTools.GetBundleLoadPath(assetname); if (localFilesHash.ContainsKey(assetname)) { //添加“remoteState == AssetState.ExistInDownLoad”在于兼容ProtectMode if (!File.Exists(localPath) || remoteHash.Trim() != localFilesHash[assetname].Trim()) { updateFileNames.Add(assetname, remoteMd5); } } else { updateFileNames.Add(assetname, remoteMd5); } } } else { if (!string.IsNullOrEmpty(assetbundleName)) { string remoteName = remoteVersionFile.GetAssetBundleByKeyAndName(groupName, assetbundleName); string localName = localVersionFile.GetAssetBundleByKeyAndName(groupName, assetbundleName); string remoateHash = remoteVersionFile.GetAssetBundleHash(groupName, remoteName); string remoateMd5 = remoteVersionFile.GetAssetBundleMd5(groupName, remoteName); if (string.IsNullOrEmpty(localName)) //本地没有 { if (!string.IsNullOrEmpty(remoteName)) //远端有 { updateFileNames.Add(remoteName, remoateMd5); //远端有,本地没有 } } else { if (!string.IsNullOrEmpty(remoteName))//本地有,远端有 { // 比较两者的hash string localHash = localVersionFile.GetAssetBundleHash(groupName, localName); string localPath = FilePathTools.GetBundleLoadPath(localName); if (!File.Exists(localPath) || localHash.Trim() != remoateHash.Trim())//hash不一样,要更新 { updateFileNames.Add(remoteName, remoateMd5); } } } } } } else {// 本地version文件不包含这个组,目前只发生在editor模式下,修复下。将来不一定。 if (remoteVersionFile.ResGroups.ContainsKey(groupName)) { item = remoteVersionFile.ResGroups[groupName]; if (item.UpdateWholeGroup) { List <string> remoteAB = remoteVersionFile.GetAssetBundlesByKey(groupName); foreach (string assetname in remoteAB) { string remoteMd5 = remoteVersionFile.GetAssetBundleMd5(groupName, assetname); updateFileNames.Add(assetname, remoteMd5); } } else { string remoteName = remoteVersionFile.GetAssetBundleByKeyAndName(groupName, assetbundleName); string remoteMd5 = remoteVersionFile.GetAssetBundleMd5(groupName, remoteName); if (!string.IsNullOrEmpty(remoteName))//远端有 { updateFileNames.Add(remoteName, remoteMd5); } } } else { DebugUtil.LogError("远端和本地的version文件都不包含:" + groupName); } } return(updateFileNames); }
public void LoadResourceAsync <T>(string name, Action <T> OnFinished = null) where T : Object { List <string> path = new List <string>(); if (AssetConfigController.Instance.UseAssetBundle) { string normalizepath = FilePathTools.NormalizePath(name.ToLower()); CacheObject co; if (dicCacheObject.TryGetValue(normalizepath, out co) && co.obj != null) { OnFinished?.Invoke(co.obj as T); } else { if (!alwaysCache) { TryClearCache(); } string bundlePath = Path.GetDirectoryName(normalizepath) + ".ab"; string assetName = Path.GetFileName(normalizepath); AssetBundle targetAb; targetAb = AssetBundleCache.GetAssetBundle(bundlePath); if (targetAb != null) { StartCoroutine(LoadFromAssetBundle <T>(targetAb, assetName, (obj) => { AddCache(normalizepath, obj); OnFinished?.Invoke(obj); })); } else { LoadAssetBundleAsync(bundlePath, (loader) => { if (loader.IsComplete) { StartCoroutine(LoadFromAssetBundle <T>(loader.AssetBundle, assetName, (obj) => { AddCache(normalizepath, obj); OnFinished?.Invoke(obj); })); } }); } } } else { if (typeof(T) == typeof(Sprite)) { path.Add(name + ".png"); path.Add(name + ".jpg"); path.Add(name + ".tga"); } else if (typeof(T) == typeof(Texture2D)) { path.Add(name + ".png"); path.Add(name + ".jpg"); } else if (typeof(T) == typeof(GameObject)) { path.Add(name + ".prefab"); } else if (typeof(T) == typeof(AudioClip)) { path.Add(name + ".mp3"); path.Add(name + ".wav"); } else if (typeof(T) == typeof(Material)) { path.Add(name + ".mat"); } else if (typeof(T) == typeof(TextAsset)) { path.Add(name + ".txt"); path.Add(name + ".json"); path.Add(name + ".xml"); path.Add(name + ".bytes"); } else if (typeof(T) == typeof(SpriteAtlas)) { path.Add(name + ".spriteatlas"); } else if (typeof(T) == typeof(TMPro.TMP_FontAsset)) { path.Add(name + ".asset"); } else if (typeof(T) == typeof(Material)) { path.Add(name + ".mat"); } else if (typeof(T) == typeof(RuntimeAnimatorController)) { path.Add(name + ".controller"); } foreach (string itempath in path) { string normalizepath = FilePathTools.NormalizePath(itempath); object obj = SubLoadResource <T>(normalizepath); if (obj != null) { OnFinished?.Invoke(obj as T); break; } } } }
static void DownloadCommonInitialABWithBreakDownloader(BaseResFakeInfo rrInfo) { DownloadInfo taskinfo = new DownloadInfo(rrInfo.LocalABPath, rrInfo.GetPlatformMd5(), null); taskinfo.savePath = FilePathTools.streamingAssetsPath_Platform + "/" + rrInfo.LocalABPath.ToLower(); if (File.Exists(taskinfo.savePath)) { File.Delete(taskinfo.savePath); } FilePathTools.CreateFolderByFilePath(taskinfo.savePath); if (!File.Exists(taskinfo.tempPath)) { FilePathTools.CreateFolderByFilePath(taskinfo.tempPath); File.Create(taskinfo.tempPath).Dispose(); } using (var sw = new FileStream(taskinfo.tempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { taskinfo.downloadedSize = (int)sw.Length; } DownloadingTask tmpTask = new DownloadingTask(taskinfo); HTTPRequest httprequest = new HTTPRequest(new Uri(tmpTask.DownloadInfo.url), HTTPMethods.Head, (req, rep) => { tmpTask.HeadRequest = null; if (rep == null) { CommonResLog("Download failed due to network for :{0}", tmpTask.DownloadInfo.fileName); tmpTask.DownloadInfo.result = DownloadResult.ServerUnreachable; DownloadCommonInitialABWithBreakDownloader(rrInfo); } else if (rep.StatusCode == 200) { try { string firstHeaderValue = rep.GetFirstHeaderValue("Content-Length"); tmpTask.DownloadInfo.downloadSize = int.Parse(firstHeaderValue); CommonResLog("Will download {0} bytes for '{1}'", tmpTask.DownloadInfo.downloadSize, tmpTask.DownloadInfo.fileName); BreakPointDownloader downloader = new BreakPointDownloader(tmpTask.DownloadInfo, new Dictionary <string, DownloadingTask>()); tmpTask.Downloader = downloader; downloader.StartDownload(); } catch (Exception ex) { CommonResLog("An error occured during download '{0}' due to {1}", tmpTask.DownloadInfo.fileName, ex); tmpTask.DownloadInfo.result = DownloadResult.Failed; DownloadCommonInitialABWithBreakDownloader(rrInfo); } } else { CommonResLog("Response is not ok! for: {0}", tmpTask.DownloadInfo.url); tmpTask.DownloadInfo.result = DownloadResult.Failed; DownloadCommonInitialABWithBreakDownloader(rrInfo); } }) { DisableCache = true }; httprequest.Send(); }
IEnumerator CheckAsset(List <string> bundleNames) { Log(string.Format("load bundle progress:{00:F1}%", 0.0f), false); List <AssetBundle> allBundles = new List <AssetBundle>(); for (int m = 0; m < bundleNames.Count; ++m) { AssetBundle bundle = AssetBundle.LoadFromFile(FilePathTools.GetBundleLoadPath(bundleNames[m])); if (null == bundle) { Fail(string.Format("can not load bundle file : {0}", bundleNames[m])); } allBundles.Add(bundle); Log(string.Format("load bundle progress:{00:F1}%", (m + 1) / (bundleNames.Count * 1.0f) * 100.0f), true); yield return(null); } Log(string.Format("load bundle progress:{00:F1}%", 100.0f), true); Log(string.Format("Object progress:{00:F1}% ", 0.0f), false); for (int m = 0; m < allBundles.Count; ++m) { UnityEngine.Object[] objs = allBundles[m].LoadAllAssets(); foreach (var obj in objs) { if (obj == null) { Fail(string.Format("null in bundle load : {0}", bundleNames[m])); } if (obj.GetType() == typeof(GameObject)) { GameObject prefab = obj as GameObject; if (null == prefab) { Fail(string.Format("{0} convert Prefab fail in bundle :{1}", obj.name, bundleNames[m])); } Component[] comps = prefab.GetComponentsInChildren <Component>(true); foreach (var com in comps) { if (null == com) { Fail(string.Format("{0} prefab exist null component in bundle :{1}", obj.name, bundleNames[m])); } } GameObject instance = Instantiate(prefab); if (null == instance) { Fail(string.Format("{0} instance is null inbundle :{1}", obj.name, bundleNames[m])); } comps = instance.GetComponentsInChildren <Component>(true); foreach (var com in comps) { if (null == com) { Fail(string.Format("{0} instance exist null component in bundle :{1}", obj.name, bundleNames[m])); } } Destroy(instance); } } Log(string.Format("Object progress:{00:F1}% ", (m + 1) / (allBundles.Count * 1.0f) * 100.0f), true); yield return(null); } Log(string.Format("Object progress:{00:F1}% ", 100.0f), true); Log(string.Format("unload bundle progress:{00:F1}%", 0.0f), false); for (int m = 0; m < allBundles.Count; ++m) { allBundles[m].Unload(false); Log(string.Format("unload bundle progress:{00:F1}%", (m + 1) / (allBundles.Count * 1.0f) * 100.0f), true); yield return(null); } Log(string.Format("unload bundle progress:{00:F1}%", 100.0f), true); yield return(null); }