private void BuildBundles(ResourceBundleConfig config, BuildTarget target) { List <HashSet <Object> > dss = new List <HashSet <Object> >(config.bundles.Count); List <Object> commonAssets = new List <Object>(); for (int i = 0; i < config.bundles.Count; ++i) { var ru = config.bundles[i].bundle; //BuildBundle(ru, target); if (ru != null) { var dsets = GetUnitDependencies(ru); dss.Add(dsets); } else { dss.Add(null); } } { Dictionary <Object, int> allObjs = new Dictionary <Object, int>(); foreach (var ds in dss) { foreach (var s in ds) { if (allObjs.ContainsKey(s)) { allObjs[s]++; } else { allObjs.Add(s, 1); } } } foreach (var s in allObjs) { if (s.Value > 1) { commonAssets.Add(s.Key); } } } var commonABB = GetAssetBundleBuild(commonAssets, "common"); List <AssetBundleBuild> abbs = new List <AssetBundleBuild>(); abbs.Add(commonABB); foreach (var ru in config.bundles) { var abb = GetAssetBundleBuild(ru.bundle, commonAssets); abbs.Add(abb); } BuildAssetBundleOptions opt = BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression; BuildPipeline.BuildAssetBundles("Assets/StreamingAssets", abbs.ToArray(), opt, target); }
public static string Compile(ResourceBundleConfig config) { string result = string.Empty; string rowFormat = "{0}\t{1}\n"; foreach (var b in config.bundles) { var bundlePath = UnityEditor.AssetDatabase.GetAssetPath(b.bundle); var bundleName = System.IO.Path.GetFileNameWithoutExtension(bundlePath); result += string.Format(rowFormat, bundleName, b.prefix); } return(result); }
private void BuildConfig(ResourceBundleConfig config) { var configPath = AssetDatabase.GetAssetPath(config); var configFilename = Path.GetFileNameWithoutExtension(configPath); var r = ResourceBundleConfigCompiler.Compile(config); if (false == Directory.Exists("Assets/StreamingAssets")) { //创建pic文件夹 Directory.CreateDirectory("Assets/StreamingAssets"); } string path = "Assets/StreamingAssets/" + configFilename.ToLower() + ".txt"; StreamWriter s = new StreamWriter(path, false); s.Write(r); s.Close(); s.Dispose(); }