/// <summary> /// 创建依赖关系 /// </summary> private static void CreateAssetBundleDepends() { RecordPackAbundleMainifestInfor(AssetBundleMgr.Instance.GetHotAssetBuildPlatformName(S_CurrentBuildTarget)); //不同平台的打包主AssetBundle RecordPackAbundleMainifestInfor(AssetBundleMgr.Instance.GetHotAssetBuildPlatformName(S_CurrentBuildTarget) + ".manifest"); // AssetBundleManifest #region 遍历记录所有的AssetBundle string[] allAssets = AssetBundleMgr.Instance.S_AssetBundleManifest.GetAllAssetBundles();//获得所有的AssetBundleName foreach (var item in allAssets) { string[] depences = AssetBundleMgr.Instance.S_AssetBundleManifest.GetAllDependencies(item); //获得当前资源的所有依赖关系 string path = S_AssetBundleOutPath + "/" + item; //获取打包后的资源AssetBundle 绝对路径 #region 记录当前AssetBundle 信息 AssetBundleRecordeInfor _infor = new AssetBundleRecordeInfor(); _infor.m_MD5Code = MD5Helper.GetFileMD5(path); System.IO.FileInfo fileInfor = new System.IO.FileInfo(path); _infor.m_ByteSize = (int)fileInfor.Length; // _infor.m_DependeceAssetNamePath.AddRange(depences); if (S_HotAssetBaseRecordInfor.AllAssetRecordsDic.ContainsKey(item)) { Debug.LogError("重复的AssetBundleName=" + item); break; } S_HotAssetBaseRecordInfor.AllAssetRecordsDic.Add(item, _infor); //记录当前的 AssetBundle 资源 #endregion #region 记录当前文件 .meta信息 AssetBundleRecordeInfor _metaInfor = new AssetBundleRecordeInfor(); _metaInfor.m_MD5Code = MD5Helper.GetFileMD5(path + ".meta"); FileInfo mataFileInfor = new System.IO.FileInfo(path + ".meta"); _metaInfor.m_ByteSize = (int)mataFileInfor.Length; if (S_HotAssetBaseRecordInfor.AllAssetRecordsDic.ContainsKey(item + ".meta")) { Debug.LogError("重复的AssetBundleName=" + item + ".meta"); break; } S_HotAssetBaseRecordInfor.AllAssetRecordsDic.Add(item + ".meta", _metaInfor); //记录当前的 AssetBundle 资源 #endregion } AssetBundleMgr.Instance.m_MainAssetBundle.Unload(true); //避免打包后编辑器加载报错 #endregion }
/// <summary> /// 记录不同平台打包下生成的主 mainAssetBundle 和 mainFest 信息 /// </summary> /// <param name="fileName"></param> private static void RecordPackAbundleMainifestInfor(string fileName) { string PlatformABundlePath = S_AssetBundleOutPath + "/" + fileName; //if(System.IO.File.Exists(PlatformABundlePath)) // System.IO.File.Create() //当AssetBundle AssetBundleRecordeInfor _infor = new AssetBundleRecordeInfor(); System.IO.FileInfo fileInfor = new System.IO.FileInfo(PlatformABundlePath); _infor.m_ByteSize = (int)fileInfor.Length; _infor.m_MD5Code = MD5Helper.GetFileMD5(PlatformABundlePath); S_HotAssetBaseRecordInfor.AllAssetRecordsDic.Add(fileName, _infor); //.meta AssetBundleRecordeInfor _metaInfor = new AssetBundleRecordeInfor(); System.IO.FileInfo metaFileInfor = new System.IO.FileInfo(PlatformABundlePath + ".meta"); _metaInfor.m_ByteSize = (int)metaFileInfor.Length; _metaInfor.m_MD5Code = MD5Helper.GetFileMD5(PlatformABundlePath + ".meta"); S_HotAssetBaseRecordInfor.AllAssetRecordsDic.Add(fileName + ".meta", _metaInfor); }