Scriptable Build Pipeline - 2018.2 入门指南

2024-05-03 21:08

本文主要是介绍Scriptable Build Pipeline - 2018.2 入门指南,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

                   相关文章暂时还是太少了~  

        转载自:https://docs.google.com/document/d/1uuiEDV7WqpHEylzE4GQwOztCttrwPu6ak0kfELz6ilc/edit#

https://docs.unity3d.com/2018.2/Documentation/ScriptReference/Build.Player.PlayerBuildInterface.html   

https://docs.unity3d.com/Packages/com.unity.scriptablebuildpipeline@0.0-preview/api/UnityEditor.Build.Pipeline.html   

Addressable资源系统的文档可以点击下面来查看:
 https://docs.unity3d.com/Packages/com.unity.addressables@0.2/manual/index.html

==================================================  先个示例代码 =====================

Scriptable Build Pipeline 大多数都是使用 BuildTaskRunnerIBuildTaskIContextObject 类实现功能。

  • IContextObject: 存储数据的接口。
  • IBuildTask: 负责处理构建的接口。BuildTaskRunner按照他们在任务列表Run()中注册的顺序。要使用的数据会[InjectContext]自动注入现场。
  • BuildTaskRunner:执行构建的类

下面的代码只是一个简单的代码,可以注册字母,获取注册的字母并显示它们。

先安装插件:

                    (看到很多文章 说路径在  项目的 Library/ PackageCache  路径下,  但是并没有这个路径呀~~)

或者这样单独添加也行 : 

还要做一件事情:   做一下拷贝 (为什么要做这个拷贝?“我之前的文章   Unity3d 周分享 第x期 ,提到过,方便查看源码,  为了设断点调试   虽然一些反编译工具也可以做到, 但是 设断点查看它的内部执行过程这样做很方便~”  )

  

在 Legacy Build Pipeline 中, 能看到   应该是Unity 5系列的 AB 构建流程 。 

还有  类 DefaultBuildTasks.cs  中

   Demo

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.Build.Pipeline.Interfaces;
using UnityEditor.Build.Pipeline;
using UnityEditor.Build.Pipeline.Injector;
using UnityEngine.Assertions;public static class BuildTest
{// 菜单栏[MenuItem("Build/test build")]static void Build(){//注册上下文//此处注册的上下文用于TaskBuildContext buildContext = new BuildContext();buildContext.SetContextObject<IMyContextData>(new MyContextData { message = "hoge" });//创建任务//任务使用的参数是从上下文中获取的。//任务注册顺序=任务执行顺序IList<IBuildTask> taskList = new List<IBuildTask>();taskList.Add(new DisplayNameTask());//实际执行该过程var result = BuildTasksRunner.Run(taskList, buildContext);Assert.AreEqual(ReturnCode.Success, result);}
}//使用BuildTasksRunner注册的任务
class DisplayNameTask : IBuildTask
{//注入匹配接口的上下文// ContextUsage.In:使用从BuildContext注册的那个// ContextUsage.Out:注册在Run中创建的上下文[InjectContext(ContextUsage.In)]IMyContextData data = null;public int Version { get { return 1; } }public ReturnCode Run(){//仅显示字符的任务//实际上收集对象并更新/生成上下文Debug.Log(data.Name);return ReturnCode.Success;}
}//这次使用的字符数据接口
//在DisplayNameTask上使用InjectContext
public interface IMyContextData : IContextObject
{string Name { get; }
}//上下文数据的实体
public class MyContextData : IMyContextData
{public string message = null;public string Name => message;
}

 

 

======================================================

Note to readers: this content is for the Scriptable Build Pipeline package and will reside in the package documentation at
https://docs.unity3d.com/Manual/PackagesList.html

Documentation source will reside at
https://gitlab.internal.unity3d.com/build-pipeline/AddressablesDemo/tree/master/AddressablesDemo/Packages/com.unity.scriptablebuildpipeline/Documentation

Table of Contents (tableofcontents.md)

Unity Scriptable Build Pipeline (index.md)

  • Getting started with Scriptable Build Pipeline (gettingstarted.md)

  • Terminology (terminology.md)

  • Usage Examples (usageexamples.md)

  • Upgrade Guide (upgradeguide.md)

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.

 

