static public List <UnityEditor.AssetBundleBuild> GetBunldeBuildsAllInOne(string path) { waitExportFiles.Clear(); string tpath = path; List <UnityEditor.AssetBundleBuild> builds = new List <UnityEditor.AssetBundleBuild>(); DirectoryInfo tdirfolder = new DirectoryInfo(Config.sResourcesPath); FileInfo[] tfileinfos = tdirfolder.GetFiles("*.*", System.IO.SearchOption.AllDirectories); UnityEditor.AssetBundleBuild tbuild = new UnityEditor.AssetBundleBuild(); tbuild.assetBundleName = "allinone" + sSuffixName; List <string> tnamelist = new List <string>(); for (int i = 0, tmax = tfileinfos.Length; i < tmax; i++) { FileInfo tfile = tfileinfos[i]; if (!IsResFile(tfile.Name)) { continue; } string tresPath = GetResPath(tfile.FullName); tnamelist.Add(tresPath); EditorUtility.DisplayProgressBar("AllInOne", "Build " + tfile.Name, (float)i / tmax); } tbuild.assetNames = tnamelist.ToArray(); builds.Add(tbuild); EditorUtility.ClearProgressBar(); return(builds); }
static public UnityEditor.AssetBundleBuild GetAssetBundleBuild(string pFileName) { string tresPath = GetResPath(pFileName); UnityEditor.AssetBundleBuild tbuild = new UnityEditor.AssetBundleBuild(); tbuild.assetBundleName = tresPath + sSuffixName; tbuild.assetNames = new string[] { tresPath }; return(tbuild); }
static public void BuildByteFileInfoFile(string pSocPath, string pDesPath, BuildTarget _target) { string txtbytefile = pSocPath + sByteFileInfo + sSuffixName; if (File.Exists(txtbytefile)) { File.Delete(txtbytefile); } string tmainfdest = txtbytefile + ".manifest"; if (File.Exists(tmainfdest)) { File.Delete(tmainfdest); } pSocPath = GetFormatPath(pSocPath); DirectoryInfo tdirfolder = new DirectoryInfo(pSocPath); FileInfo[] tfileinfos = tdirfolder.GetFiles("*" + sSuffixName, System.IO.SearchOption.AllDirectories); List <ByteFileInfo> byteFileInfoList = new List <ByteFileInfo>(); string appmainfest = "AppManifest" + sSuffixName; string appPath = GetFormatPath(System.IO.Directory.GetCurrentDirectory()); for (int i = 0, tmax = tfileinfos.Length; i < tmax; i++) { FileInfo tfile = tfileinfos[i]; string tresPath = GetFormatPath(tfile.FullName).Replace(appPath, ""); string trpstr = pSocPath; int tindex = tresPath.IndexOf(trpstr) + trpstr.Length; tresPath = tresPath.Substring(tindex, tresPath.Length - tindex); ByteFileInfo tbyteinfo = CreatByteFileInfo(tfile, tresPath); byteFileInfoList.Add(tbyteinfo); if (tfile.FullName.EndsWith(appmainfest)) { tbyteinfo.priority = 999; } EditorUtility.DisplayProgressBar("计算Build文件信息", tresPath, (float)i / tmax); } EditorUtility.ClearProgressBar(); CreatTxtInfo(byteFileInfoList, pDesPath); AssetDatabase.Refresh(); string txtfile = pDesPath + sByteFileInfo; UnityEditor.AssetBundleBuild[] tbuilds = new UnityEditor.AssetBundleBuild[1]; tbuilds[0] = new UnityEditor.AssetBundleBuild(); tbuilds[0].assetBundleName = sByteFileInfo + sSuffixName; tbuilds[0].assetNames = new string[] { txtfile }; BuildPipeline.BuildAssetBundles(pSocPath, tbuilds, sBuildOption[ExportSetting.Instance.sCompressed] | BuildAssetBundleOptions.DeterministicAssetBundle, _target); }
public UnityEngine.AssetBundleManifest Build() { if (!Directory.Exists(this.output)) { Directory.CreateDirectory(this.output); } List <UnityEditor.AssetBundleBuild> builds = new List <UnityEditor.AssetBundleBuild>(); foreach (var v in this.builds) { UnityEditor.AssetBundleBuild build = new UnityEditor.AssetBundleBuild(); build.assetBundleName = v.assetBundleName; build.assetNames = v.assetNames; builds.Add(build); } return(UnityEditor.BuildPipeline.BuildAssetBundles(this.output, builds.ToArray(), (BuildAssetBundleOptions)this.options, (BuildTarget)this.target)); }
/// <summary> /// 自动构建ab /// </summary> /// <param name="assets"></param> /// <param name="outPath"></param> /// <param name="abName"></param> /// <param name="bbo"></param> public static void BuildABs(string[] assets, string outPath, string abName, BuildAssetBundleOptions bbo) { AssetBundleBuild[] bab = new AssetBundleBuild[1]; bab[0].assetBundleName = abName;//打包的资源包名称 随便命名 bab[0].assetNames = assets; if (string.IsNullOrEmpty(outPath)) outPath = GetOutPutPath(); string tmpPath = BuildScript.GetAssetTmpPath(); string tmpFileName = Path.Combine(tmpPath, abName); BuildPipeline.BuildAssetBundles(tmpPath, bab, bbo, target); string targetFileName = Path.Combine(outPath, abName); FileInfo tInfo = new FileInfo(targetFileName); if (tInfo.Exists) tInfo.Delete(); FileInfo fino = new FileInfo(tmpFileName); fino.CopyTo(targetFileName); }
public override void Export() { base.Export(); List<AssetBundleBuild> list = new List<AssetBundleBuild>(); //标记所有 asset bundle name var all = AssetBundleUtils.GetAll(); for (int i = 0; i < all.Count; i++) { AssetTarget target = all[i]; if (target.needSelfExport) { AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = target.bundleName; build.assetNames = new string[] { target.assetPath }; list.Add(build); } } //开始打包 BuildPipeline.BuildAssetBundles(pathResolver.BundleSavePath, list.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); #if UNITY_5_1 || UNITY_5_2 AssetBundle ab = AssetBundle.CreateFromFile(pathResolver.BundleSavePath + "/AssetBundles"); #else AssetBundle ab = AssetBundle.LoadFromFile(pathResolver.BundleSavePath + "/AssetBundles"); #endif AssetBundleManifest manifest = ab.LoadAsset("AssetBundleManifest") as AssetBundleManifest; //hash for (int i = 0; i < all.Count; i++) { AssetTarget target = all[i]; Hash128 hash = manifest.GetAssetBundleHash(target.bundleName); target.bundleCrc = hash.ToString(); } this.SaveDepAll(all); ab.Unload(true); this.RemoveUnused(all); AssetDatabase.RemoveUnusedAssetBundleNames(); AssetDatabase.Refresh(); }
static public List <UnityEditor.AssetBundleBuild> GetBunldeBuildsEvery(string path, bool isHaveDep) { waitExportFiles.Clear(); string tpath = path; List <UnityEditor.AssetBundleBuild> builds = new List <UnityEditor.AssetBundleBuild>(); DirectoryInfo tdirfolder = new DirectoryInfo(Config.sResourcesPath); FileInfo[] tfileinfos = tdirfolder.GetFiles("*.*", System.IO.SearchOption.AllDirectories); for (int i = 0, tmax = tfileinfos.Length; i < tmax; i++) { FileInfo tfile = tfileinfos[i]; if (!IsResFile(tfile.Name)) { continue; } string tresPath = GetResPath(tfile.FullName); if (waitExportFiles.ContainsKey(tresPath)) { continue; } UnityEditor.AssetBundleBuild tbuild = GetAssetBundleBuild(tfile.FullName); builds.Add(tbuild); waitExportFiles.Add(tresPath, tbuild); if (isHaveDep) { AddAssetFromDependencles(tresPath, ref builds); } EditorUtility.DisplayProgressBar("单文件Build", tresPath, (float)i / tmax); } EditorUtility.ClearProgressBar(); return(builds); }
static void AddAssetFromDependencles(string presPath, ref List <UnityEditor.AssetBundleBuild> buildList) { string[] tresdepends = AssetDatabase.GetDependencies(presPath, true); foreach (var item in tresdepends) { if (!IsResFile(item)) { continue; } if (waitExportFiles.ContainsKey(item)) { continue; } UnityEditor.AssetBundleBuild tbuild = GetAssetBundleBuild(item); buildList.Add(tbuild); waitExportFiles.Add(item, tbuild); AddAssetFromDependencles(item, ref buildList); } }
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds) { BuildTarget webPlayer = BuildTarget.WebPlayer; BuildAssetBundleOptions none = BuildAssetBundleOptions.None; return BuildAssetBundles(outputPath, builds, none, webPlayer); }
private static extern AssetBundleManifest BuildAssetBundlesWithInfoInternal(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform);
/// <summary> /// <para>Build AssetBundles from a building map.</para> /// </summary> /// <param name="outputPath">Output path for the AssetBundles.</param> /// <param name="builds">AssetBundle building map.</param> /// <param name="assetBundleOptions">AssetBundle building options.</param> /// <param name="targetPlatform">Target build platform.</param> /// <returns> /// <para>The manifest listing all AssetBundles included in this build.</para> /// </returns> public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform) { if (!Directory.Exists(outputPath)) { throw new ArgumentException("The output path \"" + outputPath + "\" doesn't exist"); } if (builds == null) { throw new ArgumentException("AssetBundleBuild cannot be null."); } return BuildAssetBundlesWithInfoInternal(outputPath, builds, assetBundleOptions, targetPlatform); }
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, [DefaultValue("BuildAssetBundleOptions.None")] BuildAssetBundleOptions assetBundleOptions) { WebPlayerAssetBundlesAreNoLongerSupported(); return null; }
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds) { BuildAssetBundleOptions none = BuildAssetBundleOptions.None; return BuildAssetBundles(outputPath, builds, none); }
public static void Build() { string outputPath = Path.Combine(AssetBundlesOutputPath, AssetBundleUtility.GetPlatformName()); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } //List<KeyValuePair<string, string>> assetInfos = new List<KeyValuePair<string, string>>(); //assetInfos.Add(new KeyValuePair<string, string>(AssetBundleUtility.GetPlatformName(), AssetBundleUtility.GetPlatformName() + AssetBundleUtility.AssetBundleExtension)); List<string> paths = new List<string>(); paths.Add(AssetBundleUtility.GetPlatformName() + AssetBundleUtility.AssetBundleExtension); List<AssetBundleBuild> builds = new List<AssetBundleBuild>(); //string[] lookFor = new string[] { AssetBundleUtility.AssetBundleResourcesPath }; //string[] guids = AssetDatabase.FindAssets("", lookFor); //foreach (var guid in guids) //{ // string assetPath = AssetDatabase.GUIDToAssetPath(guid); // if (!AssetDatabase.IsValidFolder(assetPath))//排除文件夹 // { // string assetBundleName = AssetPathToAssetBundleName(assetPath).ToLower(); // paths.Add(assetBundleName); // AssetBundleBuild build = new AssetBundleBuild(); // build.assetBundleName = assetBundleName; // build.assetNames = new string[] { assetPath }; // builds.Add(build); // //Debug.Log(build.assetBundleName); // //Debug.Log(assetPath); // } //} DirectoryInfo dirInfo = new DirectoryInfo(AssetBundleUtility.AssetBundleResourcesPath); FileInfo[] fileInfos = dirInfo.GetFiles("*", SearchOption.AllDirectories); foreach (var item in fileInfos) { if (Path.GetExtension(item.Name) != ".meta") { //AssetImporter ai = AssetImporter.GetAtPath(item.FullName); //if (string.IsNullOrEmpty(ai.assetBundleName)) //{ // ai.assetBundleName = FilePathToAssetBundleName(item.FullName).ToLower(); //} //else //{ //} string assetBundleName = FilePathToAssetBundleName(item.FullName).ToLower() + AssetBundleUtility.AssetBundleExtension; paths.Add(assetBundleName); AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = assetBundleName; build.assetNames = new string[] { FilePathToAssetName(item.FullName) }; builds.Add(build); } } BuildPipeline.BuildAssetBundles(outputPath, builds.ToArray(), BuildAssetBundleOptions.DisableWriteTypeTree | BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); string manifestFilePath = Path.Combine(outputPath, AssetBundleUtility.GetPlatformName()); string manifestFilePathRename = manifestFilePath + AssetBundleUtility.AssetBundleExtension; if (File.Exists(manifestFilePathRename)) { File.Delete(manifestFilePathRename); } File.Move(manifestFilePath, manifestFilePathRename); StringBuilder sb = new StringBuilder(DateTime.Now.ToString("yyyyMMddHHmmss")); for (int i = 0; i < paths.Count; i++) { string path = paths[i]; FileStream fs = new FileStream(Path.Combine(outputPath, path), FileMode.Open); sb.AppendFormat("\n{0}\t{1}\t{2}", path, AssetBundleUtility.GetMD5HashFromFileStream(fs), fs.Length); fs.Close(); EditorUtility.DisplayProgressBar("Compute MD5", string.Format("{0}/{1} {2}", i + 1, paths.Count, path), (i + 1) / (float)paths.Count); } File.WriteAllBytes(Path.Combine(outputPath, AssetBundleUtility.VersionFileName), Encoding.UTF8.GetBytes(sb.ToString())); EditorUtility.ClearProgressBar(); if(!EditorUtility.DisplayDialog("Build AssetBundles", "Build Success!", "OK", "Open Contain Folder")) { System.Diagnostics.Process.Start("explorer.exe", "/select," + Path.GetFullPath(outputPath)); } }
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, [DefaultValue("BuildAssetBundleOptions.None")] BuildAssetBundleOptions assetBundleOptions, [DefaultValue("BuildTarget.WebPlayer")] BuildTarget targetPlatform) { if (!Directory.Exists(outputPath)) { Debug.LogError("The output path \"" + outputPath + "\" doesn't exist"); return null; } if (builds == null) { Debug.LogError("AssetBundleBuild cannot be null."); return null; } try { return BuildAssetBundlesWithInfoInternal(outputPath, builds, assetBundleOptions, targetPlatform); } catch (Exception exception) { LogBuildExceptionAndExit("BuildPipeline.BuildAssetBundles", exception); return null; } }
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds) { BuildTarget targetPlatform = BuildTarget.WebPlayer; BuildAssetBundleOptions assetBundleOptions = BuildAssetBundleOptions.None; return BuildPipeline.BuildAssetBundles(outputPath, builds, assetBundleOptions, targetPlatform); }
//Builds the actual asset bundle. Only builds if files added & required information set in mod info fields bool BuildMod() { if (!ModInfoReady) return false; //get destination for mod modOutPutPath = EditorUtility.SaveFolderPanel("Select Destination,", Application.dataPath, ""); if (!Directory.Exists(modOutPutPath)) { return false; } else if (Assets == null || Assets.Count < 0) { return false; } //refresh AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); AssetBundleBuild[] buildMap = new AssetBundleBuild[1]; buildMap[0].assetBundleName = modInfo.ModFileName + ".dfmod"; buildMap[0].assetBundleVariant = ""; //TODO buildMap[0].assetNames = Assets.ToArray(); for (int i = 0; i < buildMap[0].assetNames.Length; i++ ) { string filePath = buildMap[0].assetNames[i]; if(!File.Exists(filePath)) { Debug.LogError("Asset not found: " + filePath); return false; } else { Debug.Log("Adding Asset: " + filePath); } //replace c# file with text asset if (filePath.ToLower().EndsWith(".cs")) { filePath = CreateNewTextAssetFromScript(filePath); buildMap[0].assetNames[i] = GetAssetPathFromFilePath(filePath); Debug.Log(string.Format("{0} {1}", i, filePath)); } } //build for every target in buildTarget array for (int i = 0; i < buildTargets.Length; i++) { string fullPath = Path.Combine(modOutPutPath, buildTargets[i].ToString()); if (!Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } BuildPipeline.BuildAssetBundles(fullPath, buildMap, BuildAssetBundleOptions.None, buildTargets[i]); } return true; }
public void Run(BuildTarget target, NodeData node, ConnectionPointData inputPoint, ConnectionData connectionToOutput, Dictionary<string, List<Asset>> inputGroupAssets, List<string> alreadyCached, Action<ConnectionData, Dictionary<string, List<Asset>>, List<string>> Output) { var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node); var bundleNames = inputGroupAssets.Keys.ToList(); var bundleVariants = new Dictionary<string, List<string>>(); // get all variant name for bundles foreach (var name in bundleNames) { bundleVariants[name] = new List<string>(); var assets = inputGroupAssets[name]; foreach(var a in assets) { var variantName = a.variantName; if(!bundleVariants[name].Contains(variantName)) { bundleVariants[name].Add(variantName); } } } int validNames = 0; foreach (var name in bundleNames) { var assets = inputGroupAssets[name]; // we do not build bundle without any asset if( assets.Count > 0 ) { validNames += bundleVariants[name].Count; } } AssetBundleBuild[] bundleBuild = new AssetBundleBuild[validNames]; int bbIndex = 0; foreach(var name in bundleNames) { foreach(var v in bundleVariants[name]) { var bundleName = name; var assets = inputGroupAssets[name]; if(assets.Count <= 0) { continue; } bundleBuild[bbIndex].assetBundleName = bundleName; bundleBuild[bbIndex].assetBundleVariant = v; bundleBuild[bbIndex].assetNames = assets.Where(x => x.variantName == v).Select(x => x.importFrom).ToArray(); ++bbIndex; } } BuildPipeline.BuildAssetBundles(bundleOutputDir, bundleBuild, (BuildAssetBundleOptions)node.BundleBuilderBundleOptions[target], target); var output = new Dictionary<string, List<Asset>>(); output[key] = new List<Asset>(); var generatedFiles = FileUtility.GetAllFilePathsInFolder(bundleOutputDir); // add manifest file bundleNames.Add( BuildTargetUtility.TargetToAssetBundlePlatformName(target) ); foreach (var path in generatedFiles) { var fileName = Path.GetFileName(path); if( IsFileIntendedItem(fileName, bundleNames) ) { output[key].Add( Asset.CreateAssetWithImportPath(path) ); } else { Debug.LogWarning(node.Name + ":Irrelevant file found in assetbundle cache folder:" + fileName); } } Output(connectionToOutput, output, alreadyCached); }
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions) { BuildTarget webPlayer = BuildTarget.WebPlayer; return BuildAssetBundles(outputPath, builds, assetBundleOptions, webPlayer); }