/// <summary> /// 存储热更资源并记录热更资源信息 /// </summary> /// <param name="resname">资源名</param> /// <param name="resversion">资源版本号</param> /// <param name="data">资源二进制数据</param> private void saveHotResourceUpdate(string resname, int resversion, byte[] data) { //检查包外是否存在同名资源,存在的话需要先删除再存储最新到包外 var resfullpath = AssetBundlePath.ABHotUpdatePath + resname; if (AssetBundlePath.IsABExitInOutterPath(resname)) { Debug.Log(string.Format("删除包外资源 : {0}", resname)); File.Delete(resfullpath); } File.WriteAllBytes(resfullpath, data); if (!File.Exists(LocalResourceUpdateListFilePath)) { Debug.Log(string.Format("创建文件 : {0}", LocalResourceUpdateListFilePath)); using (var fs = File.Create(LocalResourceUpdateListFilePath)) { fs.Close(); } } using (var sw = File.AppendText(LocalResourceUpdateListFilePath)) { sw.WriteLine(resversion + ":" + resname); sw.Close(); } Debug.Log(string.Format("写入已更资源 : {0}", resfullpath)); }
/// <summary> /// 异步加载AssetBundle /// </summary> private IEnumerator AsyncLoad(AssetFile asset, Action <AssetFile> Actionfile) { if (manifestBundle == null) { Debug.LogError("manifest is null wait!"); yield return(null); } string filepath = AssetBundlePath.GetAssetBundlePath(asset.Name); AssetBundleCreateRequest req = AssetBundle.LoadFromFileAsync(filepath); while (!req.isDone) { asset.LoadProgress = req.progress * 100; yield return(null); } /// yield return asset.LoadAssetFileAsync(filepath); asset.LoadProgress = 100; asset.assetbundle = req.assetBundle; if (Actionfile != null) { while (asset.IsReadyAll) { yield return(null); } Actionfile(asset); } yield return(null); }
// 所有文件 static void AssetBundleSetFolderAll(AssetBundlePath abPath) { string path = abPath.path; DirectoryInfo raw = new DirectoryInfo(path); // 拿所有文件 FileInfo[] files = raw.GetFiles("*", SearchOption.AllDirectories); foreach (FileInfo file in files) { // 文件跳过 if (file.Directory.Name == ".svn" || file.Directory.Parent.Name == ".svn" || file.Directory.Parent.Parent.Name == ".svn" || file.Extension == ".meta" || file.Extension == ".cs" || file.Extension == ".js") { continue; } string name = file.Name.Replace(file.Extension, ""); path = file.FullName.Substring(file.FullName.IndexOf("Assets")).Replace("\\", "/"); AssetImporter importer = AssetImporter.GetAtPath(path); if (importer == null) { Debug.LogError("No Importer:" + path); break; } importer.assetBundleName = abPath.prefix + name.ToLower(); } }
/// <summary> /// AB加载携程 /// </summary> /// <returns></returns> private IEnumerator assetBundleLoadAsync() { while (true) { if (ABAsyncQueue.Count > 0) { CurrentLoadingAssetBundleLoader = ABAsyncQueue.Dequeue(); //检查是否已经同步加载完成 //如果异步加载AB时,同步请求来了,打断异步后续逻辑 //LoadState == ResourceLoadState.None表明同步加载该资源已经完成,无需再异步返回 if (CurrentLoadingAssetBundleLoader.LoadState == ResourceLoadState.None) { //ResourceLogger.logWar("有资源还未开始异步加载就被同步加载打断!"); } else { CurrentLoadingAssetBundleLoader.LoadState = ResourceLoadState.Loading; var abname = CurrentLoadingAssetBundleLoader.AssetBundleName; var abpath = AssetBundlePath.GetABLoadFullPath(abname); AssetBundleCreateRequest abrequest = null; #if UNITY_EDITOR //因为资源不全,很多资源丢失,导致直接报错 //这里临时先在Editor模式下判定下文件是否存在,避免AssetBundle.LoadFromFileAsync()直接报错 if (System.IO.File.Exists(abpath)) { abrequest = AssetBundle.LoadFromFileAsync(abpath); } else { Debug.LogError(string.Format("AB : {0}文件不存在!", CurrentLoadingAssetBundleLoader.AssetBundleName)); } #else abrequest = AssetBundle.LoadFromFileAsync(abpath); #endif yield return(abrequest); //如果异步加载AB时,同步请求来了,打断异步后续逻辑 //LoadState == ResourceLoadState.None表明同步加载该资源已经完成,无需再异步返回 if (CurrentLoadingAssetBundleLoader.LoadState == ResourceLoadState.None) { ResourceLogger.log(string.Format("资源 : {0}加载已完成,异步加载被打断!", abname)); } else { var assetbundle = abrequest.assetBundle; if (assetbundle == null) { ResourceLogger.logErr(string.Format("Failed to load AssetBundle : {0}!", CurrentLoadingAssetBundleLoader.AssetBundleName)); } CurrentLoadingAssetBundleLoader.onSelfABLoadComplete(assetbundle); } } CurrentLoadingAssetBundleLoader = null; } else { yield return(null); } } }
/// <summary> /// 加载AssetBundle打包信息 /// </summary> private void loadAssetBundleBuildInfo() { // 确保之前加载的AB打包信息卸载彻底 if (mAssetBundleBuildInfo != null) { Resources.UnloadAsset(mAssetBundleBuildInfo); mAssetBundleBuildInfo = null; } // AssetBundle打包信息比较特殊,在未加载完成前拿不到AB名字映射 // 所以这里单独特殊加载,不走正常流程 var abpath = AssetBundlePath.GetABLoadFullPath(ResourceConstData.AssetBundleBuildInfoAssetName); AssetBundle ab = null; ab = AssetBundle.LoadFromFile(abpath); if (ab != null) { mAssetBundleBuildInfo = ab.LoadAsset <AssetBundleBuildInfoAsset>(ResourceConstData.AssetBundleBuildInfoAssetName); mAssetBundleBuildInfo.init(); ab.Unload(false); Debug.Log("AssetBundle打包信息文件加载成功!"); } else { Debug.LogError($"找不到AssetBundle打包信息文件:{ResourceConstData.AssetBundleBuildInfoAssetName}"); } }
/// <summary> /// GUI Draw /// </summary> private async void OnGUI() { var toggleText = toggle ? "Custom Setting" : "Default Setting"; toggle = EditorGUILayout.BeginToggleGroup(toggleText, toggle); if (toggle) { targetPath = EditorGUILayout.TextField("Bundle Path", targetPath); compressingPath = EditorGUILayout.TextField("SVN Path", targetPath); } else { EditorGUILayout.TextField("Bundle Path", AssetBundlePath.BundlePath); EditorGUILayout.TextField("SVN Path", AssetBundlePath.SVNPath); } EditorGUILayout.EndToggleGroup(); if (GUILayout.Button("Compress")) { if (toggle) { AssetBundlePath.SetBundlePath(targetPath); AssetBundlePath.SetSVNPath(compressingPath); } _onCompressing = true; result = "압축중"; result = await Task.Run(AssetBundleCompressor.Instance.MakeAssetBundleZipFile); _onCompressing = false; AssetBundleCompressor.Instance.Delete(); } var style = new GUIStyle(); GUIStyleState state = new GUIStyleState(); state.background = GUI.skin.button.normal.background; state.textColor = Color.blue; style.active = GUI.skin.button.active; style.normal = state; style.alignment = TextAnchor.MiddleCenter; style.padding = new RectOffset(5, 5, 3, 3); style.margin = new RectOffset(160, 5, 5, 0); style.border = new RectOffset(5, 5, 1, 1); style.clipping = TextClipping.Clip; if (GUILayout.Button("Show in Explorer", style)) { System.Diagnostics.Process.Start(AssetBundlePath.SVNPath); } EditorGUILayout.LabelField(result ?? ""); if (_onCompressing) { EditorGUILayout.LabelField(AssetBundleCompressor.Instance.progress + "/" + AssetBundleCompressor.Instance.nOfFile); } }
//获取指定资源的ab名称 public static string GetResABName(string assetPath) { Init(); BundleType type = BundleType.Default;//默认打包策略 string validatePath = null; //自定义中,最后一个出现的一定是最终的ab名称 for (int i = ruleList.Count - 1; i >= 0; i--) { AssetBundlePath abPath = ruleList[i]; if (assetPath.StartsWith(abPath.path + "/")) { type = abPath.type; validatePath = abPath.path; break; } } //没有定制该资源的ab策略 if (validatePath == null) { Debug.LogError("<AssetBundleNameAuto> 该资源所在的位置不正确,无法获取ab包名称,路径 = " + assetPath); return(""); } switch (type) { case BundleType.FolderAll: //就直接到定制的文件夹 return(validatePath.Replace("Assets/", "").Replace("/", "_").ToLower()); case BundleType.Default: string leftPath = assetPath.Replace(validatePath + "/", ""); int index = leftPath.IndexOf("/", StringComparison.Ordinal); if (index > 0) { //还有文件夹,就命名到该文件夹 return((validatePath.Replace("Assets/", "").Replace("/", "_") + "_" + leftPath.Substring(0, index)).ToLower()); } else { //没有文件夹,就需要加上文件名称 return((validatePath.Replace("Assets/", "").Replace("/", "_") + "_" + leftPath.Split('.')[0]).ToLower()); } case BundleType.Folder: leftPath = assetPath.Replace(validatePath + "/", ""); index = leftPath.IndexOf("/", StringComparison.Ordinal); if (index > 0) { //还有文件夹,就命名到该文件夹 return((validatePath.Replace("Assets/", "").Replace("/", "_") + "_" + leftPath.Substring(0, index)).ToLower()); } else { //没有文件夹,就直接到定制的文件夹 return(validatePath.Replace("Assets/", "").Replace("/", "_").ToLower()); } } return(""); }
public static void SetAllABNames() { ReInit(); for (int i = 0; i < ruleList.Count; i++) { AssetBundlePath abPath = ruleList[i]; CustomDeal(abPath); } // 清理无用名称 AssetDatabase.RemoveUnusedAssetBundleNames(); }
public static void ClearLuaABNames() { Init(); for (int i = 0; i < ruleList.Count; i++) { AssetBundlePath abPath = ruleList[i]; if (abPath.path.Contains("/Lua")) { ClearABNames(abPath.path); } } Debug.Log("清除脚本(Lua)的AssetBundleName"); }
/// <summary> /// 同步加载AssetBundle /// </summary> private void SyncLoad(AssetFile asset) { string filepath = AssetBundlePath.GetAssetBundlePath(asset.Name); asset.assetbundle = AssetBundle.LoadFromFile(filepath); if (asset.assetbundle == null) { Debug.LogError(" path no found file " + filepath); } asset.IsReady = true; }
public static void SetResABNames() { Init(); for (int i = 0; i < ruleList.Count; i++) { AssetBundlePath abPath = ruleList[i]; if (!abPath.path.Contains("/Data") && !abPath.path.Contains("/Lua")) { CustomDeal(abPath); } } DealLocalization(); Debug.Log("设置资源(Res)的AssetBundleName"); }
//自定义的处理策略 private static void CustomDeal(AssetBundlePath abPath) { string prefix = abPath.path.Replace("Assets/", "").Replace("/", "_"); switch (abPath.type) { case BundleType.FolderAll: FolderAllPolicy(abPath.path, prefix); break; case BundleType.Default: DefaultPolicy(abPath.path, prefix); break; case BundleType.Folder: FolderPolicy(abPath.path, prefix); break; } }
// 所有目录 static void AssetBundleSetFolderFolder(AssetBundlePath abPath) { string path = abPath.path; DirectoryInfo raw = new DirectoryInfo(path); // 拿所有文件 DirectoryInfo[] directory = raw.GetDirectories(); foreach (DirectoryInfo dir in directory) { if (dir.Name == ".svn") { continue; } AssetImporter importer = AssetImporter.GetAtPath(path + "/" + dir.Name); importer.assetBundleName = abPath.prefix + dir.Name.ToLower(); AssetBundleClearName(path + "/" + dir.Name); } }
void UpdateButtons() { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Save", GUILayout.Width(200))) { AssetBundlePath assetBundleAsset = ScriptableObject.CreateInstance <AssetBundlePath>(); if (assetBundleAsset == null) { UnityEngine.Debug.LogError("create asset bundle asset failed!"); return; } assetBundleAsset.SharePaths = sharePaths; assetBundleAsset.AtlasPaths = atlasPaths; assetBundleAsset.AudioPaths = audioPaths; assetBundleAsset.UIPrefabPaths = uiPrefabPaths; assetBundleAsset.ModelAndEffectPaths = effectPaths; assetBundleAsset.SpinePaths = spinePaths; AssetDatabase.CreateAsset(assetBundleAsset, "Assets/assetbundlepath.asset"); } if (GUILayout.Button("Load", GUILayout.Width(200))) { AssetBundlePath assetBundlePath = AssetDatabase.LoadAssetAtPath <AssetBundlePath>("Assets/assetbundlepath.asset"); if (assetBundlePath != null) { sharePaths = assetBundlePath.SharePaths; atlasPaths = assetBundlePath.AtlasPaths; audioPaths = assetBundlePath.AudioPaths; uiPrefabPaths = assetBundlePath.UIPrefabPaths; effectPaths = assetBundlePath.ModelAndEffectPaths; spinePaths = assetBundlePath.SpinePaths; } Repaint(); } EditorGUILayout.EndHorizontal(); }
/// <summary> /// 同步加载AB /// </summary> /// <returns></returns> private void loadAssetBundleSync() { var abpath = AssetBundlePath.GetABLoadFullPath(AssetBundleName); AssetBundle ab = null; #if UNITY_EDITOR //因为资源不全,很多资源丢失,导致直接报错 //这里临时先在Editor模式下判定下文件是否存在,避免AssetBundle.LoadFromFile()直接报错 if (System.IO.File.Exists(abpath)) { ab = AssetBundle.LoadFromFile(abpath); } else { Debug.LogError(string.Format("AB : {0}文件不存在!", AssetBundleName)); } #else ab = AssetBundle.LoadFromFile(abpath); #endif onSelfABLoadComplete(ab); }
/// <summary> /// 热更资源列表下载完成回调 /// </summary> /// <param name="url"></param> /// <param name="requeststatus"></param> private void resourceListHotUpdateCompleteCB(string url, TWebRequest.WebRequestStatus requeststatus) { //TODO: if (mTestHotUpdateResourceList.Count > 0) { AssetBundlePath.CheckAndCreateABOutterPathFolder(); //StartCoroutine(resourcesRequest()); TWebRequest twr = new TWebRequest(); foreach (var res in mTestHotUpdateResourceList) { var finalurl = TestResourceURL + res; twr.enqueue(finalurl, singleResourceHotUpdateCompleteCB); } twr.startRequest(); } else { DIYLog.Log("没有热更资源需要下载!资源热更完成!"); mResourceHotUpdateCompleteCB(HotUpdateResourceCode, true); } }
// 单个目录 static void AssetBundleSetFolder(AssetBundlePath abPath) { string path = abPath.path; AssetImporter importer = AssetImporter.GetAtPath(path); string[] strs = path.Split('/'); string prefix = strs[strs.Length - 2]; string name = strs[strs.Length - 1]; if (prefix == "Tiled2Unity") { name = "Tiled2Unity_" + name; } if (importer == null) { Debug.LogError("No Importer:" + name); } importer.assetBundleName = abPath.prefix + name.ToLower(); AssetBundleClearName(path); }
/// <summary> /// 资源请求携程 /// </summary> /// <returns></returns> private IEnumerator resourcesRequest() { foreach (var hotupdateres in mTestHotUpdateResourceList) { var resurl = TestResourceURL + hotupdateres; ResourceLogger.log(string.Format("下载资源 : {0}", resurl)); var webrequest = UnityWebRequest.Get(resurl); yield return(webrequest.SendWebRequest()); if (webrequest.isNetworkError) { ResourceLogger.logErr(string.Format("{0}资源下载出错!", hotupdateres)); ResourceLogger.logErr(webrequest.error); } else { if (webrequest.isDone) { ResourceLogger.log(string.Format("{0}资源下载完成!", hotupdateres)); var data = webrequest.downloadHandler.data; //检查包外是否存在同名资源,存在的话需要先删除再存储最新到包外 var outterabfullpath = AssetBundlePath.ABHotUpdatePath + hotupdateres; if (AssetBundlePath.IsABExitInOutterPath(hotupdateres)) { ResourceLogger.log(string.Format("删除包外资源 : {0}", hotupdateres)); File.Delete(outterabfullpath); } using (var fs = File.Create(outterabfullpath)) { fs.Write(data, 0, data.Length); fs.Flush(); fs.Close(); ResourceLogger.log(string.Format("包外资源 : {0}写入完成!", hotupdateres)); } } } } }
public static IEnumerator LoadConfigData() { // Debug.Log("表的路径是: " + AssetBundlePath.GetStreamingAssetsPath()); string path = AssetBundlePath.GetStreamingAssetsPath(); string[] fileNames = PlayerPrefs.GetString(StaticTag.PLAYERPREFS_CONFIG).Split('|'); int count = fileNames.Length; float startTime = Time.realtimeSinceStartup; for (int i = 0; i < count; ++i) { WWW www = new WWW(path + fileNames[i]); yield return(www); ParseFile(www.bytes, www.url); Debug.LogFormat("###Load {0} Success!###", fileNames[i]); } Debug.LogFormat("load all data time: {0}", (Time.realtimeSinceStartup - startTime)); allConfigLoaded = true; }
public IEnumerator LoadLanguage(string languageFileName, OnLanguageLoadingFinished callBack) { string fileName = languageFileName + ".txt"; WWW www = new WWW(GameUtilities.ConvertNativeUrlToWindowsPlatform(AssetBundlePath.GetLanguageAssetPath() + fileName)); yield return(www); if (string.IsNullOrEmpty(www.error)) { StormLocalization.loadedBinaryTextAsset = new BinaryTextAsset(); StormLocalization.loadedBinaryTextAsset.name = languageFileName; StormLocalization.loadedBinaryTextAsset.text = www.bytes;; } else { Debug.LogError("Can't load file " + fileName + " Error: " + www.error); } if (callBack != null) { callBack(); } }
private static void ResetBundleName(string assetPath) { Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); AssetImporter assetImporter = AssetImporter.GetAtPath(assetPath); if (!ResourcesRegex.IsMatch(assetPath) && //!EditorRegex.IsMatch(assetPath) && (!UnityEditorNameSpaceRegex.IsMatch(assetType.Namespace) || assetType.FullName.Equals("UnityEditor.SceneAsset"))) { string bundleName = AssetBundlePath.FileToBundleName(assetPath.Remove(0, "Assets/".Length)); if (!assetImporter.assetBundleName.Equals(bundleName)) { assetImporter.assetBundleName = bundleName; } } else { if (!assetType.FullName.Equals("UnityEditor.MonoScript")) { assetImporter.assetBundleName = null; } } }
private static void ExportBin(string filePath, string filename) { ByteArray ba = new ByteArray(); Assembly asm = Assembly.LoadFile(Application.dataPath + "/../Library/ScriptAssemblies/Assembly-CSharp.dll"); DataSet dataSet = DataSetHelper.CreateDataSet(filePath + filename + FILE_SUFFIX); if (dataSet != null) { //int sheetNum = dataSet.Tables.Count; int canreadSheet = 0; foreach (DataTable sheet in dataSet.Tables) { string className = sheet.TableName; object obj = asm.CreateInstance(className); //Debug.Log("当前表名是: " + sheet.TableName); if (obj == null) { continue; } ++canreadSheet; } ba.writeInt(canreadSheet); //Converter.WriteInt(writer, sheetNum); foreach (DataTable sheet in dataSet.Tables) { string className = sheet.TableName; object obj = asm.CreateInstance(className); if (obj == null) { //MUtils.ShowNotice("Load data error: "+className+" in "+filePath+" has no data."); continue; } FieldInfo[] fis = obj.GetType().GetFields(); ba.writeUTF(sheet.TableName); //Converter.WriteJavaString(writer,sheet.TableName); int rows = sheet.Rows.Count; int rowCount = 0; for (int r = 0; r != rows; ++r) { if (string.IsNullOrEmpty(sheet.Rows[r].ItemArray[0].ToString())) { break; } rowCount++; } ba.writeInt(rowCount); if (rows > 0) { ba.writeInt(sheet.Rows[0].ItemArray.Length); } else { ba.writeInt(0); } foreach (DataRow row in sheet.Rows) { int i = 0; foreach (object item in row.ItemArray) { if (i >= fis.Length) { break; } if (fis[i].FieldType == typeof(int)) { int val = 0; int.TryParse(item.ToString(), out val); ba.writeInt(val); } else if (fis[i].FieldType == typeof(short)) { short val = 0; short.TryParse(item.ToString(), out val); ba.writeShort(val); } else if (fis[i].FieldType == typeof(long)) { long val = 0; long.TryParse(item.ToString(), out val); ba.writeLong(val); } else if (fis[i].FieldType == typeof(float) || fis[i].FieldType == typeof(double) || fis[i].FieldType == typeof(string)) { ba.writeUTF(item.ToString()); } ++i; } } } } //string binpath = AssetBundlePath.GetStreamingAssetsPath() + "bin/".Replace("file://",""); string binpath = AssetBundlePath.GetStreamingAssetsPath().Replace("file://", ""); binpath = binpath.Replace("file://", ""); var file = new FileStream(binpath + filename + FILE_BIN_SUFFIX, FileMode.Create, System.IO.FileAccess.Write); byte[] bytes = ba.data; file.Write(bytes, 0, bytes.Length); file.Close(); }
/// <summary> /// 热更资源列表下载完成回调 /// </summary> /// <param name="url">下载地址</param> /// <param name="downloadhandler">下载结果数据</param> /// <param name="requeststatus">下载状态</param> private void resourceListHotUpdateCompleteCB(string url, DownloadHandler downloadhandler, TWebRequest.WebRequestTaskInfo.WebTaskRequestStatus requeststatus) { Debug.Log(string.Format("热更资源列表地址 : {0}", url)); if (requeststatus == TWebRequest.WebRequestTaskInfo.WebTaskRequestStatus.WT_Complete) { Debug.Log(string.Format("热更资源列表下载成功!热更资源列表信息 : {0}", downloadhandler.text)); mNeedHotUpdateResourceMap.Clear(); mHotUpdateResourceTotalNumber = 0; //TODO: //结合服务器上的资源MD5信息做资源验证,确保资源下对以及未被修改 var hotupdateresourcesmap = new SortedDictionary <int, List <string> >(); var hotupdateresourcesinfo = downloadhandler.text.Split(';'); try { foreach (var hotupdatereousrceinfo in hotupdateresourcesinfo) { //避免最后添加;后导致多一个空数据报错 if (hotupdatereousrceinfo.IsNullOrEmpty()) { continue; } var resourceinfo = hotupdatereousrceinfo.Split(':'); var resversion = int.Parse(resourceinfo[0]); var resname = resourceinfo[1]; List <string> reslist; if (!hotupdateresourcesmap.TryGetValue(resversion, out reslist)) { reslist = new List <string>(); hotupdateresourcesmap.Add(resversion, reslist); } if (!reslist.Contains(resname)) { reslist.Add(resname); Debug.Log(string.Format("添加需要热更的资源信息,版本号 : {0}, 资源名 : {1}", resversion, resname)); } else { Debug.LogError(string.Format("重复的资源热更信息!版本号 : {0} 资源名 : {1}!", resversion, resname)); } } //根据返回的热更资源数据结合本地资源版本号以及已经热更下载的资源计算出剩下需要热更的资源数据 var currentresversion = VersionConfigModuleManager.Singleton.GameVersionConfig.ResourceVersionCode; foreach (var hotupdateresourceinfo in hotupdateresourcesmap) { List <string> alreadyupdatedreslist; if (!mLocalUpdatedResourceMap.TryGetValue(hotupdateresourceinfo.Key, out alreadyupdatedreslist)) { alreadyupdatedreslist = new List <string>(); } if (hotupdateresourceinfo.Key > currentresversion) { foreach (var hotupdateresource in hotupdateresourceinfo.Value) { if (alreadyupdatedreslist.Contains(hotupdateresource)) { Debug.Log(string.Format("资源已经热更过了: 资源版本号:{0} 资源名:{1}", hotupdateresourceinfo.Key, hotupdateresource)); } else { List <string> neddhotupdatereslist; if (!mNeedHotUpdateResourceMap.TryGetValue(hotupdateresourceinfo.Key, out neddhotupdatereslist)) { neddhotupdatereslist = new List <string>(); mNeedHotUpdateResourceMap.Add(hotupdateresourceinfo.Key, neddhotupdatereslist); } if (!neddhotupdatereslist.Contains(hotupdateresource)) { neddhotupdatereslist.Add(hotupdateresource); mHotUpdateResourceTotalNumber++; Debug.Log(string.Format("添加需要热更的资源信息,版本号 : {0}, 资源名 : {1}", hotupdateresourceinfo.Key, hotupdateresource)); } } } } } Debug.Log(string.Format("需要热更的资源数 : {0}", mHotUpdateResourceTotalNumber)); foreach (var needhotupdateresinfo in mNeedHotUpdateResourceMap) { foreach (var needhotupdateres in needhotupdateresinfo.Value) { Debug.Log(string.Format("需要热更的资源信息 : 资源版本号:{0} 资源名:{1}", needhotupdateresinfo.Key, needhotupdateres)); } } if (mHotUpdateResourceTotalNumber > 0) { //开始资源热更 //检查资源热更目录,不存在就创建一个 AssetBundlePath.CheckAndCreateABOutterPathFolder(); //检查资源热更列表信息目录 if (!Directory.Exists(LocalResourceUpdateListFilFolderPath)) { Directory.CreateDirectory(LocalResourceUpdateListFilFolderPath); Debug.Log(string.Format("创建目录 : {0}", LocalResourceUpdateListFilFolderPath)); } foreach (var resinfo in mNeedHotUpdateResourceMap) { foreach (var res in resinfo.Value) { //URL = 基础URL + 当前版本号 + "/" + 需要热更的资源版本号 + "/" + 需要热更的资源名 var finalurl = mHotUpdateURL + VersionConfigModuleManager.Singleton.GameVersionConfig.VersionCode.ToString("0.0") + "/" + resinfo.Key + "/" + res; mHotResourceUpdateRequest.enqueue(finalurl, singleResourceHotUpdateCompleteCB); } } mHotResourceUpdateRequest.startRequest(); } else { Debug.Log("没有资源需要热更,直接进入游戏!"); mResourceHotUpdateCompleteCB(true); mResourceHotUpdateCompleteCB = null; } } catch (Exception e) { Debug.LogError(string.Format("热更资源异常 : {0}!", e.Message)); Debug.LogError("热更资源失败!"); mHotResourceUpdateRequest.stopRequest(); mResourceHotUpdateCompleteCB(false); mResourceHotUpdateCompleteCB = null; } finally { } } else { Debug.LogError("热更资源列表下载失败!"); mResourceHotUpdateCompleteCB(false); mResourceHotUpdateCompleteCB = null; } }
/// <summary> /// 打印所有AB路径信息 /// </summary> public void printAllABPath() { DIYLog.Log("printAllABPath()"); AssetBundlePath.PrintAllPathInfo(); }