private static void Cleanup(CreateAssetBundlesContext ctx) { if (Directory.Exists(ctx.textTEMPPath)) { Directory.Delete(ctx.textTEMPPath, true); } }
public ModuleBuilder(ProductCfg.ModuleCfg cfg, string version, CreateAssetBundlesContext ctx) { Cfg = cfg; foreach (var b in Cfg.Bundles) { var bb = new BundleBuilder(b, ctx); bundleBuilders.Add(bb); } this.version = version; }
public BundleBuilder(ProductCfg.BundleCfg cfg, CreateAssetBundlesContext ctx) { Cfg = cfg; var path = cfg.Path; path = path.Replace('\\', '/'); path = path.Replace('/', '_'); BundleName = path.ToLower(); this.ctx = ctx; modulePath = Path.Combine(ctx.modulesRootPath, Cfg.Path); CheckTextCfg(); }
private static void CreateModOutputCfg(ModuleBuilder mb, CreateAssetBundlesContext ctx, UnityEngine.AssetBundleManifest manifest) { var outputRootDir = ctx.outputRootDir; var targetDir = System.IO.Path.Combine(outputRootDir, "out", mb.Cfg.Name); System.IO.Directory.CreateDirectory(targetDir); // copy bundle files foreach (var bb in mb.bundleBuilders) { var bName = bb.BundleName; var srcFileName = System.IO.Path.Combine(outputRootDir, bName); var dstFileName = System.IO.Path.Combine(targetDir, bName); System.IO.File.Copy(srcFileName, dstFileName); } // generate cfg json file var mcfg = new ModOutputCfg(); mcfg.name = mb.Cfg.Name; mcfg.version = mb.version; mcfg.csVer = ctx.csVersion; mcfg.lobbyVer = ctx.lobbyVersion; var bcfgList = new List <ModBundleOutputCfg>(); foreach (var bb in mb.bundleBuilders) { var bName = bb.BundleName; var srcFileName = System.IO.Path.Combine(outputRootDir, bName); var bcfg = new ModBundleOutputCfg(); bcfg.name = bName; var bytes = System.IO.File.ReadAllBytes(srcFileName); bcfg.md5 = NetHelper.MD5(bytes); bcfg.size = bytes.Length; bcfg.deps = manifest.GetDirectDependencies(bName); bcfgList.Add(bcfg); } mcfg.abList = bcfgList.ToArray(); var cfgFileName = System.IO.Path.Combine(targetDir, "cfg.json"); var json = UnityEngine.JsonUtility.ToJson(mcfg, true); System.IO.File.WriteAllText(cfgFileName, json); }
static void BuildAllAssetBundles() { //BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget); var productCfg = ProductCfg.LoadFromFile(System.IO.Path.Combine(UnityEngine.Application.dataPath, "product.json")); var options = BuildAssetBundleOptions.DisableWriteTypeTree | BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle; var outputRootDir = System.IO.Path.Combine(UnityEngine.Application.dataPath, "../AssetBundles"); var textTempPath = System.IO.Path.Combine(UnityEngine.Application.dataPath, ProductCfg.MODULES_PATH, ProductCfg.TEXT_PATH_TEMP); var ctx = new CreateAssetBundlesContext(); ctx.outputRootDir = outputRootDir; ctx.textTEMPPath = textTempPath; ctx.options = options; ctx.target = EditorUserBuildSettings.activeBuildTarget; ctx.modulesRootPath = Path.Combine(UnityEngine.Application.dataPath, ProductCfg.MODULES_PATH); ctx.csVersion = ModuleBuilder.GetCSVersionString(); ctx.lobbyVersion = ModuleBuilder.GetLobbyVersionString(); if (Directory.Exists(outputRootDir)) { Directory.Delete(outputRootDir, true); } Cleanup(ctx); Directory.CreateDirectory(outputRootDir); ModuleBuilder.BuildProductModules(productCfg, ctx); Cleanup(ctx); AssetDatabase.Refresh(); Debug.Log("Build AssetBundles Done!"); }
public static void BuildProductModules(ProductCfg pcfg, CreateAssetBundlesContext ctx) { var abbList = new List <AssetBundleBuild>(); var modbList = new List <ModuleBuilder>(); // build Lobby foreach (var mcfg in pcfg.Modules) { var vs = GetVersionString(mcfg.Name); var mb = new ModuleBuilder(mcfg, vs, ctx); if (mb.Build(abbList)) { modbList.Add(mb); } } if (abbList.Count < 1) { Debug.Log("no bundle found in cfg file, nothing to do"); return; } AssetDatabase.Refresh(); var manifest = BuildPipeline.BuildAssetBundles(ctx.outputRootDir, abbList.ToArray(), ctx.options, ctx.target); if (manifest == null) { return; } // for each module, copy bundles to its folder, and generate cfg.json foreach (var mb in modbList) { CreateModOutputCfg(mb, ctx, manifest); } }