initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -0,0 +1,10 @@
|
|||
# Build Logging
|
||||
|
||||
Scriptable Build Pipeline has a profiling instrumentation system enabling build performance logging. By default, building AssetBundles will create a .json log file in the Trace Event Profiler Format within the target output directory. The file contains timing measurements of various build tasks and can be viewed using the [Trace Event Profiling Tool](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool).
|
||||
|
||||
The default logger can be overriden by passing in an [IBuildLogger](xref:UnityEditor.Build.Pipeline.Interfaces.IBuildLogger) object as a context object input. This could be useful if you want to log performance data in a different format or want the build events to be added to a custom performance repot. The [BuildLog](xref:UnityEditor.Build.Pipeline.Utilities.BuildLog) class implements [IBuildLogger](xref:UnityEditor.Build.Pipeline.Interfaces.IBuildLogger) and is used as the default logger.
|
||||
|
||||
|
||||
# Adding Custom Instrumentation
|
||||
|
||||
If you are creating or modifying build tasks that could affect build performance, you should consider adding instrumentation blocks to your new code. You can do this by calling the [IBuildLogger](xref:UnityEditor.Build.Pipeline.Interfaces.IBuildLogger) methods directly or using the [ScopedStep](xref:UnityEditor.Build.Pipeline.Interfaces.BuildLoggerExternsions) and [AddEntrySafe](xref:UnityEditor.Build.Pipeline.Interfaces.BuildLoggerExternsions) extension methods.
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ec79ccd8bee404e43a7f1c0d33241303
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,119 @@
|
|||
# About the Cache Server Client
|
||||
|
||||
Use the Cache Server Client to upload and download files to any Unity Cache Server. The Cache Server Client is used to communicate with a Unity Cache Server to store and retrieve incremental artifacts of the SBP build process, so that contents of the SBP build cache can be reused by multiple machines that are using the same project.
|
||||
|
||||
*Warning:* The [Unity Cache Server](https://docs.unity3d.com/Manual/CacheServer.html) has some performance limitations when dealing with a high volume of small cache entries. That can occur when performing large builds. The Cache Server is no longer under active development, as the Asset Import Pipeline now uses the [Unity Accelerator](https://docs.unity3d.com/Manual/UnityAccelerator.html). The Scriptable Build Pipeline retains the support to cache build artifacts through the Cache Server, as documented here, but this is not a recommended configuration.
|
||||
|
||||
The Unity Accelerator can speed up the Asset Import process when the same project is opened on different machines. But it does not support sharing artifacts stored in the local SBP build cache.
|
||||
|
||||
# Installation
|
||||
|
||||
To install this package, follow the instructions in the [Package Manager documentation](https://docs.unity3d.com/Packages/com.unity.package-manager-ui@latest/index.html).
|
||||
|
||||
# Usage
|
||||
## API Examples
|
||||
|
||||
This following example shows how to share build artifacts between team members or multiple machines to achieve faster build times.
|
||||
|
||||
Requirements:
|
||||
1. A Cache Server instance dedicated to build artifacts. In addition you may run an Accelerator to speed up Asset Imports.
|
||||
2. High Reliability mode turned off on the Build Cache Server instance. The build cache uses dynamic dependencies which is incompatible with high reliability mode.
|
||||
3. The build code must use the `ContentPipeline.BuildAssetBundles` method.
|
||||
4. `BundleBuildParameters.UseCache` is set to true.
|
||||
5. `BundleBuildParameters.CacheServerHost` and `BundleBuildParameters.CacheServerPort` are set to the cache server instance host or IP address and port respectively.
|
||||
|
||||
Example code:
|
||||
|
||||
```csharp
|
||||
public static class BuildAssetBundlesExample
|
||||
{
|
||||
public static bool BuildAssetBundles(string outputPath, bool useChunkBasedCompression, BuildTarget buildTarget, BuildTargetGroup buildGroup)
|
||||
{
|
||||
var buildContent = new BundleBuildContent(ContentBuildInterface.GenerateAssetBundleBuilds());
|
||||
var buildParams = new BundleBuildParameters(buildTarget, buildGroup, outputPath);
|
||||
// Set build parameters for connecting to the Cache Server
|
||||
buildParams.UseCache = true;
|
||||
buildParams.CacheServerHost = "buildcache.unitygames.com";
|
||||
buildParams.CacheServerPort = 8126;
|
||||
|
||||
if (useChunkBasedCompression)
|
||||
buildParams.BundleCompression = BuildCompression.DefaultLZ4;
|
||||
|
||||
IBundleBuildResults results;
|
||||
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParams, buildContent, out results);
|
||||
return exitCode == ReturnCode.Success;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Upload a file
|
||||
```csharp
|
||||
const string guidStr = "f7950ee725f9d47c7b90b02224b4534f";
|
||||
const string hashStr = "5082668810f105d565e2da3f8bf394ee";
|
||||
var fileId = FileId.From(guidStr, hashStr);
|
||||
|
||||
var client = new Client("localhost", 8126);
|
||||
client.Connect();
|
||||
|
||||
using(var stream = new FileStream())
|
||||
{
|
||||
client.BeginTransaction(fileId);
|
||||
client.Upload(FileType.Asset, stream);
|
||||
client.EndTransaction();
|
||||
}
|
||||
|
||||
client.Close();
|
||||
```
|
||||
### Download a file
|
||||
```csharp
|
||||
const string guidStr = "f7950ee725f9d47c7b90b02224b4534f";
|
||||
const string hashStr = "5082668810f105d565e2da3f8bf394ee";
|
||||
var fileId = FileId.From(guidStr, hashStr);
|
||||
var filePath = "/target/filename";
|
||||
|
||||
var client = new Client("localhost", 8126);
|
||||
client.Connect();
|
||||
|
||||
// FileDownloadItem implements IDownloadItem
|
||||
var downloadItem = new FileDownloadItem(fileId, FileType.Asset, filePath);
|
||||
client.QueueDownload(downloadItem);
|
||||
|
||||
client.DownloadFinished += (object sender, DownloadFinishedEventArgs args) =>
|
||||
{
|
||||
DownloadResult result = args.Result;
|
||||
long size = args.Size;
|
||||
long queueLength = args.DownloadQueueLength;
|
||||
};
|
||||
|
||||
client.ResetDownloadFinishedEventHandler(); // cleanup
|
||||
client.Close();
|
||||
```
|
||||
## Advanced
|
||||
|
||||
### IDownloadItem
|
||||
|
||||
Implement `IDownloadItem` to download vai WriteStream to a custom location.
|
||||
## Utilities
|
||||
### Upload All Assets
|
||||
Quickly seed a local or remote cache server with the current project's imported assets.
|
||||
|
||||
1) From the Unity Editor toolbar, select `Assets -> Cache Server -> Upload All Assets`
|
||||
2) Input the destination Cache Server. The currently configured global Unity Editor setting will be used by default.
|
||||
3) Press Upload - for large projects, a progress dialog will display during the upload.
|
||||
|
||||
Or frome the Command Line:
|
||||
|
||||
`Unity -projectPath [projectPath] -ExecuteMethod Unity.CacheServer.CacheServerUploader.UploadAllFilesToCacheServer -batchmode -quit`
|
||||
|
||||
# Technical details
|
||||
## Requirements
|
||||
|
||||
This version of the Cache Server Client is compatible with the following versions of the Unity Editor:
|
||||
|
||||
* 2017.1 and later (recommended)
|
||||
* 5.6 and earlier may work but are untested
|
||||
|
||||
This Cache Server Client is compatible with the following versions of the Unity Cache Server:
|
||||
* [v5.x](https://github.com/Unity-Technologies/unity-cache-server) and later (recommended)
|
||||
* Other Cache Server versions shipped with Unity 5.x and later
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 263aa93ee5f983b4283c7875c4ffac5d
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,19 @@
|
|||
# Getting started with Scriptable Build Pipeline
|
||||
|
||||
## Installing the Scriptable Build Pipeline (SBP) package
|
||||
|
||||
Requires Unity 2018.3 or later.
|
||||
|
||||
To install this package, follow the instructions in the [Package Manager documentation](https://docs.unity3d.com/Packages/com.unity.package-manager-ui@latest).
|
||||
|
||||
To build an AssetBundle, use the ContentPipeline.BuildAssetBundles() method. In its simplest form, you supply the following parameters:
|
||||
|
||||
* Build Parameters - An object that implements the `IBuildParameters` interface. The object specifies the BuildTarget, the BuildTargetGroup, the output path, and additional optional properties.
|
||||
|
||||
* The content to build - An object that implements the `IBundleBuildContent` interface. The object specifies the content to build (the assets) and its layout (what assets in which bundles.)
|
||||
|
||||
* A results object - An object that implements the `IBundleBuildResults` interface. The object receives the details of the built AssetBundles.
|
||||
|
||||
**Note:** The `UnityEditor.Build.Pipeline` namespace contains default implementations for all of the SBP required interfaces. Implementation names mirror the interfaces, with the leading 'I' removed. For example, the `IBuildParameters` interface is implemented as `BuildParameters`.
|
||||
|
||||
To quickly switch to building AssetBundles with SBP, use the `CompatibilityBuildPipeline.BuildAssetBundles()` method as a drop in replacement for calls to `BuildPipeline.BuildAssetBundles()` in your existing code. See also [Usage Examples](UsageExamples.md) and [Upgrade Guide](UpgradeGuide.md).
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2541c70242aefc448851603446fd4982
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,7 @@
|
|||
* [Scriptable Build Pipeline](index.md)
|
||||
* [Getting Started](GettingStarted.md)
|
||||
* [Terminology](Terminology.md)
|
||||
* [Usage Examples](UsageExamples.md)
|
||||
* [Upgrade Guide](UpgradeGuide.md)
|
||||
* [Unity Cache Server](CacheServerClient.md)
|
||||
* [Build Log](BuildLogger.md)
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6b2e26372b35c4f47a102f1defd27ccb
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,11 @@
|
|||
# Terminology
|
||||
|
||||
**Asset** - A source file on disk, typically located in the Project’s Assets folder. This file is imported to a game-ready representation of your Asset internally which can contain multiple Objects.
|
||||
|
||||
**Object** - A single Unity serializable unit. All Unity Objects derive from [UnityEngine.Object](https://docs.unity3d.com/ScriptReference/Object.html). An imported Asset is made up of one or more Objects. For example a ScriptableObject Asset has a single Object, while a Prefab contains a heirarchy of GameObjects, Components and other Unity Objects.
|
||||
|
||||
**SubAsset** - An additional Asset that is stored inside an Asset file. See [AssetDatabase.AddObjectToAsset](https://docs.unity3d.com/ScriptReference/AssetDatabase.AddObjectToAsset.html) and [AssetBundle.LoadAssetWithSubAssets](https://docs.unity3d.com/ScriptReference/AssetBundle.LoadAssetWithSubAssets.html).
|
||||
|
||||
**Includes** - The set of Objects from which an Asset is constructed.
|
||||
|
||||
**References** - The unique set of Objects that are needed (referenced) by the Includes of an Asset, but not included in the Asset. For example a Material object inside a Material Asset can reference a Shader object inside a Shader Asset.
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1e6053f8fe15edc40965c55cac4e2bca
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,35 @@
|
|||
# Upgrade Guide
|
||||
|
||||
To build your AssetBundles with the SBP package, use the `CompatibilityBuildPipeline.BuildAssetBundles` method wherever you used the [BuildPipeline.BuildAssetBundle](https://docs.unity3d.com/ScriptReference/BuildPipeline.BuildAssetBundles.html) method.
|
||||
|
||||
**Note:** Not all of the features that were supported previously are supported in SBP.
|
||||
|
||||
The following tables list the features of the `CompatibilityBuildPipeline.BuildAssetBundles` method in comparison to the `BuildPipeline.BuildAssetBundle` method.
|
||||
|
||||
| Feature| Support | Notes |
|
||||
|:---|:---|:---|
|
||||
| AssetBundles| Supported | SBP builds AssetBundles built nearly identically to the previous build pipeline. You load them in a similar manner to how you currently load AssetBundles. |
|
||||
| Incremental Building | Supported | SBP implements this feature using the new `BuildCache` class. |
|
||||
| Asset loading path| Behavior changed | AssetBundles built with BuildPipeline today support loading an Asset by full path: *Assets/ExampleFolder/Asset.prefab*, file name: *Asset*, or file name with extension: *Asset.prefab*. However AssetBundles built with SBP by default only support loading an Asset by full path: *Assets/ExampleFolder/Asset.prefab*. This is to avoid loading collision that can occur if two Assets in the same AssetBundle have the different full paths, but the same file name. To change this behavior, the loading path can be set using `IBundleBuildContent.Addresses` with the `ContentPipeline.BuildAssetBundles` API or use the [AssetBundleBuild.addressableNames](https://docs.unity3d.com/ScriptReference/AssetBundleBuild-addressableNames.html) field. See [Usage Examples](UsageExamples.md). |
|
||||
| AssetBundle Manifest | Behavior changed | SBP does not write an AssetBundle storing the AssetBundleManifest object. SBP implements replacement functionality with the class `CompatibilityAssetBundleManifest`. This has an identical API to the existing [AssetBundleManifest](https://docs.unity3d.com/ScriptReference/AssetBundleManifest.html) class, plus the addition of a method to get the CRC value for a bundle.|
|
||||
| AssetBundle .manifest files | Behaviour changed | Builds performed with BuildPipeline.BuildAssetBundles output YAML-format files with the .manifest file extension that describe the content of each AssetBundle. SBP does not write .manifest files for individual AssetBundles. When CompatibilityBuildPipeline is used, SBP will serialize the CompatibilityAssetBundleManifest object to a .manifest with filename matching the build folder name. This file has similar, but not identical, content to the top level .manifest file that is generated by BuildPipeline.BuildAssetBundles. |
|
||||
| Code Stripping | Behaviour changed | SBP does not generate the .manifest file content that can be used in conjunction with [BuildPlayerOptions.assetBundleManifestPath](https://docs.unity3d.com/ScriptReference/BuildPlayerOptions-assetBundleManifestPath.html) to prevent Player builds from stripping out types that are only used in AssetBundles. Instead SBP supports generating an link.xml to achieve the same result.|
|
||||
| Build Report | Not supported | SBP does not generate a [BuildReport](https://docs.unity3d.com/ScriptReference/Build.Reporting.BuildReport.html) file. |
|
||||
| AssetBundle Variants| Not supported | There is currently no replacement functionality for AssetBundle Variants. |
|
||||
| Build Callbacks | Supported | SBP supports invoking the [IProcessSceneWithReport](https://docs.unity3d.com/ScriptReference/Build.IProcessSceneWithReport.html) and IPreprocessShaders build callbacks. |
|
||||
|
||||
BuildAssetBundleOptions Enum:
|
||||
|
||||
| Value| Support | Notes |
|
||||
|:---|:---|:---|
|
||||
| UncompressedAssetBundle| Supported | Identical to using `BuildCompression.DefaultUncompressed`. |
|
||||
| ChunkBasedCompression | Supported | Identical to using `BuildCompression.DefaultLZ4`. **Note:** This has always been LZ4HC in the Editor, and LZ4 if it was recompressed at Runtime. |
|
||||
| DisableWriteTypeTree | Supported | Identical to using `ContentBuildFlags.DisableWriteTypeTree`. |
|
||||
| DeterministicAssetBundle | Supported | This is enabled by default, and it can’t be disabled. SBP builds deterministically. |
|
||||
| ForceRebuildAssetBundle | Supported | Identical to using `IBuildParameters.UseCache = false;`. |
|
||||
| AppendHashToAssetBundleName | Supported | Identical to using `IBundleBuildParameters.AppendHash = true;`. |
|
||||
| DisableLoadAssetByFileName | Always enabled | This is enabled by default, and can’t be disabled. SBP is strict about the rule: "what you pass in is exactly what you get out". If you pass in *My/Example1/Example2/Asset.asset* as the file name to use to load the Asset, you must use that identifier exactly, including the correct upper and lower case, and all punctuation. |
|
||||
| DisableLoadAssetByFileNameWithExtension | Always enabled | See above details on DisableLoadAssetByFileName. |
|
||||
| IgnoreTypeTreeChanges | Not supported | The incremental build system used this value to prevent rebuilding AssetBundles when an Asset's serialization layout changed, but the data for the Asset itself did not change. SBP currently rebuilds if there are any changes. |
|
||||
| StrictMode | Not supported | The SBP is stricter about properly building AssetBundles and knowing when builds fail. |
|
||||
| DryRunBuild | Not supported | SBP works fundamentally differently. It is faster to do a full build to determine if anything has changed. |
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 266785459f1a968469d8d75029c09c7a
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,176 @@
|
|||
# Usage Examples
|
||||
|
||||
## Basic Example
|
||||
This example assumes that your are already familiar with the basic usage of `BuildPipeline.BuildAssetBundles` and want to switch to using Scriptable Build Pipeline with as little effort as possible.
|
||||
|
||||
The following code example shows how AssetBundles are currently built:
|
||||
|
||||
```csharp
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
|
||||
public static class BuildAssetBundlesExample
|
||||
{
|
||||
public static bool BuildAssetBundles(string outputPath, bool forceRebuild, bool useChunkBasedCompression, BuildTarget buildTarget)
|
||||
{
|
||||
var options = BuildAssetBundleOptions.None;
|
||||
if (useChunkBasedCompression)
|
||||
options |= BuildAssetBundleOptions.ChunkBasedCompression;
|
||||
|
||||
if (forceRebuild)
|
||||
options |= BuildAssetBundleOptions.ForceRebuildAssetBundle;
|
||||
|
||||
Directory.CreateDirectory(outputPath);
|
||||
var manifest = BuildPipeline.BuildAssetBundles(outputPath, options, buildTarget);
|
||||
return manifest != null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
To update the previous code example to use SBP instead, add a new `using UnityEditor.Build.Pipeline` and replace the call to `BuildPipeline.BuildAssetBundles` with `CompatibilityBuildPipeline.BuildAssetBundles` as shown below:
|
||||
|
||||
```csharp
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
// Added new using
|
||||
using UnityEditor.Build.Pipeline;
|
||||
|
||||
public static class BuildAssetBundlesExample
|
||||
{
|
||||
public static bool BuildAssetBundles(string outputPath, bool forceRebuild, bool useChunkBasedCompression, BuildTarget buildTarget)
|
||||
{
|
||||
var options = BuildAssetBundleOptions.None;
|
||||
if (useChunkBasedCompression)
|
||||
options |= BuildAssetBundleOptions.ChunkBasedCompression;
|
||||
|
||||
if (forceRebuild)
|
||||
options |= BuildAssetBundleOptions.ForceRebuildAssetBundle;
|
||||
|
||||
Directory.CreateDirectory(outputPath);
|
||||
// Replaced BuildPipeline.BuildAssetBundles with CompatibilityBuildPipeline.BuildAssetBundles here
|
||||
var manifest = CompatibilityBuildPipeline.BuildAssetBundles(outputPath, options, buildTarget);
|
||||
return manifest != null;
|
||||
}
|
||||
}
|
||||
```
|
||||
**Notes:** Some changes in the SBP building and loading process do not match the BuildPipeline behavior. For more information on these changes, see [Upgrade Guide](UpgradeGuide.md).
|
||||
|
||||
## Per-Bundle Compression Example
|
||||
The following example shows how to build your AssetBundles using different compression levels for each AssetBundle.This is useful if you are planning on shipping part of your bundles as Lz4 or Uncompressed with Player and want to download the remainder as Lzma later.
|
||||
|
||||
The simplest implementation is to create a custom build parameters class that inherits from `BundleBuildParameters` and override the `GetCompressionForIdentifier` method. Then construct and pass this into the `ContentPipeline.BuildAssetBundles` method.
|
||||
|
||||
```csharp
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Content;
|
||||
using UnityEditor.Build.Pipeline;
|
||||
using UnityEditor.Build.Pipeline.Interfaces;
|
||||
|
||||
public static class BuildAssetBundlesExample
|
||||
{
|
||||
// New parameters class inheriting from BundleBuildParameters
|
||||
class CustomBuildParameters : BundleBuildParameters
|
||||
{
|
||||
public Dictionary<string, BuildCompression> PerBundleCompression { get; set; }
|
||||
|
||||
public CustomBuildParameters(BuildTarget target, BuildTargetGroup group, string outputFolder) : base(target, group, outputFolder)
|
||||
{
|
||||
PerBundleCompression = new Dictionary<string, BuildCompression>();
|
||||
}
|
||||
|
||||
// Override the GetCompressionForIdentifier method with new logic
|
||||
public override BuildCompression GetCompressionForIdentifier(string identifier)
|
||||
{
|
||||
BuildCompression value;
|
||||
if (PerBundleCompression.TryGetValue(identifier, out value))
|
||||
return value;
|
||||
return BundleCompression;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool BuildAssetBundles(string outputPath, bool useChunkBasedCompression, BuildTarget buildTarget, BuildTargetGroup buildGroup)
|
||||
{
|
||||
var buildContent = new BundleBuildContent(ContentBuildInterface.GenerateAssetBundleBuilds());
|
||||
// Construct the new parameters class
|
||||
var buildParams = new CustomBuildParameters(buildTarget, buildGroup, outputPath);
|
||||
// Populate the bundle specific compression data
|
||||
buildParams.PerBundleCompression.Add("Bundle1", BuildCompression.DefaultUncompressed);
|
||||
buildParams.PerBundleCompression.Add("Bundle2", BuildCompression.DefaultLZMA);
|
||||
|
||||
if (m_Settings.compressionType == CompressionType.None)
|
||||
buildParams.BundleCompression = BuildCompression.DefaultUncompressed;
|
||||
else if (m_Settings.compressionType == CompressionType.Lzma)
|
||||
buildParams.BundleCompression = BuildCompression.DefaultLZMA;
|
||||
else if (m_Settings.compressionType == CompressionType.Lz4 || m_Settings.compressionType == CompressionType.Lz4HC)
|
||||
buildParams.BundleCompression = BuildCompression.DefaultLZ4;
|
||||
|
||||
IBundleBuildResults results;
|
||||
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParams, buildContent, out results);
|
||||
return exitCode == ReturnCode.Success;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Load By File Name Example
|
||||
The following example shows how to use the `CompatibilityBuildPipeline` methods to load by a filename instead of the full path.
|
||||
|
||||
The example uses the `ContentBuildInterface.GenerateAssetBundleBuilds()` method to get the set of bundles and assets to build, then modifies `addressableNames` field to set the loading path of the filename instead of the full path.
|
||||
|
||||
```csharp
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Content;
|
||||
using UnityEditor.Build.Pipeline;
|
||||
|
||||
public static class BuildAssetBundlesExample
|
||||
{
|
||||
public static bool BuildAssetBundles(string outputPath, bool forceRebuild, bool useChunkBasedCompression, BuildTarget buildTarget)
|
||||
{
|
||||
var options = BuildAssetBundleOptions.None;
|
||||
if (useChunkBasedCompression)
|
||||
options |= BuildAssetBundleOptions.ChunkBasedCompression;
|
||||
|
||||
if (forceRebuild)
|
||||
options |= BuildAssetBundleOptions.ForceRebuildAssetBundle;
|
||||
|
||||
// Get the set of bundle to build
|
||||
var bundles = ContentBuildInterface.GenerateAssetBundleBuilds();
|
||||
// Update the addressableNames to load by the file name without extension
|
||||
for (var i = 0; i < bundles.Length; i++)
|
||||
bundles[i].addressableNames = bundles[i].assetNames.Select(Path.GetFileNameWithoutExtension).ToArray();
|
||||
|
||||
var manifest = CompatibilityBuildPipeline.BuildAssetBundles(m_Settings.outputPath, bundles, options, m_Settings.buildTarget);
|
||||
return manifest != null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Building Archives that Contain ContentFiles
|
||||
The following example shows how to build Archive files that contain ContentFiles by using the `DefaultBuildTasks.ContentFileCompatible` as the tasks for building
|
||||
|
||||
Using `ContentFileIdentifiers` is required, otherwise the resulting AssetBundles will not be able to load.
|
||||
|
||||
Requires Unity 2022.2 or later.
|
||||
```csharp
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Content;
|
||||
using UnityEditor.Build.Pipeline;
|
||||
using UnityEditor.Build.Pipeline.Tasks;
|
||||
using UnityEditor.Build.Pipeline.Utilities;
|
||||
|
||||
public class BuildAssetBundlesExample
|
||||
{
|
||||
public static bool BuildAssetBundles(string outputPath, bool useChunkBasedCompression, BuildTarget buildTarget, BuildTargetGroup buildGroup)
|
||||
{
|
||||
var buildContent = new BundleBuildContent(ContentBuildInterface.GenerateAssetBundleBuilds());
|
||||
var buildParams = new BundleBuildParameters(buildTarget, buildGroup, outputPath);
|
||||
if (useChunkBasedCompression)
|
||||
buildParams.BundleCompression = UnityEngine.BuildCompression.LZ4;
|
||||
|
||||
var tasks = DefaultBuildTasks.ContentFileCompatible();
|
||||
var buildLayout = new ClusterOutput();
|
||||
var exitCode = ContentPipeline.BuildAssetBundles(buildParams, buildContent, out _, tasks, new ContentFileIdentifiers(), buildLayout);
|
||||
return exitCode == ReturnCode.Success;
|
||||
}
|
||||
}
|
||||
```
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0d142c6ddde5f86428c60bc924edae0e
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
# Unity Scriptable Build Pipeline
|
||||
|
||||
The Scriptable Build Pipeline (SBP) package allows you to control how Unity builds content. The package moves the previously C++-only build pipeline code to a public C# package with a pre-defined build flow for building AssetBundles. The pre-defined AssetBundle build flow reduces build time, improves incremental build processing, and provides greater flexibility than before.
|
||||
|
||||
The [Addressables](https://docs.unity3d.com/Packages/com.unity.addressables@latest) package uses the Scriptable Build Pipeline to build AssetBundles. For new projects it is recommended to use Addressables for your builds, rather than directly building AssetBundles using the Scriptable Build Pipeline.
|
||||
|
||||
If your project currently uses [BuildPipeline.BuildAssetBundle](https://docs.unity3d.com/ScriptReference/BuildPipeline.BuildAssetBundles.html) to build AssetBundles then you can update your build scripts to use the Scriptable Build Pipeline instead. See the [Upgrade Guide](UpgradeGuide.md) for more details.
|
||||
|
||||
The Scriptable Build Pipeline also makes it possible to customize the build process with your own build flows, derived classes and other code that you write to run during the build itself. However, this type of customization is intended for advanced use cases and it can present challenges when upgrading to newer versions of the Scriptable Build Pipeline. For example, changes to the underlying package and DefaultBuildTasks may not be compatible with your customizations. So when possible, it can be more practical to write your custom build script to perform actions before and after the AssetBundle build, rather than seeking to inject a lot of custom code directly into the build itself.
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0f39cb52d59e44a40b4cf36f34ccae52
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue