private async void DownloadResListAsync() { BeginHandle?.Invoke(this); while (true) { if (mBeDownloadResKey.Count == 0) { break; } uint tmpKey = mBeDownloadResKey.Dequeue(); long tmpResFlag = 0; if (!mResInfoDict.TryGetValue(tmpKey, out tmpResFlag)) { Logger.LogError(""); break; } var tmpResInfo = ResourcesSystem.ResFlag2Info(tmpResFlag); while (true) { try { using (UnityWebRequestAsync webReqAsync = Game.ObjectPool.Fetch <UnityWebRequestAsync>()) { WebRequestAsync = webReqAsync; string tmpUrl = URL + tmpResInfo.FileHashStr; bool tmpResult = await webReqAsync.DownloadAsync(tmpUrl); if (tmpResult) { Save(webReqAsync.Request.downloadHandler.data, tmpResInfo.FileHashStr); } else { Failed(); } } } catch (Exception e) { Logger.LogError($"download res error! {tmpResInfo.FileHashStr} -> {e}"); continue; } break; } mDownloadedSize += tmpResInfo.ResSize; DownloadProgressHandle?.Invoke(this); WebRequestAsync = null; tmpResInfo.Dispose(); } Finish(); }
public static byte[] LoadBytesFile(string fileName, PathHelper.EBytesFileType fileType = PathHelper.EBytesFileType.Table) { byte[] tmpData = null; string tmpFileFoldName = PathHelper.GetBytesFileFoldNameByType(fileType); fileName = $"{tmpFileFoldName}/{fileName}"; if (GameSetup.instance.IsPublish) { var tmpResInfo = ResourcesSystem.FindResInfo(fileName); switch (tmpResInfo.ResPos) { case ResourcesSystem.EResPos.Resource: { TextAsset tmpTextAsset = Resources.Load <TextAsset>(tmpResInfo.FileHashStr); if (null != tmpTextAsset) { tmpData = tmpTextAsset.bytes; } else { Logger.LogError($"加载bytes文件 {tmpResInfo.FileHashStr} 失败."); } break; } case ResourcesSystem.EResPos.Persistent: { tmpData = ReadFile($"{PathHelper.AppHotfixResPath}/{tmpResInfo.FileHashStr}"); break; } default: { Logger.LogError("资源定位错误. bytes文件不可能出现在StreamAsset位置."); break; } } tmpResInfo.Dispose(); } else { tmpData = ReadFile($"{PathHelper.RUN_TIME_RES_PATH}/{fileName}"); } return(tmpData); }
//bundle文件资源路径 public static string BundleName2ResPath(string bundleName) { string tmpResPath = AppHotfixResPath; if (GameSetup.instance.IsPublish) { var tmpResInfo = ResourcesSystem.FindResInfo(bundleName); switch (tmpResInfo.ResPos) { case ResourcesSystem.EResPos.StreamAsset: { tmpResPath = $"{AppStreamAssetsPath}/{tmpResInfo.FileHashStr}"; break; } case ResourcesSystem.EResPos.Persistent: { tmpResPath = $"{AppHotfixResPath}/{tmpResInfo.FileHashStr}"; break; } default: { Logger.LogError($"资源定位错误. assetBundle不可能出现在resources位置. name = {bundleName}"); break; } } tmpResInfo.Dispose(); } else { tmpResPath = $"{smNoPublicAssetBundlePath}/{bundleName}"; } return(tmpResPath); }
protected override void LoadDescribe(byte[] data, EPosType ePosType) { base.LoadDescribe(data, ePosType); Dictionary <uint, long> tmpNewestDescDict = ResourcesSystem.LoadResDescInfo(data); mResInfoDict = tmpNewestDescDict; //包内资源 不需要作比对 if (EPosType.ApkInner == ePosType) { Finish(); return; } TextAsset tmpTextAsset = Resources.Load <TextAsset>(ApkVersionData.ResDescCrc.ToString()); if (null == tmpTextAsset) { Logger.LogError($"包内找不到资源描述文件 {ApkVersionData.ResDescCrc}"); Failed(); return; } Dictionary <uint, long> tmpApkResDescDict = ResourcesSystem.LoadResDescInfo(tmpTextAsset.bytes); List <uint> tmpInLocalResKeyList = new List <uint>(); var tmpIter = tmpNewestDescDict.GetEnumerator(); while (tmpIter.MoveNext()) { var tmpKV = tmpIter.Current; var tmpResInfo = ResourcesSystem.ResFlag2Info(tmpKV.Value); long tmpApkResFlag = 0; //此资源在初始包资源里 if (tmpApkResDescDict.TryGetValue(tmpKV.Key, out tmpApkResFlag)) { //此资源hash值未变动/资源未变更 if (tmpResInfo.FileHash == (uint)tmpApkResFlag) { continue; } } //更改此资源位置描述 ->本地 tmpInLocalResKeyList.Add(tmpKV.Key); //如此资源不存在于本地 需从资源服下载 if (!File.Exists($"{LocalPath}/{tmpResInfo.FileHash}")) { mBeDownloadResKey.Enqueue(tmpKV.Key); TotalSize += tmpResInfo.ResSize; } tmpResInfo.Dispose(); } //更改资源位置描述 -> 本地 for (int i = 0, max = tmpInLocalResKeyList.Count; i < max; ++i) { uint tmpKey = tmpInLocalResKeyList[i]; long tmpResFlag = tmpNewestDescDict[tmpKey]; var tmpResInfo = ResourcesSystem.ResFlag2Info(tmpResFlag); tmpResInfo.ResPos = ResourcesSystem.EResPos.Persistent; tmpNewestDescDict[tmpKey] = ResourcesSystem.ResInfo2Flag(tmpResInfo); tmpResInfo.Dispose(); } if (TotalSize > 1) { CheckFinishHandle?.Invoke(this); } else { Finish(); } }