If you are moving from using BuildPipeline methods to the SBP, see the Usage Examples and Upgrade Guide.

 

Getting started with Scriptable Build Pipeline

Installing the Scriptable Build Pipeline (SBP) package

Requires Unity 2018.2 or later.

To install this package, follow the instructions in the Package Manager documentation.

To build AssetBundles, 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 existing code. This method has the nearly identical parameters as the BuildPipeline.BuildAssetBundles() method. For additional information, see the Usage Examples and Upgrade Guide.

 

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 (SubAssets.)

 

Object (SubAsset) - A single Unity serializable unit. Also known as a SubAsset. An imported Asset is made up of one or more Objects.

 

Includes - The unique 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.

 

Usage Examples

Basic Example

This example assumes that your are already familiar with the basic usage of the two BuildPipeline.BuildAssetBundles methods 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:

 

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, replace the call to BuildPipeline.BuildAssetBundles with CompatibilityBuildPipeline.BuildAssetBundles as shown below:

 

using System.IO;

using UnityEditor;

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);

       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 the Upgrade Guide.

 

Cache Server Integration Example

This following example shows how to share build artifacts between team members or multiple machines to achieve faster build times.

 

Requirements:

  1. A separate Cache Server instance dedicated to build artifacts. It cannot be shared as an Asset Cache Server as data collisions will occur.

  2. The build code must use the ContentPipeline.BuildAssetBundles method.

  3. BundleBuildParameters.UseCache is set to true.

  4. BundleBuildParameters.CacheServerHost and BundleBuildParameters.CacheServerPort are set to the cache server instance host or IP address and port respectively.

 

Example code:

 

using UnityEditor;

using UnityEditor.Build.Content;

using UnityEditor.Build.Pipeline;

using UnityEditor.Build.Pipeline.Interfaces;

 

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);

       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;

   }

}

 

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.

 

using UnityEditor;

using UnityEditor.Build.Content;

using UnityEditor.Build.Pipeline;

using UnityEditor.Build.Pipeline.Interfaces;

 

public static class BuildAssetBundlesExample

{

   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>();

       }

 

       public new 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());

       var buildParams = new CustomBuildParameters(buildTarget, buildGroup, outputPath);

       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 Filename 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.

 

using System.IO;

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;

 

       var bundles = ContentBuildInterface.GenerateAssetBundleBuilds();

       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;

   }

}

 

Custom Build Task Example

 

// TODO: make code example

 

Assign Built-In Objects to Bundles Example

 

// TODO: Maybe this should just be built-in shader extraction?

 

Upgrade Guide

To build your AssetBundles with the SBP package, use the CompatibilityBuildPipeline.BuildAssetBundles method wherever you used the BuildPipeline.BuildAssetBundle 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 that are 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 BuildCache.

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 API or AssetBundleBuild.addressableNames field. See Code Examples.

AssetBundle Manifest

Behavior changed

SBP implements replacement functionality using the new class name CompatibilityAssetBundleManifest. This has an identical API to the existing AssetBundleManifest class, and has an additional method to get the CRC value for a bundle which did not exist before.

AssetBundle Variants

Not supported

There is currently no replacement functionality for AssetBundle Variants.



 

BuildAssetBundleOptions Enum:

 

Value

Support

Notes

UncompressedAssetBundle

Supported

Identical to using BuildCompression.DefaultUncompressed with the new API.

ChunkBasedCompression

Supported

Identical to using BuildCompression.DefaultLZ4 with the new API.

Note: This has always been LZ4HC in the Editor, and LZ4 if it was recompressed at Runtime.

DisableWriteTypeTree

Supported

Identical to using ContentBuildFlags.DisableWriteTypeTree with the new API.

DeterministicAssetBundle

Supported

This is enabled by default, and it can’t be disabled. SBP builds deterministically.

ForceRebuildAssetBundle

Supported

Identical to using IBuildParameters.UseCache = false; with the new API.

AppendHashToAssetBundleName

Supported

Identical to using IBundleBuildParameters.AppendHash = true; with the new API.

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.



 

 

这篇关于Scriptable Build Pipeline - 2018.2 入门指南的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/957654

