public static void Build(bool _all = true) { long begin = System.DateTime.Now.Ticks; ClearAllAssetBundleName(); if (!BuildRule.LoadRules(_all)) { return; } List <AssetBundleBuild> builds = BuildRule.GetBuilds(); if (builds == null || builds.Count == 0) { return; } BuildPipeline.BuildAssetBundles(Path, builds.ToArray(), Options, TargetPlatform); if (_all) { BuildResList(null); } else { Dictionary <string, ResConfig> res_config = new Dictionary <string, ResConfig>(); Dictionary <string, string> res_path = new Dictionary <string, string>(); LoadResList(res_config, res_path); BuildResList(res_config); } TimeSpan elapsedSpan = new TimeSpan(System.DateTime.Now.Ticks - begin); Debug.LogFormat("打包所有完成 用时{0}秒", elapsedSpan.TotalSeconds); }
public static void BuildResList(Dictionary <string, ResConfig> _res_list) { AssetBundle ab = AssetBundle.LoadFromFile(string.Format("{0}/StreamingAssets", Application.streamingAssetsPath)); AssetBundleManifest manifest = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); string[] bundles = manifest.GetAllAssetBundles(); if (_res_list == null) { _res_list = new Dictionary <string, ResConfig>(); } for (int i = 0; i < bundles.Length; i++) { ResConfig config = new ResConfig(); config.BundleName = bundles[i]; config.Md5 = manifest.GetAssetBundleHash(bundles[i]).ToString(); string[] depen = manifest.GetAllDependencies(bundles[i]); config.Dependencies.AddRange(depen); config.Size = GetAssetBundleSize(string.Format("{0}/{1}", Application.streamingAssetsPath, bundles[i])); if (config.Size == 0) { Debug.LogErrorFormat("AB包 {0}的大小居然为0 请检查!", bundles[i]); } string[] paths = BuildRule.GetAssetPathByBundle(config.BundleName); //string[] paths = AssetDatabase.GetAssetPathsFromAssetBundle( config.BundleName ); for (int j = 0; j < paths.Length; j++) { config.Assets.Add(paths[j]); } if (_res_list.ContainsKey(config.BundleName)) //打包选中才有这种情况 { _res_list[config.BundleName] = config; } else { _res_list.Add(config.BundleName, config); } } ab.Unload(true); SaveResList(ResListPath, _res_list); AssetDatabase.Refresh(); BuildPipeline.BuildAssetBundles(Path, new AssetBundleBuild[] { new AssetBundleBuild() { assetBundleName = "res_list.assetbundle", assetNames = new[] { ResListPath } } }, Options, TargetPlatform); if (File.Exists(string.Format("{0}/StreamingAssets", Application.streamingAssetsPath))) { File.Delete(string.Format("{0}/StreamingAssets", Application.streamingAssetsPath)); } var alls = GetFiles(new DirectoryInfo(Path)); foreach (var file in alls) { if (file.EndsWith(".manifest")) { File.Delete(file); } } File.Delete(Application.persistentDataPath + "/res_list"); AssetDatabase.Refresh(); }