static void saveUabConfig(UabConfig uabcfg) { string path = UabFileUtil.PathCombine(UabEditorDef.UabRoot, UabDef.UAB_CONFIG_NAME); string json = JsonUtility.ToJson(uabcfg, true); File.WriteAllBytes(path, Encoding.UTF8.GetBytes(json)); }
public static void Build(string cfgpath) { UabConfig cfg = UabCommon.LoadUabConfigFromFile(cfgpath); if (cfg == null || cfg.G == null) { Debug.LogError("uab cfg error! "); return; } Build(cfg); }
public static void Build(UabConfig uabcfg) { //var abnames = AssetDatabase.GetAllAssetBundleNames(); //for (int i = 0;i<abnames.Length;i++) //{ // AssetDatabase.RemoveAssetBundleName(abnames[i],true); // //Debug.LogError("FORCE REMOVE AB NAME :"+ abnames[i]); //} string targetroot = UabFileUtil.PathCombine(UabEditorDef.UabRoot, UabDef.UAB_BUNDLE_ROOT); UabFileUtil.EnsureDir(targetroot); for (int i = 0; i < uabcfg.G.Length; i++) { if (!uabcfg.G[i].enabled) { continue; } if (!uabcfg.G[i].isasset) { continue; } string[] files = UabCollect.collectFiles(uabcfg.G[i]); for (int j = 0; j < files.Length; j++) { if (!uabcfg.G[i].resourceasset) { //Debug.LogWarning("file :" + files[j] + " check depend :"); var d = AssetDatabase.GetDependencies(files[j], true); for (int m = 0; m < d.Length; m++) { //Debug.LogError("dependency is " + d[m]); if (!neededRes.Contains(d[m])) { neededRes.Add(d[m]); } } } else { if (!allNotLoadedRes.Contains(files[j])) { allNotLoadedRes.Add(files[j]); } } } } //foreach(var res in allNotLoadedRes) //{ // if (!neededRes.Contains(res)) // Debug.LogError("检测到无用资源 :" + res); //} //return; List <UabInfoItem> uabItems = new List <UabInfoItem>(); List <AssetBundleBuild> abbuilds = new List <AssetBundleBuild>(); List <UabInfoItem> items = null; for (int i = 0; i < uabcfg.G.Length; i++) { if (!uabcfg.G[i].enabled) { continue; } if (!uabcfg.G[i].isasset) { continue; } List <AssetBundleBuild> l = UabCollect.CollectABBuilds(uabcfg.G[i]); if (uabcfg.G[i].name == "video") { items = buildOnePipeline(l, BuildAssetBundleOptions.UncompressedAssetBundle | BuildAssetBundleOptions.DeterministicAssetBundle); if (items == null) { return; } uabItems.AddRange(items); } else { abbuilds.AddRange(l); } } BuildAssetBundleOptions op = BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle; items = buildOnePipeline(abbuilds, op); if (items == null) { return; } uabItems.AddRange(items); saveUabConfig(uabcfg); saveUabInfo(uabItems); AssetDatabase.Refresh(); Debug.Log("uab build success..."); }