using System; using System.Collections.Generic; using UnityEditor.Build.Pipeline.Interfaces; using UnityEditor.Build.Pipeline.Tasks; namespace UnityEditor.Build.Pipeline { /// /// Basic static class containing preset build pipeline task collections. /// public static class DefaultBuildTasks { /// /// Options for different preset build pipelines /// public enum Preset { /// /// Use to indicate that the pipeline only executes player scripts. /// PlayerScriptsOnly, /// /// Use to indicate that the pipeline should create asset bundles. /// AssetBundleCompatible, /// /// Use to indicate that the pipeline should create asset bundles and the built-in shader bundle. /// AssetBundleBuiltInShaderExtraction, /// /// Use to indicate that the pipeline should create asset bundles, the built-in shader bundle, and MonoScript bundle. /// AssetBundleShaderAndScriptExtraction, } /// /// Constructs and returns an IList containing the build tasks in the correct order for the preset build pipeline. /// /// The preset build pipeline to construct and return. /// IList containing the build tasks in the correct order for the preset build pipeline. public static IList Create(Preset preset) { switch (preset) { case Preset.PlayerScriptsOnly: return PlayerScriptsOnly(); case Preset.AssetBundleCompatible: return AssetBundleCompatible(false, false); case Preset.AssetBundleBuiltInShaderExtraction: return AssetBundleCompatible(true, false); case Preset.AssetBundleShaderAndScriptExtraction: return AssetBundleCompatible(true, true); default: throw new NotImplementedException(string.Format("Preset for '{0}' not yet implemented.", preset)); } } static IList PlayerScriptsOnly() { var buildTasks = new List(); // Setup buildTasks.Add(new SwitchToBuildPlatform()); // Player Scripts buildTasks.Add(new BuildPlayerScripts()); buildTasks.Add(new PostScriptsCallback()); // Dependency // - Empty // Packing // - Empty // Writing // - Empty return buildTasks; } static IList AssetBundleCompatible(bool shaderTask, bool monoscriptTask) { var buildTasks = new List(); // Setup buildTasks.Add(new SwitchToBuildPlatform()); buildTasks.Add(new RebuildSpriteAtlasCache()); // Player Scripts buildTasks.Add(new BuildPlayerScripts()); buildTasks.Add(new PostScriptsCallback()); // Dependency buildTasks.Add(new CalculateSceneDependencyData()); #if UNITY_2019_3_OR_NEWER buildTasks.Add(new CalculateCustomDependencyData()); #endif buildTasks.Add(new CalculateAssetDependencyData()); buildTasks.Add(new StripUnusedSpriteSources()); if (shaderTask) buildTasks.Add(new CreateBuiltInShadersBundle("UnityBuiltInShaders.bundle")); if (monoscriptTask) buildTasks.Add(new CreateMonoScriptBundle("UnityMonoScripts.bundle")); buildTasks.Add(new PostDependencyCallback()); // Packing buildTasks.Add(new GenerateBundlePacking()); if (shaderTask || monoscriptTask) buildTasks.Add(new UpdateBundleObjectLayout()); buildTasks.Add(new GenerateBundleCommands()); buildTasks.Add(new GenerateSubAssetPathMaps()); buildTasks.Add(new GenerateBundleMaps()); buildTasks.Add(new PostPackingCallback()); // Writing buildTasks.Add(new WriteSerializedFiles()); buildTasks.Add(new ArchiveAndCompressBundles()); buildTasks.Add(new AppendBundleHash()); buildTasks.Add(new GenerateLinkXml()); buildTasks.Add(new PostWritingCallback()); return buildTasks; } #if UNITY_2022_2_OR_NEWER public static IList ContentFileCompatible() { var buildTasks = new List(); // Setup buildTasks.Add(new SwitchToBuildPlatform()); buildTasks.Add(new RebuildSpriteAtlasCache()); // Player Scripts buildTasks.Add(new BuildPlayerScripts()); buildTasks.Add(new PostScriptsCallback()); // Dependency buildTasks.Add(new CalculateSceneDependencyData()); buildTasks.Add(new CalculateCustomDependencyData()); buildTasks.Add(new CalculateAssetDependencyData()); buildTasks.Add(new StripUnusedSpriteSources()); buildTasks.Add(new PostDependencyCallback()); // Packing buildTasks.Add(new ClusterBuildLayout()); buildTasks.Add(new PostPackingCallback()); // Writing buildTasks.Add(new WriteSerializedFiles()); buildTasks.Add(new ArchiveAndCompressBundles()); buildTasks.Add(new GenerateLinkXml()); buildTasks.Add(new PostWritingCallback()); return buildTasks; } #endif } }