2022-03-03 18:08:32 +08:00
|
|
|
|
# 资源构建
|
|
|
|
|
|
|
|
|
|
![image](https://github.com/tuyoogame/YooAsset/raw/main/Docs/Image/AssetBuilder-img1.jpg)
|
|
|
|
|
|
|
|
|
|
### 界面介绍
|
|
|
|
|
|
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-03-03 19:33:36 +08:00
|
|
|
|
- **Compression**
|
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-03-23 18:24:12 +08:00
|
|
|
|
- **Encryption Services**
|
|
|
|
|
|
|
|
|
|
加密服务类列表。
|
|
|
|
|
|
|
|
|
|
- **Redundancy Services**
|
|
|
|
|
|
|
|
|
|
冗余服务类列表。
|
|
|
|
|
|
2022-03-03 19:33:36 +08:00
|
|
|
|
- **Append Extension**
|
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-03-03 19:33:36 +08:00
|
|
|
|
- **Force Rebuild**
|
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-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-03-03 19:33:36 +08:00
|
|
|
|
- **Build**
|
2022-03-03 18:08:32 +08:00
|
|
|
|
|
2022-03-03 19:33:36 +08:00
|
|
|
|
点击Build按钮会开始构建流程,构建流程分为多个节点顺序执行,如果某个节点发生错误,会导致构建失败。错误信息可以在控制台查看。
|
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-03-23 18:24:12 +08:00
|
|
|
|
bool IEncryptionServices.Check(string filePath)
|
2022-03-03 19:13:07 +08:00
|
|
|
|
{
|
|
|
|
|
// 对配置表相关的资源包进行加密
|
|
|
|
|
return filePath.Contains("Assets/Config/");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
|
|
|
|
|
![image](https://github.com/tuyoogame/YooAsset/raw/main/Docs/Image/AssetBuilder-img4.jpg)
|
|
|
|
|
|
|
|
|
|
### 补丁清单
|
|
|
|
|
|
|
|
|
|
补丁清单是一个Json格式的文本文件,里面包含了所有资源包的信息,例如:名称,版本,大小,CRC等。
|
|
|
|
|
|
|
|
|
|
![image](https://github.com/tuyoogame/YooAsset/raw/main/Docs/Image/AssetBuilder-img2.jpg)
|
|
|
|
|
|
|
|
|
|
### 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.IsVerifyBuildingResult = true;
|
|
|
|
|
buildParameters.OutputRoot = defaultOutputRoot;
|
|
|
|
|
buildParameters.BuildTarget = buildTarget;
|
|
|
|
|
buildParameters.BuildVersion = buildVersion;
|
|
|
|
|
buildParameters.CompressOption = ECompressOption.LZ4;
|
|
|
|
|
buildParameters.AppendFileExtension = false;
|
2022-03-23 18:24:12 +08:00
|
|
|
|
buildParameters.EncryptionServices = new GameEncryption();
|
|
|
|
|
buildParameters.RedundancyServices = null;
|
|
|
|
|
buildParameters.IsForceRebuild = true;
|
2022-03-03 19:13:07 +08:00
|
|
|
|
buildParameters.BuildinTags = "buildin";
|
|
|
|
|
|
|
|
|
|
// 执行构建
|
|
|
|
|
AssetBundleBuilder builder = new AssetBundleBuilder();
|
|
|
|
|
builder.Run(buildParameters);
|
|
|
|
|
|
|
|
|
|
// 构建完成
|
|
|
|
|
Debug.Log("构建完成");
|
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
|
|
|
|
}
|
|
|
|
|
````
|
|
|
|
|
|