团结 Accelerator 是在 Unity Accelerator 基础上扩展开发的高效工具,新增了免构建、Lazy Download 等关键功能。本文档基于 Unity Accelerator 官方文档 编写,详细介绍其工作流程、部署方式及配置步骤。
在常用网络中部署 Accelerator,需满足以下要求:
确保主机在本地网络运行且可托管 Accelerator。
项目需使用 团结引擎 1.7.1 preview 或更高版本。
从以下链接下载对应平台的 Accelerator 可执行文件,并将其置于一个空文件夹中(Windows 平台需注意路径长度限制,建议将文件夹放在磁盘根目录):
Linux 和 macOS 的运行方式类似,具体步骤如下:
进入可行性目录:
假设上述unity-accelerator.exe已经被下载到C盘中的tuanjieaccelerator目录下,本地启动PowerShell命令行工具, cd进入到该目录下:
cd C:\tuanjieaccelerator
注册 ADBV2 模式:
.\unity-accelerator.exe register adbv2
设置账号密码:
.\unity-accelerator.exe dashboard password [username]
根据提示输入密码。
启动 Accelerator:
.\unity-accelerator.exe run --debug --log-stdout-also --no-auto-updates
初次启动时,系统会提示是否允许网络访问,确认后若看到日志输出即表示启动成功。
默认不指定端口时,可通过以下前端访问入口查看状态:
http://127.0.0.1/dashboard/
要配置您的 Editor 来将该 Accelerator 用作资源管线版本 2 缓存服务器,请遵循以下步骤进行操作:
建议给不同项目分配不同的Namespace Prefix,以避免缓存冲突。还可以根据需要单独禁用上传或下载。例如,可能希望构建系统只启用上传,而开发人员的编辑器只启用下载。请注意,TLS/SSL 选项只是自 2020.1 起的编辑器版本中的功能,并且还必须针对 TLS 配置Accelerator。
在编辑器主视图中,可以通过查看右下方的状态栏来检查Accelerator连接(仅限自 2020.1 起的编辑器版本):
注意:免构建与 Lazy Download 不可同时启用。
为了保证独立性我们将从配置 Editor 使用Accelerator重新开始,详细介绍每个步骤
新建空项目并打开
配置 Cache Server:点击右下角 Cache Server 图标打开设置界面。
将 Cache Server Mode 设为 Enabled,并输入局域网本机 IP 地址, 点击 Check Connection 测试连接,成功后显示 Connection successful, 保存并关闭设置页面。

启用 InstantAsset 和免构建选项:
打开 Project Settings > Editor > Instant Player;,参考以下配置开启 Instant Assets、开启 Auto Upload Source Data(自动同步 SourceDB 和资源依赖信息)、开启 Dataless Player 支持免构建、开启 Caching for Shaders(自动编译指定平台 shader)、开启 Caching for Scenes(自动处理场景为运行时可读)

设置构建选项:
在 Project Settings > Player 中,允许通过 HTTP 链接下载资产;
将 Managed Stripping Level 设置为 Disabled;如果Scripts Backend选择使用 IL2CPP,在移动端平台、WebGL和小游戏平台,需要关闭 Strip Engine Code 选项。
分配命名空间:
在 Project Settings > Editor > Cache Server 中,为项目分配唯一的 Namespace prefix,避免使用默认值 default。确认 Editor 已连接 Accelerator(右下角图标变蓝)。在 Assets 目录下右击,选择 Reimport All,将所有 artifact 缓存上传至 Accelerator。

