private static void ExportPackedExportable(string path, string exportPath) { System.Diagnostics.Stopwatch watcher = new System.Diagnostics.Stopwatch(); watcher.Start(); exportTimes++; if (!File.Exists(path)) { return; } if (path.EndsWith(".unity")) { #if UNITY_IPHONE BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { path }, exportPath, BuildTarget.iOS); #else BuildPipeline.BuildStreamedSceneAssetBundle(new string[] { path }, exportPath, ExportScenesManager.CurrentBuildTarget); #endif } else { var obj = AssetDatabase.LoadMainAssetAtPath(path); #if UNITY_IPHONE if (!BuildPipeline.BuildAssetBundle(obj, null, exportPath, Options, BuildTarget.iOS)) #else if (!BuildPipeline.BuildAssetBundle(obj, null, exportPath, Options, ExportScenesManager.CurrentBuildTarget)) #endif { throw new InvalidOperationException(exportPath + " 导出失败。"); } } watcher.Stop(); ExportScenesManager.LogDebug(exportTimes + "/" + m_dependencyTree.Count + ":" + watcher.ElapsedMilliseconds + " " + path); }
public static void ExportAllBundles() { ExportScenesManager.AutoSwitchTarget(); string path = "Assets/Resources/GUI"; var rootPath = ExportScenesManager.GetFolderPath(ExportScenesManager.SubMogoResources); fileList.Clear(); GetSubDir(path); var files = fileList.Select(x => x.Replace('\\', '/')).Where(x => x.EndsWith(".prefab")).ToArray(); ExportScenesManager.LogDebug(files.PackArray('\n')); BuildBundleWithRoot(files, rootPath, true); }
private static void ExportBundle(string[] files, string exportRootPath) { Clean(); BuildDependencyTree(files); var sorted = (from dependency in m_dependencyTree group dependency by dependency.Value into g select new { Layer = g.Key, Dependencies = from pair in g select pair.Key }) .OrderByDescending((x) => x.Layer); Debug.Log("statck depth will be " + sorted.Count()); for (int i = 0; i < sorted.Count(); ++i) { BuildPipeline.PushAssetDependencies(); foreach (string dependency in sorted.ElementAt(i).Dependencies) { Debug.Log("layer " + i + " build " + dependency); ExportScenesManager.LogDebug(dependency); var relativePath = GetRelativePath(dependency); //var exportFileName = ResourceManager.GetExportFileName(relativePath); var exportPath = string.Concat(exportRootPath, "/", relativePath); //Debug.Log(exportPath); var exportDirectory = Path.GetDirectoryName(exportPath); if (!Directory.Exists(exportDirectory)) { Directory.CreateDirectory(exportDirectory); } IEnumerable <string> lowerDependencies = null; if (i < sorted.Count() && i > 0 && dependenciesDic.ContainsKey(dependency) && dependenciesDic[dependency].Count != 0) // { lowerDependencies = sorted.ElementAt(i - 1).Dependencies.Where(t => dependenciesDic[dependency].Contains(t)); //修改成获取精确依赖 } if (ExportBundleWithoutMetaData(dependency, Mogo.Util.ResourceManager.WithSuffix(exportPath))) { WriteMetaData(exportRootPath, relativePath, lowerDependencies, exportRootPath); ExportScenesManager.LogDebug(exportPath + " 导出成功。"); } } } for (int i = 0; i < sorted.Count(); ++i) { BuildPipeline.PopAssetDependencies(); } }
public static void BuildBundleWithRoot(string[] roots, string exportRootPath, bool isMerge = false) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); if (isMerge) { ExportBundle(roots, exportRootPath); } else { foreach (var item in roots) { ExportBundle(new string[] { item }, exportRootPath); } } sw.Stop(); ExportScenesManager.LogDebug("cost time: " + sw.ElapsedMilliseconds); }
public static void BuildAssetVersion(string[] files, string rootPath) { Clean(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); BuildDependencyTree(files); sw.Stop(); ExportScenesManager.LogDebug("BuildDependencyTree time: " + sw.ElapsedMilliseconds); //Debug.Log(m_dependencyTree.PackMap(':', '\n')); var sorted = (from dependency in m_dependencyTree group dependency by dependency.Value into g select new { Layer = g.Key, Dependencies = from pair in g select pair.Key }) .OrderByDescending((x) => x.Layer); var count = sorted.Count(); ExportScenesManager.LogDebug("sorted.Count: " + count); for (int i = 0; i < count; ++i) { foreach (var dependency in sorted.ElementAt(i).Dependencies) { var relativePath = GetRelativePath(dependency); //Debug.Log("relativePath: " + relativePath); //var exportFileName = ResourceManager.GetExportFileName(relativePath); var exportPath = string.Concat(rootPath, "/", relativePath); //Debug.Log("exportPath: " + exportPath); //Debug.Log(exportPath); var exportDirectory = Path.GetDirectoryName(exportPath); if (!Directory.Exists(exportDirectory)) { Directory.CreateDirectory(exportDirectory); } IEnumerable <string> lowerDependencies = null; if (i < sorted.Count() && i > 0 && dependenciesDic.ContainsKey(dependency) && dependenciesDic[dependency].Count != 0) { lowerDependencies = sorted.ElementAt(i - 1).Dependencies.Where(t => dependenciesDic[dependency].Contains(t));//修改成获取精确依赖 } WriteMetaData(rootPath, relativePath, lowerDependencies, Application.dataPath, false); //Debug.Log(exportPath + " 生成成功。"); } } }