2022-03-03 18:08:32 +08:00
|
|
|
|
# 资源构建
|
|
|
|
|
|
2022-04-03 13:00:13 +08:00
|
|
|
|
![image](https://github.com/tuyoogame/YooAsset/raw/main/Docs/Image/AssetBuilder-img1.png)
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
|
|
|
|
### 界面介绍
|
|
|
|
|
|
2022-03-03 19:33:36 +08:00
|
|
|
|
- **Build Output**
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-03-03 19:33:36 +08:00
|
|
|
|
构建输出的目录,会根据Unity编辑器当前切换的平台自动划分构建结果。
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-03-03 19:33:36 +08:00
|
|
|
|
- **Build Version**
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-03-03 19:33:36 +08:00
|
|
|
|
构建版本号,也是资源版本号,版本号必须大于零。
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-05-04 00:12:06 +08:00
|
|
|
|
- **Build Mode**
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-05-12 12:37:48 +08:00
|
|
|
|
构建模式
|
|
|
|
|
|
|
|
|
|
(1) 强制构建模式:会删除指定构建平台下的所有构建记录,重新构建所有资源包。
|
|
|
|
|
|
|
|
|
|
(2) 增量构建模式:以上一次构建结果为基础,对于发生变化的资源进行增量构建。
|
|
|
|
|
|
|
|
|
|
(3) 演练构建模式:在不生成AssetBundle文件的前提下,进行演练构建并快速生成构建报告和补丁清单。
|
|
|
|
|
|
|
|
|
|
(4) 模拟构建模式:在编辑器下配合EditorSimulateMode运行模式,来模拟真实运行的环境。
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-04-04 22:44:13 +08:00
|
|
|
|
- **Encryption**
|
2022-03-23 18:24:12 +08:00
|
|
|
|
|
2022-04-04 22:44:13 +08:00
|
|
|
|
加密类列表。
|
2022-03-23 18:24:12 +08:00
|
|
|
|
|
2022-05-04 00:12:06 +08:00
|
|
|
|
- **Compression**
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-05-04 00:12:06 +08:00
|
|
|
|
资源包的压缩方式。
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-05-04 00:12:06 +08:00
|
|
|
|
- **Append Extension**
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-05-04 00:12:06 +08:00
|
|
|
|
构建的资源包文件名是否包含后缀格式。
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-03-03 19:33:36 +08:00
|
|
|
|
- **Buildin Tags**
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-03-03 19:33:36 +08:00
|
|
|
|
标记为安装包里的资源标签列表。构建成功后,会将相关标记的资源包拷贝到StreamingAssets文件夹下。
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-04-04 22:44:13 +08:00
|
|
|
|
- **构建**
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-04-04 22:44:13 +08:00
|
|
|
|
点击构建按钮会开始构建流程,构建流程分为多个节点顺序执行,如果某个节点发生错误,会导致构建失败。错误信息可以在控制台查看。
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
|
|
|
|
### 资源包加密
|
|
|
|
|
|
2022-03-23 23:08:39 +08:00
|
|
|
|
编写继承IEncryptionServices接口的加密类。注意:加密类文件需要放置在Editor文件夹里。
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
|
|
|
|
````C#
|
2022-03-23 18:24:12 +08:00
|
|
|
|
using System;
|
2022-03-21 23:49:50 +08:00
|
|
|
|
using YooAsset.Editor;
|
|
|
|
|
|
2022-03-23 18:24:12 +08:00
|
|
|
|
public class GameEncryption : IEncryptionServices
|
2022-03-03 18:08:32 +08:00
|
|
|
|
{
|
2022-03-03 19:13:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检测资源包是否需要加密
|
|
|
|
|
/// </summary>
|
2022-04-04 22:44:13 +08:00
|
|
|
|
bool IEncryptionServices.Check(string bundleName)
|
2022-03-03 19:13:07 +08:00
|
|
|
|
{
|
|
|
|
|
// 对配置表相关的资源包进行加密
|
2022-04-04 22:44:13 +08:00
|
|
|
|
return bundleName.Contains("assets/config/");
|
2022-03-03 19:13:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 对数据进行加密,并返回加密后的数据
|
|
|
|
|
/// </summary>
|
2022-03-23 18:24:12 +08:00
|
|
|
|
byte[] IEncryptionServices.Encrypt(byte[] fileData)
|
2022-03-03 19:13:07 +08:00
|
|
|
|
{
|
|
|
|
|
int offset = 32;
|
|
|
|
|
var temper = new byte[fileData.Length + offset];
|
|
|
|
|
Buffer.BlockCopy(fileData, 0, temper, offset, fileData.Length);
|
|
|
|
|
return temper;
|
|
|
|
|
}
|
2022-03-03 18:08:32 +08:00
|
|
|
|
}
|
|
|
|
|
````
|
|
|
|
|
|
|
|
|
|
### 补丁包
|
|
|
|
|
|
|
|
|
|
构建成功后会在输出目录下找到补丁包文件夹,该文件夹名称为本次构建时指定的资源版本号。
|
|
|
|
|
|
2022-03-23 18:24:12 +08:00
|
|
|
|
补丁包文件夹里包含补丁清单文件,资源包文件,构建报告文件等。
|
|
|
|
|
|
|
|
|
|
资源包文件都是以文件的哈希值命名。
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-05-04 00:12:06 +08:00
|
|
|
|
![image](https://github.com/tuyoogame/YooAsset/raw/main/Docs/Image/AssetBuilder-img4.png)
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
|
|
|
|
### 补丁清单
|
|
|
|
|
|
2022-05-04 00:12:06 +08:00
|
|
|
|
补丁清单是一个Json格式的文本文件,里面包含了所有资源包的信息,例如:名称,大小,CRC等。
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-05-04 00:12:06 +08:00
|
|
|
|
![image](https://github.com/tuyoogame/YooAsset/raw/main/Docs/Image/AssetBuilder-img2.png)
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
|
|
|
|
### Jenkins支持
|
|
|
|
|
|
|
|
|
|
如果需要自动化构建,可以参考如下代码范例:
|
|
|
|
|
|
|
|
|
|
````c#
|
|
|
|
|
private static void BuildInternal(BuildTarget buildTarget)
|
|
|
|
|
{
|
2022-03-03 19:13:07 +08:00
|
|
|
|
Debug.Log($"开始构建 : {buildTarget}");
|
|
|
|
|
|
2022-03-23 18:24:12 +08:00
|
|
|
|
// 命令行参数
|
2022-03-03 19:13:07 +08:00
|
|
|
|
int buildVersion = GetBuildVersion();
|
|
|
|
|
|
|
|
|
|
// 构建参数
|
|
|
|
|
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
|
|
|
|
AssetBundleBuilder.BuildParameters buildParameters = new AssetBundleBuilder.BuildParameters();
|
|
|
|
|
buildParameters.OutputRoot = defaultOutputRoot;
|
|
|
|
|
buildParameters.BuildTarget = buildTarget;
|
2022-05-04 00:12:06 +08:00
|
|
|
|
buildParameters.BuildMode = EBuildMode.ForceRebuild;
|
2022-03-03 19:13:07 +08:00
|
|
|
|
buildParameters.BuildVersion = buildVersion;
|
|
|
|
|
buildParameters.BuildinTags = "buildin";
|
2022-05-04 00:12:06 +08:00
|
|
|
|
buildParameters.VerifyBuildingResult = true;
|
|
|
|
|
buildParameters.EnableAddressable = false;
|
|
|
|
|
buildParameters.AppendFileExtension = false;
|
|
|
|
|
buildParameters.EncryptionServices = new GameEncryption();
|
|
|
|
|
buildParameters.CompressOption = ECompressOption.LZ4;
|
2022-03-03 19:13:07 +08:00
|
|
|
|
|
|
|
|
|
// 执行构建
|
|
|
|
|
AssetBundleBuilder builder = new AssetBundleBuilder();
|
|
|
|
|
builder.Run(buildParameters);
|
2022-03-03 18:08:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从构建命令里获取参数
|
|
|
|
|
private static int GetBuildVersion()
|
|
|
|
|
{
|
2022-03-03 19:13:07 +08:00
|
|
|
|
foreach (string arg in System.Environment.GetCommandLineArgs())
|
|
|
|
|
{
|
|
|
|
|
if (arg.StartsWith("buildVersion"))
|
|
|
|
|
return int.Parse(arg.Split("="[0])[1]);
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2022-03-03 18:08:32 +08:00
|
|
|
|
}
|
|
|
|
|
````
|
|
|
|
|
|