构建项目及配置场景:
准备两个场景: 空场景(SampleScene):新建项目默认创建; 展示场景(ShowScene):在 Assets/ArtAssets 文件夹中新建 ShowScene.scene。在 SampleScene 中添加一个 GameObject,并挂载以下脚本以加载 ShowScene:
using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
public class TestNoBuild : MonoBehaviour
{
private static TestNoBuild instance;
private InstantAssetTable assetTable;
private string tablename;
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
void OnGUI()
{
if (GUI.Button(new Rect(100, 100, 200, 50), "Load Scene"))
{
StartCoroutine(LoadSceneAsync());
}
if (GUI.Button(new Rect(100, 160, 200, 50), "Unload Scene"))
{
StartCoroutine(UnloadScene());
}
}
IEnumerator UnloadScene()
{
InstantAsset.UnloadAssetTable(tablename);
string sceneName = "Scenes/SampleScene"; // 替换为实际路径
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName);
yield return asyncLoad;
}
IEnumerator LoadSceneAsync()
{
tablename = Path.Combine(Application.streamingAssetsPath, "ArtAssets_table-scene");
InstantAsset.SetInstantAssetRootPath(Application.streamingAssetsPath);
yield return null;
assetTable = InstantAsset.ReadAssetTable(tablename) as InstantAssetTable;
string sceneName = "assets/ArtAssets/showscene.scene"; // 替换为实际路径
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName);
yield return asyncLoad;
}
}
构建首包:
在 Build Settings 中点击 Add Open Scenes,将 SampleScene 添加为启动场景,构建工程可执行文件包。
免构建测试:
确保 Editor 和 Player 连接到同一 Accelerator 服务。
测试流程:
步骤一:将空场景(SampleScene)打包并运行,点击 Load Scene,此时展示场景(ShowScene)应正确显示在运行程序中。
步骤二:不需关闭运行程序,直接在 ShowScene 中添加任意资源(如 Prefab、FBX、音频、动画等)或者修复资产; 若引用内置资源,需执行 Assets > Update Builtin Resources For CacheServer 参考以下图示。
步骤三:点击运行程序的 Unload Scene 按钮,卸载已加载资源,再点击 Load Scene,此时编辑后的展示场景应正确显示。
步骤四:重复第二和第三步进行测试。

注意:免构建目前支持除脚本外的常见资产新增和修改。
正式出包分发(脱离 Accelerator):
新建 Editor 文件夹,添加以下 BuildAssetPacker.cs 脚本, 点击 InstantAsset > Build AssetPacker 构建资源包:
using System.Collections.Generic;
using UnityEditor;
using System.IO;
using UnityEngine;
public class CreateAssetPacker
{
[MenuItem("InstantAsset/Build AssetPacker")]
static void BuildAllAssetPacker()
{
string pathname = Application.streamingAssetsPath;
Debug.Log("save path: " + pathname);
if (Directory.Exists(pathname))
Directory.Delete(pathname, true);
Directory.CreateDirectory(pathname);
List<InstantAssetAliasTable> tables = new List<InstantAssetAliasTable>();
tables.Add(new InstantAssetAliasTable() { aliasTableName = "ArtAssets_table", buildDirectoryPath = "Assets/ArtAssets" });
bool build = InstantAssetEditorUtility.BuildAssetPacker(pathname, tables.ToArray(), InstantAssetOptions.None, 512 * 1024, BuildTarget.StandaloneWindows64);
if (build)
Debug.Log("build succeed!");
else
Debug.Log("build failed!");
}
}
关闭 Dataless Player,重新构建首包。

注意:此步骤之前必须已完成 Build AssetPacker。资产免构建功能不会涉及上层业务代码的改动,因此针对资源的调用接口将转发到 Accelerator 的 RESTful API 接口服务。如果业务层使用同步调用接口,底层将由异步执行后强制同步返回结果;在 WebGL 和 MiniGame 平台上,推荐业务层使用异步调用接口。
Path.GetFullPath("Built-In-Extra-Resources_0") 路径下的缓存文件,并重新运行程序。default。net::ERR_UNSAFE_PORT 错误,请在 Cache Server 配置界面将端口号指定为 8080。针对大型项目,若希望加快项目打开进程,则可以使用 Lazy Download 功能。该功能位于 Cache Server > Download > Lazy Download Mode菜单项。Lazy Download 支持在开启项目时,只下载必要资产,而其他资产会在后续被使用时下载,比如,点击资产,场景加载。另外,该功能需要团结1.7.0 preview及以上版本。
Lazy Download Mode 用法说明
1. 勾选 Download 选项以启用 Lazy Download。
2. 选择 Lazy Download Mode,具体模式说明请参考官方文档。
注意:Lazy Download 需团结引擎 1.7.0 preview 或以上版本支持。
| Lazy Download Mode | 用法 |
|---|---|
| Disabled | 不开启Lazy Download,这是系统默认选项,此时在用户开启项目时,会下载所有资源。支持命令行参数设置,-cacheServerLazyDownloadMode 0
|
| Lazy Download | 开启Lazy Download,此时在用户开启项目时,只会下载部分资源,其它资源会在使用该资源时被下载。支持命令行参数设置,-cacheServerLazyDownloadMode 1
|
| Lazy Download And Background Download | 在开启Lazy Download的同时,也支持Background Download,即在进入项目后,后台下载其余资源 支持命令行参数设置,-cacheServerLazyDownloadMode 2
|