/// <summary> /// 载入ResourcesManifest /// </summary> public static ResourcesManifest LoadResourcesManifestByPath(string full_name) { var result = new ResourcesManifest(); result.Load(full_name); return(result); }
/// <summary> /// 载入数据 /// </summary> private bool LoadData() { Manifest = new ResourcesManifest(); bool result = Manifest.Load(EditorCommon.RESOURCES_MANIFEST_FILE_PATH); Build(); return(result); }
/// <summary> /// 载入数据 /// </summary> public bool LoadData(ResourcesManifest manifest = null) { bool result = false; if (manifest == null) { Manifest = new ResourcesManifest(); result = Manifest.Load(EditorCommon.RESOURCES_MANIFEST_FILE_PATH); } else { Manifest = manifest; result = true; } Build(); return(result); }
/// <summary> /// 执行已做的修改 /// </summary> void ExecuteModified() { ResourcesManifest old_resources_manifest = new ResourcesManifest(); old_resources_manifest.Load(EditorCommon.RESOURCES_MANIFEST_FILE_PATH); //压缩AB包 bool compress = BuildAssetBundle.CompressAssetBundles(old_resources_manifest , Manifest); //保存数据 bool save = compress ? SaveData() : false; //拷贝资源 bool copy = save ? BuildAssetBundle.CopyNativeAssetBundleToStreamingAssets(Manifest) : false; bool succeed = compress && copy && save; if (succeed) { //同步数据 if (AssetBundleBuildWindow.Instance != null) { AssetBundleBuildWindow.Instance.SyncConfigForm(Manifest.Data); } else { AssetBundleBuild buildData = new AssetBundleBuild(); buildData.Load(EditorCommon.ASSETBUNDLE_BUILD_RULE_FILE_PATH); buildData.SyncConfigFrom(Manifest.Data); buildData.Save(EditorCommon.ASSETBUNDLE_BUILD_RULE_FILE_PATH); } } string title = "执行配置AssetBundle" + (succeed ? "成功" : "失败"); string compress_desc = "压缩资源 - " + (compress ? "成功" : "失败"); string save_desc = "保存配置文件 - " + (save ? "成功" : "失败"); string copy_desc = "拷贝初始资源至安装包目录 - " + (copy ? "成功" : "失败"); string desc = compress_desc + "\n" + save_desc + "\n" + copy_desc + "\n\n"; EditorUtility.DisplayDialog(title, desc, "确认"); }
/// <summary> /// 执行已做的修改 /// </summary> void ExecuteModified() { ResourcesManifest old_resources_manifest = new ResourcesManifest(); old_resources_manifest.Load(EditorCommon.RESOURCES_MANIFEST_FILE_PATH); bool compress = BuildAssetBundle.CompressAssetBundles(old_resources_manifest , ref Manifest); bool save = compress ? SaveData() : false; bool copy = save ? BuildAssetBundle.CopyNativeAssetBundleToStreamingAssets(Manifest) : false; bool succeed = compress && copy && save; string title = "执行配置AssetBundle" + (succeed ? "成功" : "失败"); string compress_desc = "压缩资源 - " + (compress ? "成功" : "失败"); string save_desc = "保存配置文件 - " + (save ? "成功" : "失败"); string copy_desc = "拷贝初始资源至安装包目录 - " + (copy ? "成功" : "失败"); string desc = compress_desc + "\n" + save_desc + "\n" + copy_desc + "\n\n"; EditorUtility.DisplayDialog(title, desc, "确认"); }
/// <summary> /// 根据AssetBundle导出ResourcesManifest文件 /// </summary> public static void ExportResourcesManifestFile(AssetBundleManifest manifest) { ResourcesManifest info = new ResourcesManifest(); //读取所有AssetBundle string root_dir = EditorCommon.PATH + "/"; List <string> scenes = new List <string>(); if (manifest != null) { //读取主AssetBundle ResourcesManifestData.AssetBundle desc = new ResourcesManifestData.AssetBundle(); desc.AssetBundleName = Common.MAIN_MANIFEST_FILE_NAME; desc.Size = zcode.FileHelper.GetFileSize(root_dir + Common.MAIN_MANIFEST_FILE_NAME); info.Data.AssetBundles.Add(Common.MAIN_MANIFEST_FILE_NAME, desc); //读取其它AssetBundle foreach (var name in manifest.GetAllAssetBundles()) { desc = new ResourcesManifestData.AssetBundle(); desc.AssetBundleName = name; desc.Size = zcode.FileHelper.GetFileSize(root_dir + name); AssetBundle ab = AssetBundle.LoadFromFile(root_dir + name); foreach (var asset in ab.GetAllAssetNames()) { desc.Assets.Add(asset); } foreach (var scene in ab.GetAllScenePaths()) { desc.Scenes.Add(scene); scenes.Add(scene); } ab.Unload(false); info.Data.AssetBundles.Add(name, desc); } } //读取所有Scene信息 for (int i = 0; i < scenes.Count; ++i) { ResourcesManifestData.Scene scene_desc = new ResourcesManifestData.Scene(); scene_desc.SceneLevelName = Path.GetFileNameWithoutExtension(scenes[i]); scene_desc.ScenePath = scenes[i]; scene_desc.SceneConfigPath = SceneConfig.GetSceneConfigPath(scenes[i]); info.Data.Scenes.Add(scene_desc.SceneLevelName, scene_desc); } //读取旧的ResourcesInfo,同步其它额外的数据 ResourcesManifest old_info = new ResourcesManifest(); old_info.Load(EditorCommon.RESOURCES_MANIFEST_FILE_PATH); if (old_info.Data != null && old_info.Data.AssetBundles.Count > 0) { foreach (var desc in old_info.Data.AssetBundles.Values) { if (info.Data.AssetBundles.ContainsKey(desc.AssetBundleName)) { info.Data.AssetBundles[desc.AssetBundleName].IsNative = desc.IsNative; info.Data.AssetBundles[desc.AssetBundleName].IsPermanent = desc.IsPermanent; } } } //保存ResourcesInfo info.Save(EditorCommon.RESOURCES_MANIFEST_FILE_PATH); AssetDatabase.Refresh(); }
/// <summary> /// 加载粒度信息 /// </summary> void LoadAssetBundleGranularityInfo() { Dictionary <string, int> granularity_table = new Dictionary <string, int>(); //载入ResourcesManifest文件 ResourcesManifest resoureces_manifest = new ResourcesManifest(); resoureces_manifest.Load(EditorCommon.RESOURCES_MANIFEST_FILE_PATH); if (resoureces_manifest.Data.AssetBundles.Count == 0) { return; } //载入AssetBunbleManifest string full_name = EditorCommon.MAIN_MANIFEST_FILE_PATH; AssetBundleManifest manifest = Common.LoadMainManifestByPath(full_name); if (manifest == null) { return; } //遍历AssetBundle foreach (var ab_name in manifest.GetAllAssetBundles()) { AssetBundle ab = EditorCommon.LoadAssetBundleFromName(ab_name); if (ab != null) { //获得所有的AssetBundle依赖 List <string> de_abs = new List <string>(manifest.GetAllDependencies(ab_name)); //获得所有依赖的AssetBundle的Asset List <string> de_assets = new List <string>(); foreach (var ab_name1 in de_abs) { AssetBundle ab1 = EditorCommon.LoadAssetBundleFromName(ab_name1); if (ab1 != null) { de_assets.AddRange(ab1.GetAllAssetNames()); ab1.Unload(false); } } //获得所有的Asset List <string> result = new List <string>(); List <string> assets = new List <string>(ab.GetAllAssetNames()); SearchValidAsset(assets, de_assets, ref result); foreach (var name in result) { if (granularity_table.ContainsKey(name)) { granularity_table[name] = granularity_table[name] + 1; } else { granularity_table.Add(name, 1); } } ab.Unload(false); } } //刷新UI数据 AssetNodeGroup group = gui_multi_select_.Group as AssetNodeGroup; group.Root.RefreshGranularity("assets", granularity_table); }
/// <summary> /// 加载粒度信息 /// </summary> void LoadGranularityInfo(bool show_details, Action <string, float> progress_report) { Dictionary <string, string> granularity_details_table = null; if (show_details) { granularity_details_table = new Dictionary <string, string>(16384); } Dictionary <string, int> granularity_table = new Dictionary <string, int>(16384); //载入ResourcesManifest文件 ResourcesManifest resoureces_manifest = new ResourcesManifest(); resoureces_manifest.Load(EditorCommon.RESOURCES_MANIFEST_FILE_PATH); if (resoureces_manifest.Data.AssetBundles == null || resoureces_manifest.Data.AssetBundles.Count == 0) { return; } //载入AssetBunbleManifest string full_name = EditorCommon.MAIN_MANIFEST_FILE_PATH; AssetBundleManifest manifest = Common.LoadMainManifestByPath(full_name); if (manifest == null) { return; } var all_asset_bundle_names = manifest.GetAllAssetBundles(); //遍历AssetBundle,并载入所有AssetBundle float count = all_asset_bundle_names.Length; float current = 0; Dictionary <string, AssetBundle> all_ab = new Dictionary <string, AssetBundle>(all_asset_bundle_names.Length); foreach (var ab_name in all_asset_bundle_names) { if (progress_report != null) { progress_report("正在加载 " + ab_name, ++current / count); } AssetBundle ab = EditorCommon.LoadAssetBundleFromName(ab_name); all_ab.Add(ab_name, ab); } //遍历所有ab包,计算粒度 HashSet <string> result = new HashSet <string>(); HashSet <string> dep_asset_names = new HashSet <string>(); count = all_ab.Count; current = 0; foreach (var ab in all_ab) { string ab_name = ab.Key; AssetBundle assetbundle = ab.Value; if (progress_report != null) { progress_report("正在分析 " + ab_name, ++current / count); } //获得所有的AssetBundle依赖 string[] dep_ab_names = manifest.GetAllDependencies(ab_name); //获得所有依赖的AssetBundle的Asset dep_asset_names.Clear(); foreach (var dep_name in dep_ab_names) { AssetBundle dep_ab = null; if (all_ab.TryGetValue(dep_name, out dep_ab)) { string[] asset_names = dep_ab.GetAllAssetNames(); for (int i = 0; i < asset_names.Length; ++i) { dep_asset_names.Add(asset_names[i]); } } } //搜寻所有有效的资源 result.Clear(); List <string> assets = new List <string>(assetbundle.GetAllAssetNames()); SearchValidAsset(assets, dep_asset_names, ref result); //设置粒度值 foreach (var name in result) { if (granularity_table.ContainsKey(name)) { granularity_table[name] = granularity_table[name] + 1; } else { granularity_table.Add(name, 1); } if (granularity_details_table != null) { if (!granularity_details_table.ContainsKey(name)) { granularity_details_table.Add(name, ""); } granularity_details_table[name] = granularity_details_table[name] + ab_name + "\n"; } } result.Clear(); } //卸载所有AssetBundle foreach (var ab in all_ab) { ab.Value.Unload(true); } all_ab.Clear(); //刷新UI数据 string path = asset_bundle_build_.Data.BuildStartLocalPath.ToLower(); AssetNodeGroup group = gui_multi_select_.Group as AssetNodeGroup; current = 0; count = asset_bundle_build_.Data.Assets.Root.Count(); RefreshGranularity(granularity_table, granularity_details_table, path, group.Root, (name) => { if (progress_report != null) { progress_report("正在刷新 " + name, ++current / count); } }); }