protected static AssetBundleBuild[] GetBuildList(EZBundleObject ezBundle) { List <AssetBundleBuild> buildList = new List <AssetBundleBuild>(); foreach (EZBundleObject.BundleInfo ezBundleInfo in ezBundle.bundleList) { if (ezBundleInfo.bundleName == "") { continue; } if (ezBundleInfo.filePattern == "") { ezBundleInfo.filePattern = "*.*"; } string[] files = Directory.GetFiles(ezBundleInfo.dirPath, ezBundleInfo.filePattern, ezBundleInfo.searchOption); for (int i = 0; i < files.Length; i++) { files[i] = files[i].Replace('\\', '/'); } AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = ezBundleInfo.bundleName; build.assetNames = files; buildList.Add(build); } return(buildList.ToArray()); }
public static void BuildBundle(EZBundleObject ezBundle, bool managerMode) { OnPreBuild(); if (ezBundle.forceRebuild && Directory.Exists(ezBundle.outputPath)) { Directory.Delete(ezBundle.outputPath, true); } Directory.CreateDirectory(ezBundle.outputPath); AssetDatabase.Refresh(); CopyDirectories(ezBundle); AssetDatabase.Refresh(); if (managerMode) { OnPostBuild(BuildPipeline.BuildAssetBundles(ezBundle.outputPath, buildOptions, ezBundle.buildTarget)); } else { OnPostBuild(BuildPipeline.BuildAssetBundles(ezBundle.outputPath, GetBuildList(ezBundle), buildOptions, ezBundle.buildTarget)); } if (!string.IsNullOrEmpty(ezBundle.listFileName)) { CreateFileList(ezBundle.outputPath, ezBundle.listFileName); } AssetDatabase.Refresh(); Debug.Log("build complete."); }
protected static void CopyDirectories(EZBundleObject ezBundle) { foreach (EZBundleObject.CopyInfo copyInfo in ezBundle.copyList) { string sour = copyInfo.sourDirPath; string dest = copyInfo.destDirPath; if (string.IsNullOrEmpty(sour) || string.IsNullOrEmpty(dest)) { continue; } if (!Directory.Exists(sour)) { return; } Directory.CreateDirectory(dest); string[] files = Directory.GetFiles(sour); foreach (string filePath in files) { if (filePath.EndsWith(".meta")) { continue; } string newPath = dest + filePath.Replace(sour, ""); Directory.CreateDirectory(Path.GetDirectoryName(newPath)); File.Copy(filePath, newPath, true); } } }