相关文章

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Retrieval-based-Voice-Conversion-WebUI模型构建指南

一、模型介绍 Retrieval-based-Voice-Conversion-WebUI(简称 RVC)模型是一个基于 VITS(Variational Inference with adversarial learning for end-to-end Text-to-Speech)的简单易用的语音转换框架。 具有以下特点 简单易用:RVC 模型通过简单易用的网页界面,使得用户无需深入了

数论入门整理(updating)

一、gcd lcm 基础中的基础,一般用来处理计算第一步什么的,分数化简之类。 LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } <pre name="code" class="cpp">LL lcm(LL a, LL b){LL c = gcd(a, b);return a / c * b;} 例题:

Java 创建图形用户界面(GUI)入门指南(Swing库 JFrame 类)概述

概述 基本概念 Java Swing 的架构 Java Swing 是一个为 Java 设计的 GUI 工具包,是 JAVA 基础类的一部分,基于 Java AWT 构建,提供了一系列轻量级、可定制的图形用户界面(GUI)组件。 与 AWT 相比,Swing 提供了许多比 AWT 更好的屏幕显示元素,更加灵活和可定制,具有更好的跨平台性能。 组件和容器 Java Swing 提供了许多

【IPV6从入门到起飞】5-1 IPV6+Home Assistant(搭建基本环境)

【IPV6从入门到起飞】5-1 IPV6+Home Assistant #搭建基本环境 1 背景2 docker下载 hass3 创建容器4 浏览器访问 hass5 手机APP远程访问hass6 更多玩法 1 背景 既然电脑可以IPV6入站,手机流量可以访问IPV6网络的服务,为什么不在电脑搭建Home Assistant(hass),来控制你的设备呢?@智能家居 @万物互联

MCU7.keil中build产生的hex文件解读

1.hex文件大致解读 闲来无事,查看了MCU6.用keil新建项目的hex文件 用FlexHex打开 给我的第一印象是:经过软件的解释之后,发现这些数据排列地十分整齐 :02000F0080FE71:03000000020003F8:0C000300787FE4F6D8FD75810702000F3D:00000001FF 把解释后的数据当作十六进制来观察 1.每一行数据

poj 2104 and hdu 2665 划分树模板入门题

题意: 给一个数组n(1e5)个数,给一个范围(fr, to, k),求这个范围中第k大的数。 解析: 划分树入门。 bing神的模板。 坑爹的地方是把-l 看成了-1........ 一直re。 代码: poj 2104: #include <iostream>#include <cstdio>#include <cstdlib>#include <al

MySQL-CRUD入门1

文章目录 认识配置文件client节点mysql节点mysqld节点 数据的添加(Create)添加一行数据添加多行数据两种添加数据的效率对比 数据的查询(Retrieve)全列查询指定列查询查询中带有表达式关于字面量关于as重命名 临时表引入distinct去重order by 排序关于NULL 认识配置文件 在我们的MySQL服务安装好了之后, 会有一个配置文件, 也就

基于UE5和ROS2的激光雷达+深度RGBD相机小车的仿真指南(五):Blender锥桶建模

前言 本系列教程旨在使用UE5配置一个具备激光雷达+深度摄像机的仿真小车,并使用通过跨平台的方式进行ROS2和UE5仿真的通讯,达到小车自主导航的目的。本教程默认有ROS2导航及其gazebo仿真相关方面基础,Nav2相关的学习教程可以参考本人的其他博客Nav2代价地图实现和原理–Nav2源码解读之CostMap2D(上)-CSDN博客往期教程: 第一期:基于UE5和ROS2的激光雷达+深度RG

音视频入门基础:WAV专题(10)——FFmpeg源码中计算WAV音频文件每个packet的pts、dts的实现

一、引言 从文章《音视频入门基础:WAV专题(6)——通过FFprobe显示WAV音频文件每个数据包的信息》中我们可以知道,通过FFprobe命令可以打印WAV音频文件每个packet(也称为数据包或多媒体包)的信息,这些信息包含该packet的pts、dts: 打印出来的“pts”实际是AVPacket结构体中的成员变量pts,是以AVStream->time_base为单位的显