Compare commits

...

240 Commits

Author SHA1 Message Date
何冠峰
df77df4854 update space shooter
修正编译错误
2024-12-25 18:49:12 +08:00
何冠峰
4f75248f5b Update CHANGELOG.md 2024-12-25 18:47:41 +08:00
何冠峰
2b56f4469d Update package.json 2024-12-25 18:47:27 +08:00
何冠峰
8d1f0d2010 update extension sample 2024-12-25 17:24:48 +08:00
何冠峰
16117b67f1 update sapce shooter 2024-12-24 18:49:14 +08:00
何冠峰
4fc0d06908 update resource manager
重构运行时核心代码
2024-12-24 18:45:37 +08:00
何冠峰
6254d00bb5 update file system
重构运行时核心代码
2024-12-24 18:23:19 +08:00
何冠峰
6d6fd3af2c update assetbundle builder 2024-12-24 17:35:26 +08:00
何冠峰
16344393a1 update resource package
增加新方法:public PackageDetails GetPackageDetails()
2024-12-19 17:25:31 +08:00
何冠峰
36f561a595 update extension sample 2024-12-19 14:42:33 +08:00
何冠峰
f5f024b1d6 update extension sample 2024-12-19 14:09:35 +08:00
何冠峰
429f68ff64 update asset bundle builder 2024-12-19 12:24:19 +08:00
何冠峰
f9074518dd update space shooter 2024-12-19 11:28:49 +08:00
何冠峰
bda803761b update extension sample 2024-12-19 11:28:27 +08:00
何冠峰
d3c1c5acb0 fix #407 2024-12-19 11:15:58 +08:00
何冠峰
dcaafedabb update YooAssetSettings
移除配置参数:ManifestFileName
2024-12-17 18:08:40 +08:00
何冠峰
985c76d8ce fix #291
cache file system 新增参数:最大并发数和每帧请求最大数
2024-12-17 17:14:59 +08:00
何冠峰
8c532798cb update file system 2024-12-17 15:37:47 +08:00
何冠峰
17aed56270 update extension smaple 2024-12-17 15:28:49 +08:00
何冠峰
1f07411dde fix #293
Default Yoo Folder Name 可配空
2024-12-17 15:27:36 +08:00
何冠峰
906e0e3554 Update TaskCreateManifest.cs 2024-12-17 15:24:13 +08:00
何冠峰
22958923ad Update EditorSimulateBuildpipelineViewer.cs 2024-12-17 09:54:14 +08:00
何冠峰
a5f94198c0 update sapce shooter 2024-12-16 19:38:29 +08:00
何冠峰
8a2bac8770 refactor : editor simulate build
移除了枚举定义类型:EDefaultBuildPipeline
修改了EditorSimulateModeHelper.SimulateBuild()方法
2024-12-16 19:37:09 +08:00
何冠峰
3fd24f6f19 fix #391 2024-12-16 18:38:46 +08:00
何冠峰
c30292013b Update UnloadUnusedAssetsOperation.cs 2024-12-16 18:13:10 +08:00
何冠峰
edd6db731f update extension sample 2024-12-16 18:12:45 +08:00
何冠峰
19e0c7b01a fix #307 2024-12-16 18:05:27 +08:00
何冠峰
58fc76b8d2 fix #403
移除了EBuildMode枚举类型
2024-12-16 17:45:07 +08:00
何冠峰
1638bb301d fix #406 2024-12-16 16:45:05 +08:00
何冠峰
f0ed677d86 refactor : remove DryRunBuild build mode
移除演练构建模式
2024-12-13 14:32:17 +08:00
何冠峰
4b0c52d2dd fix #404 2024-12-13 14:10:12 +08:00
何冠峰
5f4e1d0b2f update package
scriptablebuildpipeline版本切换为1.21.25
2024-12-13 11:44:55 +08:00
何冠峰
a98a48a58d Update TaskCreateManifest.cs 2024-12-13 11:12:09 +08:00
何冠峰
763054884b fix #387 2024-12-13 11:00:30 +08:00
何冠峰
376088e63c update space shoot 2024-12-13 10:25:56 +08:00
何冠峰
c614ba4705 fix #402 2024-12-13 10:25:16 +08:00
何冠峰
14ea408fec fix #386 2024-12-12 18:13:33 +08:00
何冠峰
038a52f7fc Update ResourcePackage.cs 2024-12-12 17:59:04 +08:00
何冠峰
341bd5947f update extension sample 2024-12-12 17:55:39 +08:00
何冠峰
b5d857d2f1 fix #380
新增示例文件 CopyBuildinManifestOperation
2024-12-12 17:53:34 +08:00
何冠峰
97f9a3d4b1 refactor : default cache file system 2024-12-12 17:35:42 +08:00
何冠峰
9607d7135b refactor : cache system 2024-12-12 15:16:34 +08:00
何冠峰
b1338a9ffd refactor : cache file system 2024-12-12 15:00:08 +08:00
何冠峰
bf1e3da298 feat : remove delivery file system
Host Play Mode 移除了DeliveryFileSystemParameters
2024-12-11 18:43:15 +08:00
何冠峰
a91cbee50c update space shooter 2024-12-11 18:24:55 +08:00
何冠峰
15fbbf3873 Update InitializeParameters.cs 2024-12-11 18:24:40 +08:00
何冠峰
f73abba79f feat : web play mode support remote services
WebPlayMode支持跨域加载。
2024-12-11 18:19:09 +08:00
何冠峰
5fa9ebee80 feat : package manifest add note info
清单文件增加备注信息
2024-12-11 11:22:50 +08:00
何冠峰
d890ccd5e6 feat : default editor file system support async simulate frame
编辑器文件系统支持异步模拟加载帧数
2024-12-11 10:43:13 +08:00
何冠峰
e76a782a80 Update ResourcePackage.cs 2024-12-11 10:04:33 +08:00
何冠峰
0f7c5b2564 Update ResourcePackage.cs 2024-12-10 18:41:09 +08:00
何冠峰
fcf0f34d5a update resource manager 2024-12-10 18:00:13 +08:00
何冠峰
acf2301028 refactor : wait for sync complete 2024-12-10 16:48:08 +08:00
何冠峰
9bc0577423 Update DefaultIgnoreRule.cs
忽略Gizmos和编辑器资源
2024-12-10 15:18:34 +08:00
何冠峰
d037ce5b86 Update LoadBundleFileOperation.cs 2024-12-10 15:17:49 +08:00
何冠峰
cdaa45e163 Update README.md 2024-11-07 10:08:10 +08:00
何冠峰
2b9014f4d8 update space shooter
修正PatchOperation不支持原生文件
2024-10-29 17:07:53 +08:00
何冠峰
75a013d961 Update InstantiateOperation.cs
禁用引擎提供的GameObject对象的异步实例化
2024-10-28 12:11:41 +08:00
何冠峰
27563fa58e Merge pull request #379 from rickytheoldtree/patch-1
Update README.md
2024-10-22 17:34:08 +08:00
何冠峰
55f958266c Update InstantiateOperation.cs
use Object.InstantiateAsync
2024-10-17 10:52:25 +08:00
何冠峰
d980b55997 update operation system 2024-10-17 10:51:17 +08:00
rickytheoldtree
7232caa5c0 Update README.md 2024-10-14 11:55:23 +08:00
何冠峰
c0df366676 update wechat file system 2024-09-30 18:00:02 +08:00
何冠峰
8e7a43275f update extension sample 2024-09-30 17:59:25 +08:00
何冠峰
d3567d8dd5 Merge pull request #368 from JackCheng-314/EditorGitYooAsset
Wechat Clear Cache
2024-09-30 14:52:16 +08:00
jcakCheng
e9539636ac 误删除,调用微信小游戏接口删除缓存文件目录下所有文件 2024-09-13 21:05:15 +08:00
jcakCheng
093dd25e0f 微信小游戏相关代码,迁移至WechatFileSystem,修改packageversion缓存逻辑 2024-09-13 20:59:46 +08:00
jcakCheng
e0427d3062 微信小游戏,PackageVersion请求url添加_appendTimeTicks;修改unusedCache路径判断 2024-09-13 11:44:40 +08:00
jcakCheng
0627641845 添加微信小游戏删除缓存根目录之后重启小游戏逻辑,WX.CleanAllFileCache 2024-09-09 20:33:28 +08:00
jcakCheng
4bbcc3c73d 修改宏的条件 2024-09-09 20:03:07 +08:00
jcakCheng
945842c0e7 提交微信缓存相关逻辑,删除全部缓存和部分无用缓存 2024-09-09 19:52:42 +08:00
何冠峰
02ba98f120 style editor code 2024-09-05 10:14:00 +08:00
何冠峰
688f8ec26c feat : webgl platform logs 2024-09-02 11:29:01 +08:00
何冠峰
7652de0129 fix #359 2024-09-02 10:30:21 +08:00
何冠峰
3f027e5456 fix #361 2024-08-30 18:45:58 +08:00
何冠峰
6a17335231 Update ByteGameFileSystem.cs 2024-08-27 15:46:04 +08:00
何冠峰
ebf0dd9e46 Update InstantiateOperation.cs 2024-08-27 15:45:55 +08:00
何冠峰
04bd352a05 Update BuildBundleInfo.cs
适配unity2019
2024-08-27 15:45:46 +08:00
何冠峰
fa4ebfe3be fix #349 2024-08-22 22:05:08 +08:00
何冠峰
87421bb391 style : add log 2024-08-22 15:19:36 +08:00
何冠峰
c35e22fbd7 feat : Gaem async operation add Abort method. 2024-08-22 15:18:57 +08:00
何冠峰
94623d8dc0 feat : Instantiate add actived param.
实例化对象方法增加激活参数。
2024-08-22 15:18:31 +08:00
何冠峰
50eed2be10 update extension sample 2024-08-21 17:36:43 +08:00
何冠峰
e9b7336146 perf : optimize asset bundle builder 2024-08-21 17:36:27 +08:00
何冠峰
fbec06fa81 update extension sample 2024-08-19 12:29:54 +08:00
何冠峰
9fe8dad72d update extension sample
增加抖音小游戏文件系统
2024-08-19 12:24:54 +08:00
何冠峰
3046bbe697 Merge pull request #342 from miuleung/dev
Fix File Dialog Cancel Error Log
2024-08-15 14:34:37 +08:00
何冠峰
7089952895 Update CHANGELOG.md 2024-08-15 11:55:53 +08:00
何冠峰
737d2a796b Update CHANGELOG.md 2024-08-15 11:54:39 +08:00
何冠峰
e25fd14675 Update package.json 2024-08-15 11:54:34 +08:00
何冠峰
c55dc713f4 fix : fixed the host play mode init stuck
修复HostPlayMode初始化卡死问题。
2024-08-15 11:53:25 +08:00
miuleung
40ef17edcd Merge branch 'tuyoogame:dev' into dev 2024-08-14 15:15:50 +08:00
何冠峰
418536ded1 perf : check collect asset type
检测收集的资源类型是否有效
2024-08-13 19:13:26 +08:00
miuleung
c156b5c0a7 Fix File Dialog Cancel Error Log
选择文件时取消报错修复
2024-08-13 16:05:20 +08:00
何冠峰
ae454b72dc update extension sample 2024-08-13 10:54:29 +08:00
何冠峰
d34d1117a0 Update CHANGELOG.md 2024-08-13 10:30:52 +08:00
何冠峰
a5f3767cbc Update package.json 2024-08-13 10:30:37 +08:00
何冠峰
3bdb339f54 style : resource package 2024-08-13 10:19:29 +08:00
何冠峰
22cb3c3942 style : resource manager 2024-08-13 10:10:43 +08:00
何冠峰
e5f5241879 fix #311 2024-08-12 20:18:03 +08:00
何冠峰
79ac231df2 feat : builtin file system can be empty in host play mode.
HostPlayMode模式下内置文件系统可以为空。
2024-08-12 19:10:57 +08:00
hevinci
b7b375092f refactor : process build logic 2024-08-03 19:01:55 +08:00
hevinci
f86ea04521 refactor : operation system 2024-08-03 19:01:18 +08:00
hevinci
738c02f58f update space shooter 2024-08-03 18:43:28 +08:00
hevinci
d017688416 feat : the bundle file decryption
资源文件解密
2024-08-03 18:43:12 +08:00
何冠峰
6b56275f87 Merge pull request #326 from absences/decrypt
Assetbundle加载增加解密方法
2024-08-03 17:03:45 +08:00
hevinci
b89f00130e refactor load scene code 2024-08-03 16:53:25 +08:00
何冠峰
4f58c54eff Merge pull request #333 from dadahsueh/dev
feat : add load scene parameter LocalPhysicsMode
2024-08-03 16:09:49 +08:00
Dada Hsueh
9001be21ac feat : add load scene parameter LocalPhysicsMode 2024-08-01 11:04:43 +08:00
hevinci
b421e7d2f8 Update CHANGELOG.md 2024-07-31 12:06:23 +08:00
hevinci
0e7c14abde Update package.json 2024-07-31 12:06:15 +08:00
hevinci
caf072ed9b Update DefaultBuildinFileSystemBuild.cs 2024-07-31 12:02:07 +08:00
hevinci
51f2709956 Update EditorTools.cs 2024-07-31 12:01:29 +08:00
absences
0d5558f29f Update IDecryptionServices.cs 2024-07-29 14:34:21 +08:00
unknown
c6377ce544 原生文件加密/解密 2024-07-27 18:37:17 +08:00
unknown
07d34891ef Assetbundle加载增加解密方法 2024-07-27 17:23:26 +08:00
unknown
ddce031ee5 Assetbundle加载增加解密方法 2024-07-27 15:25:21 +08:00
hevinci
6680a6450b fix #325
适配unity2019引擎
2024-07-24 10:12:42 +08:00
hevinci
dc119b26c7 fix #321 2024-07-19 12:02:43 +08:00
hevinci
2cbfca4f3b update extension sample
着色器变种文件增加内部排序
2024-07-15 18:51:32 +08:00
何冠峰
7d8fce6f46 Update CHANGELOG.md 2024-07-10 16:54:45 +08:00
何冠峰
13ad50aef5 Update package.json 2024-07-10 16:54:43 +08:00
何冠峰
30245b3668 update extension sample 2024-07-10 16:50:19 +08:00
何冠峰
589eea7cf3 update file system
统一所有PlayMode的初始化行为
2024-07-09 23:37:20 +08:00
何冠峰
24c5108ce1 update asset bundle collector
适配团结引擎
2024-07-09 16:33:41 +08:00
何冠峰
21fbb01ce4 merge #317
根据NETAnalyzers调整代码
2024-07-08 18:54:07 +08:00
何冠峰
e664f20d34 update extension sample 2024-07-08 17:36:39 +08:00
何冠峰
b0ce14dc0e update file system
IFileSystem新增ReadFileData方法
2024-07-08 17:36:25 +08:00
何冠峰
d2b38cbc1b Update CHANGELOG.md 2024-07-07 18:04:21 +08:00
何冠峰
a6d978090c Update package.json 2024-07-07 18:04:19 +08:00
何冠峰
f9d40987eb update extension sample 2024-07-07 16:16:00 +08:00
何冠峰
cab710493e update file system 2024-07-07 16:15:42 +08:00
何冠峰
9970cf704b update space shooter 2024-07-07 16:02:22 +08:00
何冠峰
260867b588 update operation logic 2024-07-07 16:01:55 +08:00
何冠峰
25231ecd32 update resource manager 2024-07-07 09:45:01 +08:00
何冠峰
b282515c39 update extension sample 2024-07-07 00:52:50 +08:00
何冠峰
bafd15571a update file system 2024-07-07 00:52:17 +08:00
何冠峰
481711fd75 update space shooter 2024-07-05 20:21:51 +08:00
何冠峰
d09b52301a update extension sample 2024-07-05 20:20:38 +08:00
何冠峰
0c77ef628f update file system 2024-07-05 20:20:27 +08:00
何冠峰
54f585c67a update extension sample 2024-07-05 19:29:50 +08:00
何冠峰
a9e5e7fdd3 update file system 2024-07-05 19:29:34 +08:00
何冠峰
b151f968d7 update space shooter 2024-07-05 15:10:52 +08:00
何冠峰
86ef93caa3 update extension sample 2024-07-05 15:10:34 +08:00
何冠峰
75511397d6 update file system 2024-07-05 15:10:07 +08:00
何冠峰
db8d09d0d6 update extension sample
增加微信小游戏文件系统范例
2024-07-04 22:56:45 +08:00
何冠峰
02d70a476d update file system 2024-07-04 22:55:58 +08:00
何冠峰
9420f8561f update web file system 2024-07-04 21:59:24 +08:00
何冠峰
d43eb821b9 update sapce shooter 2024-07-04 20:49:18 +08:00
何冠峰
b82ede8bde update samples 2024-07-04 20:49:07 +08:00
何冠峰
ff02da5c54 refactor the runtime code
重构了运行时代码,支持全新的文件系统。
2024-07-04 20:36:26 +08:00
hevinci
2987d356b6 fix #308 2024-05-27 10:42:24 +08:00
hevinci
dc5f0b151b Update CHANGELOG.md 2024-05-16 17:20:58 +08:00
hevinci
dd5bcc3d9d Update package.json 2024-05-16 17:20:45 +08:00
hevinci
80188ae6e6 fix #295 2024-05-10 10:57:06 +08:00
hevinci
05e77dc166 update dependencies
SBP依赖库升级至2.1.3版本
2024-05-09 14:05:53 +08:00
hevinci
b9b8f8e170 style code 2024-04-26 16:06:49 +08:00
hevinci
c9cc09cbed fix #289 2024-04-26 16:05:37 +08:00
hevinci
bef90bf3b8 perf : check build pipeline parameter type 2024-04-26 16:05:13 +08:00
hevinci
a369efa429 fix #276 2024-04-12 11:25:12 +08:00
hevinci
370329b07d refactor : wechat game support
提供对微信小游戏缓存的查询接口
2024-04-11 19:51:34 +08:00
hevinci
e743a15fbc update extension sample 2024-04-09 20:09:12 +08:00
hevinci
10c8b52092 add packages files 2024-04-09 19:15:35 +08:00
hevinci
1461b91a94 fix #268
修复了挂起场景未解除状态前无法卸载的问题。
2024-04-03 17:14:16 +08:00
hevinci
b5ffd5005a fix #269
优化场景挂起流程,支持中途取消挂起操作。
2024-04-03 17:11:11 +08:00
hevinci
f06bd83dc3 style : add summry 2024-04-02 17:26:57 +08:00
hevinci
a1450ee78a refactor : build System Stability
工具类新增了FileSHA1Safely,FileMD5Safely,FileCRC32Safely等方法。
2024-04-02 13:04:11 +08:00
hevinci
4c619778c3 feat : support open harmony
支持华为鸿蒙系统
2024-03-13 15:50:46 +08:00
hevinci
4e8840cd93 update space shooter 2024-03-12 11:12:39 +08:00
hevinci
0a709f741a feat : asset bundle collector config upgrade compatible 2024-03-12 11:12:13 +08:00
hevinci
ef8229981e feat : add IIgnoreRule interface
支持自定义过滤规则
移除了IgnoreDefaultType收集参数
2024-03-12 10:33:54 +08:00
hevinci
2a5a2626a4 feat : add load scene sync method 2024-03-08 15:39:25 +08:00
hevinci
f4ddaedbf4 feat : add load scene sync method 2024-03-08 14:23:07 +08:00
hevinci
42104eb944 perf : check collector error 2024-03-08 11:39:48 +08:00
hevinci
fadc8e6fd6 feat : add shader pack rule and filter rule 2024-03-08 11:38:29 +08:00
hevinci
81747462b1 feat : add load scene sync method 2024-03-08 11:06:48 +08:00
何冠峰
c01adad2a0 Merge pull request #245 from absences/dev
fix path error
2024-03-04 11:13:47 +08:00
何冠峰
e598d60439 Merge pull request #249 from ZensYue/dev
移除场景成功之后再尝试卸载ab包
2024-03-04 11:12:45 +08:00
e
929cd23f35 移除场景成功之后再尝试卸载ab包 2024-03-03 23:41:28 +08:00
unknown
d1aca5b675 fix path error 2024-02-28 10:06:45 +08:00
hevinci
b67868868d style : correct typos 2024-02-26 17:42:04 +08:00
hevinci
af3bf8448c style : change file to unicode 2024-02-26 14:29:36 +08:00
hevinci
4170c60f0c style : The hash utility class is exposed 2024-02-21 10:10:37 +08:00
hevinci
0a7a883aae fix #244 2024-02-20 11:31:27 +08:00
hevinci
88a1184877 perf : optimize package manifest deserialize 2024-02-20 10:04:10 +08:00
hevinci
c7329fcab5 feat : remove space character for bundle name
移除资源包名里的空格字符
2024-02-20 09:55:49 +08:00
hevinci
6eb9a90a03 feat : add GetAllCacheFileInfosAsync method 2024-02-18 12:11:29 +08:00
hevinci
7586882a97 fix #236 2024-02-01 18:41:16 +08:00
hevinci
6f13c021b9 Update CHANGELOG.md 2024-01-17 12:11:25 +08:00
hevinci
5f30c92d44 Update package.json 2024-01-17 12:11:17 +08:00
hevinci
3e6c55d981 style : code comment 2024-01-10 15:04:29 +08:00
hevinci
de36f984d7 style : change macro name 2024-01-03 16:44:48 +08:00
hevinci
95328fe1a6 feat : wechat game cache query 2024-01-03 16:24:02 +08:00
hevinci
1fb78185ff feat : support share pack rule
支持共享资源打包规则
2024-01-03 15:13:28 +08:00
hevinci
58f9aea979 fix #223 2024-01-02 11:46:29 +08:00
hevinci
4d4bb1e34f fix #223 2024-01-02 11:06:50 +08:00
hevinci
6e1978ec10 fix #224 2024-01-02 10:35:41 +08:00
hevinci
d8a8afba5e Update CHANGELOG.md 2023-12-27 19:54:07 +08:00
hevinci
6e6f425bdd Update package.json 2023-12-27 19:54:05 +08:00
hevinci
9ebe92f832 refactor : asset bundle reporter 2023-12-27 18:24:31 +08:00
hevinci
cbdb84a69f fix #212 2023-12-27 18:20:37 +08:00
hevinci
67b2b886a8 fix #220 2023-12-26 11:40:47 +08:00
hevinci
2838289650 feat : the build report file add independ asset info 2023-12-26 11:30:19 +08:00
hevinci
4b68362fb8 update samples 2023-12-25 14:20:02 +08:00
hevinci
e8e7696a4d refactor : editor code 2023-12-25 14:19:55 +08:00
hevinci
82b2a5cc20 fix #210 2023-12-22 10:24:41 +08:00
hevinci
2332765932 style : Code text indent format 2023-12-21 19:49:50 +08:00
hevinci
552d689317 style : Code text indent format 2023-12-21 19:44:14 +08:00
hevinci
5e2d82d071 style : Code text indent format 2023-12-21 19:40:13 +08:00
hevinci
727f356eea style : Code text indent format 2023-12-21 19:29:26 +08:00
hevinci
544832c46a style : Code text indent format 2023-12-21 19:10:46 +08:00
hevinci
5c1d316d67 feat #203 2023-12-21 17:45:51 +08:00
hevinci
267ec77c37 fix #198
禁用的分组不再检测合法性
2023-12-21 17:33:08 +08:00
hevinci
c2a7106221 fix #202 2023-12-21 16:18:36 +08:00
hevinci
0e29e9823d update query services interface
内置文件和分发文件查询方法参数里增加了文件哈希值
2023-12-21 16:10:54 +08:00
hevinci
47962424eb fix #201
修复断点续传失效的问题
2023-12-21 12:06:06 +08:00
hevinci
505d23ca07 update space shooter sample 2023-12-13 09:56:36 +08:00
hevinci
d4fcb868d8 update resource package
修复下载器合并后重新计算下载字节数不正确的问题。
2023-11-22 11:13:39 +08:00
hevinci
6dd1f43445 fix #205 2023-11-18 17:12:41 +08:00
hevinci
2626cb6750 fix #195 2023-11-01 16:30:58 +08:00
hevinci
81a98ded8a update sapce shooter 2023-11-01 11:03:40 +08:00
hevinci
930f02765d Update package.json
升级SBP依赖版本,解决图集内精灵图片冗余问题
2023-11-01 11:03:16 +08:00
hevinci
a4ffa580b7 update asset bundle builder
remove RemoveSpriteAtlasRedundancy task.
2023-11-01 11:02:46 +08:00
hevinci
506612527d Update CHANGELOG.md 2023-10-27 17:24:35 +08:00
hevinci
74f9f2b0e6 Update package.json 2023-10-27 17:24:17 +08:00
hevinci
4119f02c60 update resource manager 2023-10-27 16:24:33 +08:00
hevinci
bc9a4e07e2 update operation system
异步操作增加执行优先级
2023-10-27 16:08:38 +08:00
hevinci
9418544264 update resource manager
初始化参数增加AutoDestroyAssetProvider
2023-10-26 19:07:51 +08:00
hevinci
460ea091bd fix #185 2023-10-26 17:11:56 +08:00
hevinci
64681db027 update resource manager 2023-10-25 18:45:30 +08:00
hevinci
992957e1e9 Merge branch 'dev' of https://github.com/tuyoogame/YooAsset into dev 2023-10-25 18:28:57 +08:00
hevinci
ce62dbc27f update resource manager
所有异步加载方法增加权重参数。
2023-10-25 18:28:55 +08:00
何冠峰
e2df967aa9 Merge pull request #190 from zy020118/patch-1
Update DownloadManager.cs
2023-10-25 14:13:29 +08:00
hevinci
5b4a188c0b update space shooter 2023-10-24 18:41:58 +08:00
hevinci
e8b5a58a90 update resource manager 2023-10-24 18:38:31 +08:00
swift
c3d5c13a80 Update DownloadManager.cs
WebGL平台改名遗漏 DefaultBuildPipeline->EDefaultBuildPipeline
2023-10-24 14:26:00 +08:00
hevinci
d30a8aefa4 update resource manager
优化ForceUnloadAllAssets方法逻辑
2023-10-19 19:39:14 +08:00
hevinci
194afe435a update resource manager
增加卸载指定资源的方法。
2023-10-19 16:28:30 +08:00
hevinci
82ef993d83 fix #180 2023-10-18 12:14:24 +08:00
804 changed files with 37188 additions and 28477 deletions

1
.gitignore vendored
View File

@@ -20,7 +20,6 @@
/Assets/StreamingAssets.meta /Assets/StreamingAssets.meta
/Assets/Samples /Assets/Samples
/Assets/Samples.meta /Assets/Samples.meta
/Packages
/UserSettings /UserSettings

View File

@@ -2,38 +2,399 @@
All notable changes to this package will be documented in this file. All notable changes to this package will be documented in this file.
## [2.0.2-preview] - 2023-10-17 ## [2.2.5-preview] - 2024-12-25
### Fixed 依赖的ScriptableBuildPipeline (SBP) 插件库版本切换为1.21.25版本!
- Fixed the mistaken code in the build window. 重构了ResourceManager相关的核心代码方便借助文件系统扩展和支持更复杂的需求
- Fixed an issue where auto collect shaders was not effective for dependent resources.
### Editor
- 新增了编辑器模拟构建管线 EditorSimulateBuildPipeline
- 移除了EBuildMode枚举类型构建界面有变动。
- IActiveRule分组激活接口新增GroupData类。
### Improvements ### Improvements
- Add error code for exception output during package building. - 增加抖音小游戏文件系统,见扩展示例代码。
## [2.0.1-preview] - 2023-10-11 - 微信小游戏文件系统支持删除无用缓存文件和全部缓存文件。
- 资源构建管线现在默认剔除了Gizmos和编辑器资源。
- 优化了资源构建管线里资源收集速度。
资源收集速度提升100倍
```csharp
class BuildParameters
{
/// <summary>
/// 使用资源依赖缓存数据库
/// 说明:开启此项可以极大提高资源收集速度
/// </summary>
public bool UseAssetDependencyDB = false;
}
```
- WebPlayMode支持跨域加载。
```csharp
// 创建默认的WebServer文件系统参数
public static FileSystemParameters CreateDefaultWebServerFileSystemParameters(bool disableUnityWebCache = false)
// 创建默认的WebRemote文件系统参数支持跨域加载
public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteServices remoteServices, bool disableUnityWebCache = false)
```
- 编辑器模拟文件系统新增初始化参数:支持异步模拟加载帧数。
```csharp
/// <summary>
/// 异步模拟加载最小帧数
/// </summary>
FileSystemParametersDefine.ASYNC_SIMULATE_MIN_FRAME
/// <summary>
/// 异步模拟加载最大帧数
/// </summary>
FileSystemParametersDefine.ASYNC_SIMULATE_MAX_FRAME
```
- 缓存文件系统新增初始化参数:支持设置下载器最大并发连接数和单帧最大请求数
```csharp
var fileSystremParams = FileSystemParameters.CreateDefaultCacheFileSystemParameters();
fileSystremParams .AddParameter(FileSystemParametersDefine.DOWNLOAD_MAX_CONCURRENCY, 99);
fileSystremParams .AddParameter(FileSystemParametersDefine.DOWNLOAD_MAX_REQUEST_PER_FRAME, 10);
```
### Fixed ### Fixed
- (#175) Fixed a bug where the url path of mac platform contains spaces, which would cause the request error. - (#349) 修复了在加载清单的时候,即使本地存在缓存文件还会去远端下载。
- (#177) Fixed the inability to load main asset object after loading the sub asset. - (#361) 修复了协程里等待的asset handle被release会无限等待并输出警告信息。
- (#178) Fixed the error when initializing resource package that prompted not initialized. - (#359) 修复了SubAssetsHandle.GetSubAssetObject会获取到同名的主资源。
- (#179) Fixed issue with SBP build pipeline packaging reporting errors. - (#387) 修复了加密后文件哈希冲突的时候没有抛出异常错误。
- (#404) 修复了Unity2022.3.8版本提示编译错误Cannot resolve symbol 'AsyncInstantiateOperation'
### Added ### Added
- Resource downloader add combine function. - 新增示例文件 CopyBuildinManifestOperation.cs
```c# - 新增示例文件 LoadGameObjectOperation.cs
/// <summary>
/// 合并其它下载器 - 新增了获取配置清单详情的方法
/// </summary>
/// <param name="downloader">合并的下载器</param> ```csharp
public void Combine(DownloaderOperation downloader); class ResourcePackage
{
public PackageDetails GetPackageDetails()
}
``` ```
## [2.0.0-preview] - 2023-10-07 - 新增了获取所有资源信息的方法
```csharp
class ResourcePackage
{
public AssetInfo[] GetAllAssetInfos()
}
```
- 新增了清理缓存文件的通用方法
```csharp
/// <summary>
/// 文件清理方式
/// </summary>
public enum EFileClearMode
{
/// <summary>
/// 清理所有文件
/// </summary>
ClearAllBundleFiles = 1,
/// <summary>
/// 清理未在使用的文件
/// </summary>
ClearUnusedBundleFiles = 2,
/// <summary>
/// 清理指定标签的文件
/// 说明需要指定参数可选string, string[], List<string>
/// </summary>
ClearBundleFilesByTags = 3,
}
class ResourcePackage
{
/// <summary>
/// 清理缓存文件
/// </summary>
/// <param name="clearMode">清理方式</param>
/// <param name="clearParam">执行参数</param>
public ClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(EFileClearMode clearMode, object clearParam = null)
}
```
### Changed
- 修改了EditorSimulateModeHelper.SimulateBuild()方法
- 重命名ResourcePackage.GetAssetsInfoByTags()方法为GetAssetInfosByTags()
- 实例化对象方法增加激活参数。
```csharp
public InstantiateOperation InstantiateAsync(bool actived = true)
```
- 清单文件的版本提升到2.2.5版本
```csharp
/// <summary>
/// 资源包裹的备注信息
/// </summary>
public string PackageNote;
```
### Removed
- 移除了HostPlayModeParameters.DeliveryFileSystemParameters字段
- 移除了ResourcePackage.ClearAllBundleFilesAsync()方法
- 移除了ResourcePackage.ClearUnusedBundleFilesAsync()方法
- 移除了FileSystemParameters.CreateDefaultBuildinRawFileSystemParameters()方法
- 移除了FileSystemParameters.CreateDefaultCacheRawFileSystemParameters()方法
- 移除了枚举类型EDefaultBuildPipeline
- 移除了配置参数YooAssetSettings.ManifestFileName
## [2.2.4-preview] - 2024-08-15
### Fixed
- 修复了HostPlayMode初始化卡死的问题。
## [2.2.3-preview] - 2024-08-13
### Fixed
- (#311) 修复了断点续传下载器极小概率报错 : “416 Range Not Satisfiable”
### Improvements
- 原生文件构建管线支持原生文件加密。
- HostPlayMode模式下内置文件系统初始化参数可以为空。
- 场景加载增加了LocalPhysicsMode参数来控制物理运行模式。
- 默认的内置文件系统和缓存文件系统增加解密方法。
```csharp
/// <summary>
/// 创建默认的内置文件系统参数
/// </summary>
/// <param name="decryptionServices">加密文件解密服务类</param>
/// <param name="verifyLevel">缓存文件的校验等级</param>
/// <param name="rootDirectory">内置文件的根路径</param>
public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(IDecryptionServices decryptionServices, EFileVerifyLevel verifyLevel, string rootDirectory);
/// <summary>
/// 创建默认的缓存文件系统参数
/// </summary>
/// <param name="remoteServices">远端资源地址查询服务类</param>
/// <param name="decryptionServices">加密文件解密服务类</param>
/// <param name="verifyLevel">缓存文件的校验等级</param>
/// <param name="rootDirectory">文件系统的根目录</param>
public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, IDecryptionServices decryptionServices, EFileVerifyLevel verifyLevel, string rootDirectory);
```
## [2.2.2-preview] - 2024-07-31
### Fixed
- (#321) 修复了在Unity2022里编辑器下离线模式运行失败的问题。
- (#325) 修复了在Unity2019里编译报错问题。
## [2.2.1-preview] - 2024-07-10
统一了所有PlayMode的初始化逻辑EditorSimulateMode和OfflinePlayMode初始化不再主动加载资源清单
### Added
- 新增了IFileSystem.ReadFileData方法支持原生文件自定义获取文本和二进制数据。
### Improvements
- 优化了DefaultWebFileSystem和DefaultBuildFileSystem文件系统的内部初始化逻辑。
## [2.2.0-preview] - 2024-07-07
重构了运行时代码新增了文件系统接口IFileSystem方便开发者扩展特殊需求。
新增微信小游戏文件系统示例代码详细见Extension Sample/Runtime/WechatFileSystem
### Added
- 新增了ResourcePackage.DestroyAsync方法
- 新增了FileSystemParameters类帮助初始化文件系统
内置了编辑器文件系统参数内置文件系统参数缓存文件系统参数Web文件系统参数。
```csharp
public class FileSystemParameters
{
/// <summary>
/// 文件系统类
/// </summary>
public string FileSystemClass { private set; get; }
/// <summary>
/// 文件系统的根目录
/// </summary>
public string RootDirectory { private set; get; }
/// <summary>
/// 添加自定义参数
/// </summary>
public void AddParameter(string name, object value)
}
```
### Changed
- 重构了InitializeParameters初始化参数
- 重命名YooAssets.DestroyPackage方法为RemovePackage
- 重命名ResourcePackage.UpdatePackageVersionAsync方法为RequestPackageVersionAsync
- 重命名ResourcePackage.UnloadUnusedAssets方法为UnloadUnusedAssetsAsync
- 重命名ResourcePackage.ForceUnloadAllAssets方法为UnloadAllAssetsAsync
- 重命名ResourcePackage.ClearUnusedCacheFilesAsync方法为ClearUnusedBundleFilesAsync
- 重命名ResourcePackage.ClearAllCacheFilesAsync方法为ClearAllBundleFilesAsync
### Removed
- 移除了YooAssets.Destroy方法
- 移除了YooAssets.SetDownloadSystemClearFileResponseCode方法
- 移除了YooAssets.SetCacheSystemDisableCacheOnWebGL方法
- 移除了ResourcePackage.GetPackageBuildinRootDirectory方法
- 移除了ResourcePackage.GetPackageSandboxRootDirectory方法
- 移除了ResourcePackage.ClearPackageSandbox方法
- 移除了IBuildinQueryServices接口
- 移除了IDeliveryLoadServices接口
- 移除了IDeliveryQueryServices接口
## [2.1.2] - 2024-05-16
SBP库依赖版本升级至2.1.3
### Fixed
- (#236) 修复了资源配置界面AutoCollectShader复选框没有刷新的问题。
- (#244) 修复了导入器在安卓平台导入本地下载的资源失败的问题。
- (#268) 修复了挂起场景未解除状态前无法卸载的问题。
- (#269) 优化场景挂起流程,支持中途取消挂起操作。
- (#276) 修复了HostPlayMode模式下如果内置清单是最新版本每次运行都会触发拷贝行为。
- (#289) 修复了Unity2019版本脚本IWebRequester编译报错。
- (#295) 解决了在安卓移动平台,华为和三星真机上有极小概率加载资源包失败 : Unable to open archive file
### Added
- 新增GetAllCacheFileInfosOperation()获取缓存文件信息的方法。
- 新增LoadSceneSync()同步加载场景的方法。
- 新增IIgnoreRule接口资源收集流程可以自定义。
- 新增IWechatQueryServices接口用于微信平台本地文件查询。
后续将会通过虚拟文件系统来支持!
### Changed
- 调整了UnloadSceneOperation代码里场景的卸载顺序。
### Improvements
- 优化了资源清单的解析过程。
- 移除资源包名里的空格字符。
- 支持华为鸿蒙系统。
## [2.1.1] - 2024-01-17
### Fixed
- (#224) 修复了编辑器模式打包时 SimulateBuild 报错的问题。
- (#223) 修复了资源构建界面读取配置导致的报错问题。
### Added
- 支持共享资源打包规则,可以定制化独立的构建规则。
```c#
public class BuildParameters
{
/// <summary>
/// 是否启用共享资源打包
/// </summary>
public bool EnableSharePackRule = false;
}
```
- 微信小游戏平台,资源下载器支持底层缓存查询。
## [2.1.0] - 2023-12-27
升级了 Scriptable build pipeline (SBP) 的版本,来解决图集引用的精灵图片冗余问题。
### Fixed
- (#195) 修复了在EditorPlayMode模式下AssetHandle.GetDownloadStatus()发生异常的问题。
- (#201) 修复了断点续传失效的问题。
- (#202) 修复了打包参数FileNameStyle设置为BundleName后IQueryServices会一直返回true的问题。
- (#205) 修复了HybridCLR插件里创建资源下载器触发的异常。
- (#210) 修复了DownloaderOperation在未开始下载前内部的PackageName为空的问题。
- (#220) 修复了资源收集界面关闭后,撤回操作还会生效的问题。
- 修复了下载器合并后重新计算下载字节数不正确的问题。
### Improvements
- (#198) 资源收集界面禁用的分组不再检测合法性。
- (#203) 资源构建类容许自定义打包的输出目录。
- 资源构建报告增加未依赖的资源信息列表。
### Changed
- IBuildinQueryServices和IDeliveryQueryServices查询方法变更。
```c#
public interface IBuildinQueryServices
{
/// <summary>
/// 查询是否为应用程序内置的资源文件
/// </summary>
/// <param name="packageName">包裹名称</param>
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
/// <param name="fileCRC">文件哈希值</param>
/// <returns>返回查询结果</returns>
bool Query(string packageName, string fileName, string fileCRC);
}
public interface IDeliveryQueryServices
{
/// <summary>
/// 查询是否为开发者分发的资源文件
/// </summary>
/// <param name="packageName">包裹名称</param>
/// <param name="fileName">文件名称(包含文件的后缀格式)</param>
/// <param name="fileCRC">文件哈希值</param>
/// <returns>返回查询结果</returns>
bool Query(string packageName, string fileName, string fileCRC);
}
```
### Removed
- (#212) 移除了构建报告里的资源冗余信息列表。
This is the preview version.

View File

@@ -8,49 +8,49 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleBuilder public class AssetBundleBuilder
{ {
private readonly BuildContext _buildContext = new BuildContext(); private readonly BuildContext _buildContext = new BuildContext();
/// <summary> /// <summary>
/// 构建资源包 /// 构建资源包
/// </summary> /// </summary>
public BuildResult Run(BuildParameters buildParameters, List<IBuildTask> buildPipeline, bool enableLog) public BuildResult Run(BuildParameters buildParameters, List<IBuildTask> buildPipeline, bool enableLog)
{ {
// 检测构建参数是否为空 // 检测构建参数是否为空
if (buildParameters == null) if (buildParameters == null)
throw new Exception($"{nameof(buildParameters)} is null !"); throw new Exception($"{nameof(buildParameters)} is null !");
// 检测构建参数是否为空 // 检测构建参数是否为空
if (buildPipeline.Count == 0) if (buildPipeline.Count == 0)
throw new Exception($"Build pipeline is empty !"); throw new Exception($"Build pipeline is empty !");
// 清空旧数据 // 清空旧数据
_buildContext.ClearAllContext(); _buildContext.ClearAllContext();
// 构建参数 // 构建参数
var buildParametersContext = new BuildParametersContext(buildParameters); var buildParametersContext = new BuildParametersContext(buildParameters);
_buildContext.SetContextObject(buildParametersContext); _buildContext.SetContextObject(buildParametersContext);
// 初始化日志 // 初始化日志
BuildLogger.InitLogger(enableLog); BuildLogger.InitLogger(enableLog);
// 执行构建流程 // 执行构建流程
Debug.Log($"Begin to build package : {buildParameters.PackageName} by {buildParameters.BuildPipeline}"); Debug.Log($"Begin to build package : {buildParameters.PackageName} by {buildParameters.BuildPipeline}");
var buildResult = BuildRunner.Run(buildPipeline, _buildContext); var buildResult = BuildRunner.Run(buildPipeline, _buildContext);
if (buildResult.Success) if (buildResult.Success)
{ {
buildResult.OutputPackageDirectory = buildParametersContext.GetPackageOutputDirectory(); buildResult.OutputPackageDirectory = buildParametersContext.GetPackageOutputDirectory();
BuildLogger.Log("Resource pipeline build success"); BuildLogger.Log("Resource pipeline build success");
} }
else else
{ {
BuildLogger.Error($"{buildParameters.BuildPipeline} build failed !"); BuildLogger.Error($"{buildParameters.BuildPipeline} build failed !");
BuildLogger.Error($"An error occurred in build task {buildResult.FailedTask}"); BuildLogger.Error($"An error occurred in build task {buildResult.FailedTask}");
BuildLogger.Error(buildResult.ErrorInfo); BuildLogger.Error(buildResult.ErrorInfo);
} }
return buildResult; return buildResult;
} }
} }
} }

View File

@@ -6,23 +6,23 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public static class AssetBundleBuilderHelper public static class AssetBundleBuilderHelper
{ {
/// <summary> /// <summary>
/// 获取默认的输出根 /// 获取默认的输出根
/// </summary> /// </summary>
public static string GetDefaultBuildOutputRoot() public static string GetDefaultBuildOutputRoot()
{ {
string projectPath = EditorTools.GetProjectPath(); string projectPath = EditorTools.GetProjectPath();
return $"{projectPath}/Bundles"; return $"{projectPath}/Bundles";
} }
/// <summary> /// <summary>
/// 获取流文件夹路径 /// 获取流文件夹路径
/// </summary> /// </summary>
public static string GetStreamingAssetsRoot() public static string GetStreamingAssetsRoot()
{ {
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettingsData.Setting.DefaultYooFolderName}/"; return YooAssetSettingsData.GetYooEditorBuildinRoot();
} }
} }
} }

View File

@@ -4,90 +4,102 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public static class AssetBundleBuilderSetting public static class AssetBundleBuilderSetting
{ {
// EBuildPipeline // EBuildPipeline
public static EBuildPipeline GetPackageBuildPipeline(string packageName) public static EBuildPipeline GetPackageBuildPipeline(string packageName)
{ {
string key = $"{Application.productName}_{packageName}_{nameof(EBuildPipeline)}"; string key = $"{Application.productName}_{packageName}_{nameof(EBuildPipeline)}";
return (EBuildPipeline)EditorPrefs.GetInt(key, (int)EBuildPipeline.BuiltinBuildPipeline); return (EBuildPipeline)EditorPrefs.GetInt(key, (int)EBuildPipeline.BuiltinBuildPipeline);
} }
public static void SetPackageBuildPipeline(string packageName, EBuildPipeline buildPipeline) public static void SetPackageBuildPipeline(string packageName, EBuildPipeline buildPipeline)
{ {
string key = $"{Application.productName}_{packageName}_{nameof(EBuildPipeline)}"; string key = $"{Application.productName}_{packageName}_{nameof(EBuildPipeline)}";
EditorPrefs.SetInt(key, (int)buildPipeline); EditorPrefs.SetInt(key, (int)buildPipeline);
} }
// EBuildMode // ECompressOption
public static EBuildMode GetPackageBuildMode(string packageName, EBuildPipeline buildPipeline) public static ECompressOption GetPackageCompressOption(string packageName, EBuildPipeline buildPipeline)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EBuildMode)}"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(ECompressOption)}";
return (EBuildMode)EditorPrefs.GetInt(key, (int)EBuildMode.ForceRebuild); return (ECompressOption)EditorPrefs.GetInt(key, (int)ECompressOption.LZ4);
} }
public static void SetPackageBuildMode(string packageName, EBuildPipeline buildPipeline, EBuildMode buildMode) public static void SetPackageCompressOption(string packageName, EBuildPipeline buildPipeline, ECompressOption compressOption)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EBuildMode)}"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(ECompressOption)}";
EditorPrefs.SetInt(key, (int)buildMode); EditorPrefs.SetInt(key, (int)compressOption);
} }
// ECompressOption // EFileNameStyle
public static ECompressOption GetPackageCompressOption(string packageName, EBuildPipeline buildPipeline) public static EFileNameStyle GetPackageFileNameStyle(string packageName, EBuildPipeline buildPipeline)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(ECompressOption)}"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EFileNameStyle)}";
return (ECompressOption)EditorPrefs.GetInt(key, (int)ECompressOption.LZ4); return (EFileNameStyle)EditorPrefs.GetInt(key, (int)EFileNameStyle.HashName);
} }
public static void SetPackageCompressOption(string packageName, EBuildPipeline buildPipeline, ECompressOption compressOption) public static void SetPackageFileNameStyle(string packageName, EBuildPipeline buildPipeline, EFileNameStyle fileNameStyle)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(ECompressOption)}"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EFileNameStyle)}";
EditorPrefs.SetInt(key, (int)compressOption); EditorPrefs.SetInt(key, (int)fileNameStyle);
} }
// EFileNameStyle // EBuildinFileCopyOption
public static EFileNameStyle GetPackageFileNameStyle(string packageName, EBuildPipeline buildPipeline) public static EBuildinFileCopyOption GetPackageBuildinFileCopyOption(string packageName, EBuildPipeline buildPipeline)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EFileNameStyle)}"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EBuildinFileCopyOption)}";
return (EFileNameStyle)EditorPrefs.GetInt(key, (int)EFileNameStyle.HashName); return (EBuildinFileCopyOption)EditorPrefs.GetInt(key, (int)EBuildinFileCopyOption.None);
} }
public static void SetPackageFileNameStyle(string packageName, EBuildPipeline buildPipeline, EFileNameStyle fileNameStyle) public static void SetPackageBuildinFileCopyOption(string packageName, EBuildPipeline buildPipeline, EBuildinFileCopyOption buildinFileCopyOption)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EFileNameStyle)}"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EBuildinFileCopyOption)}";
EditorPrefs.SetInt(key, (int)fileNameStyle); EditorPrefs.SetInt(key, (int)buildinFileCopyOption);
} }
// EBuildinFileCopyOption // BuildFileCopyParams
public static EBuildinFileCopyOption GetPackageBuildinFileCopyOption(string packageName, EBuildPipeline buildPipeline) public static string GetPackageBuildinFileCopyParams(string packageName, EBuildPipeline buildPipeline)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EBuildinFileCopyOption)}"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_BuildFileCopyParams";
return (EBuildinFileCopyOption)EditorPrefs.GetInt(key, (int)EBuildinFileCopyOption.None); return EditorPrefs.GetString(key, string.Empty);
} }
public static void SetPackageBuildinFileCopyOption(string packageName, EBuildPipeline buildPipeline, EBuildinFileCopyOption buildinFileCopyOption) public static void SetPackageBuildinFileCopyParams(string packageName, EBuildPipeline buildPipeline, string buildinFileCopyParams)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EBuildinFileCopyOption)}"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_BuildFileCopyParams";
EditorPrefs.SetInt(key, (int)buildinFileCopyOption); EditorPrefs.SetString(key, buildinFileCopyParams);
} }
// BuildFileCopyParams // EncyptionClassName
public static string GetPackageBuildinFileCopyParams(string packageName, EBuildPipeline buildPipeline) public static string GetPackageEncyptionClassName(string packageName, EBuildPipeline buildPipeline)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_BuildFileCopyParams"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_EncyptionClassName";
return EditorPrefs.GetString(key, string.Empty); return EditorPrefs.GetString(key, string.Empty);
} }
public static void SetPackageBuildinFileCopyParams(string packageName, EBuildPipeline buildPipeline, string buildinFileCopyParams) public static void SetPackageEncyptionClassName(string packageName, EBuildPipeline buildPipeline, string encyptionClassName)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_BuildFileCopyParams"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_EncyptionClassName";
EditorPrefs.SetString(key, buildinFileCopyParams); EditorPrefs.SetString(key, encyptionClassName);
} }
// EncyptionClassName // ClearBuildCache
public static string GetPackageEncyptionClassName(string packageName, EBuildPipeline buildPipeline) public static bool GetPackageClearBuildCache(string packageName, EBuildPipeline buildPipeline)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_EncyptionClassName"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_ClearBuildCache";
return EditorPrefs.GetString(key, string.Empty); return EditorPrefs.GetInt(key, 0) > 0;
} }
public static void SetPackageEncyptionClassName(string packageName, EBuildPipeline buildPipeline, string encyptionClassName) public static void SetPackageClearBuildCache(string packageName, EBuildPipeline buildPipeline, bool clearBuildCache)
{ {
string key = $"{Application.productName}_{packageName}_{buildPipeline}_EncyptionClassName"; string key = $"{Application.productName}_{packageName}_{buildPipeline}_ClearBuildCache";
EditorPrefs.SetString(key, encyptionClassName); EditorPrefs.SetInt(key, clearBuildCache ? 1 : 0);
} }
}
// UseAssetDependencyDB
public static bool GetPackageUseAssetDependencyDB(string packageName, EBuildPipeline buildPipeline)
{
string key = $"{Application.productName}_{packageName}_{buildPipeline}_UseAssetDependencyDB";
return EditorPrefs.GetInt(key, 0) > 0;
}
public static void SetPackageUseAssetDependencyDB(string packageName, EBuildPipeline buildPipeline, bool useAssetDependencyDB)
{
string key = $"{Application.productName}_{packageName}_{buildPipeline}_UseAssetDependencyDB";
EditorPrefs.SetInt(key, useAssetDependencyDB ? 1 : 0);
}
}
} }

View File

@@ -9,153 +9,158 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleBuilderWindow : EditorWindow public class AssetBundleBuilderWindow : EditorWindow
{ {
[MenuItem("YooAsset/AssetBundle Builder", false, 102)] [MenuItem("YooAsset/AssetBundle Builder", false, 102)]
public static void OpenWindow() public static void OpenWindow()
{ {
AssetBundleBuilderWindow window = GetWindow<AssetBundleBuilderWindow>("AssetBundle Builder", true, WindowsDefine.DockedWindowTypes); AssetBundleBuilderWindow window = GetWindow<AssetBundleBuilderWindow>("AssetBundle Builder", true, WindowsDefine.DockedWindowTypes);
window.minSize = new Vector2(800, 600); window.minSize = new Vector2(800, 600);
} }
private string _buildPackage; private string _buildPackage;
private EBuildPipeline _buildPipeline; private EBuildPipeline _buildPipeline;
private Toolbar _toolbar; private Toolbar _toolbar;
private ToolbarMenu _packageMenu; private ToolbarMenu _packageMenu;
private ToolbarMenu _pipelineMenu; private ToolbarMenu _pipelineMenu;
private VisualElement _container; private VisualElement _container;
public void CreateGUI() public void CreateGUI()
{ {
try try
{ {
VisualElement root = this.rootVisualElement; VisualElement root = this.rootVisualElement;
// 加载布局文件 // 加载布局文件
var visualAsset = UxmlLoader.LoadWindowUXML<AssetBundleBuilderWindow>(); var visualAsset = UxmlLoader.LoadWindowUXML<AssetBundleBuilderWindow>();
if (visualAsset == null) if (visualAsset == null)
return; return;
visualAsset.CloneTree(root); visualAsset.CloneTree(root);
_toolbar = root.Q<Toolbar>("Toolbar"); _toolbar = root.Q<Toolbar>("Toolbar");
_container = root.Q("Container"); _container = root.Q("Container");
// 检测构建包裹 // 检测构建包裹
var packageNames = GetBuildPackageNames(); var packageNames = GetBuildPackageNames();
if (packageNames.Count == 0) if (packageNames.Count == 0)
{ {
var label = new Label(); var label = new Label();
label.text = "Not found any package"; label.text = "Not found any package";
label.style.width = 100; label.style.width = 100;
_toolbar.Add(label); _toolbar.Add(label);
return; return;
} }
// 构建包裹 // 构建包裹
{ {
_buildPackage = packageNames[0]; _buildPackage = packageNames[0];
_packageMenu = new ToolbarMenu(); _packageMenu = new ToolbarMenu();
_packageMenu.style.width = 200; _packageMenu.style.width = 200;
foreach (var packageName in packageNames) foreach (var packageName in packageNames)
{ {
_packageMenu.menu.AppendAction(packageName, PackageMenuAction, PackageMenuFun, packageName); _packageMenu.menu.AppendAction(packageName, PackageMenuAction, PackageMenuFun, packageName);
} }
_toolbar.Add(_packageMenu); _toolbar.Add(_packageMenu);
} }
// 构建管线 // 构建管线
{ {
_pipelineMenu = new ToolbarMenu(); _pipelineMenu = new ToolbarMenu();
_pipelineMenu.style.width = 200; _pipelineMenu.style.width = 200;
_pipelineMenu.menu.AppendAction(EBuildPipeline.BuiltinBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.BuiltinBuildPipeline); _pipelineMenu.menu.AppendAction(EBuildPipeline.EditorSimulateBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.EditorSimulateBuildPipeline);
_pipelineMenu.menu.AppendAction(EBuildPipeline.ScriptableBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.ScriptableBuildPipeline); _pipelineMenu.menu.AppendAction(EBuildPipeline.BuiltinBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.BuiltinBuildPipeline);
_pipelineMenu.menu.AppendAction(EBuildPipeline.RawFileBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.RawFileBuildPipeline); _pipelineMenu.menu.AppendAction(EBuildPipeline.ScriptableBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.ScriptableBuildPipeline);
_toolbar.Add(_pipelineMenu); _pipelineMenu.menu.AppendAction(EBuildPipeline.RawFileBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.RawFileBuildPipeline);
} _toolbar.Add(_pipelineMenu);
}
RefreshBuildPipelineView(); RefreshBuildPipelineView();
} }
catch (Exception e) catch (Exception e)
{ {
Debug.LogError(e.ToString()); Debug.LogError(e.ToString());
} }
} }
private void RefreshBuildPipelineView() private void RefreshBuildPipelineView()
{ {
// 清空扩展区域 // 清空扩展区域
_container.Clear(); _container.Clear();
_buildPipeline = AssetBundleBuilderSetting.GetPackageBuildPipeline(_buildPackage); _buildPipeline = AssetBundleBuilderSetting.GetPackageBuildPipeline(_buildPackage);
_packageMenu.text = _buildPackage; _packageMenu.text = _buildPackage;
_pipelineMenu.text = _buildPipeline.ToString(); _pipelineMenu.text = _buildPipeline.ToString();
var buildTarget = EditorUserBuildSettings.activeBuildTarget; var buildTarget = EditorUserBuildSettings.activeBuildTarget;
if (_buildPipeline == EBuildPipeline.BuiltinBuildPipeline) if (_buildPipeline == EBuildPipeline.EditorSimulateBuildPipeline)
{ {
var viewer = new BuiltinBuildPipelineViewer(_buildPackage, buildTarget, _container); var viewer = new EditorSimulateBuildPipelineViewer(_buildPackage, buildTarget, _container);
} }
else if (_buildPipeline == EBuildPipeline.ScriptableBuildPipeline) else if (_buildPipeline == EBuildPipeline.BuiltinBuildPipeline)
{ {
var viewer = new ScriptableBuildPipelineViewer(_buildPackage, buildTarget, _container); var viewer = new BuiltinBuildPipelineViewer(_buildPackage, buildTarget, _container);
} }
else if (_buildPipeline == EBuildPipeline.RawFileBuildPipeline) else if (_buildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{ {
var viewer = new RawfileBuildpipelineViewer(_buildPackage, buildTarget, _container); var viewer = new ScriptableBuildPipelineViewer(_buildPackage, buildTarget, _container);
} }
else else if (_buildPipeline == EBuildPipeline.RawFileBuildPipeline)
{ {
throw new System.NotImplementedException(_buildPipeline.ToString()); var viewer = new RawfileBuildpipelineViewer(_buildPackage, buildTarget, _container);
} }
} else
private List<string> GetBuildPackageNames() {
{ throw new System.NotImplementedException(_buildPipeline.ToString());
List<string> result = new List<string>(); }
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages) }
{ private List<string> GetBuildPackageNames()
result.Add(package.PackageName); {
} List<string> result = new List<string>();
return result; foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
} {
result.Add(package.PackageName);
}
return result;
}
private void PackageMenuAction(DropdownMenuAction action) private void PackageMenuAction(DropdownMenuAction action)
{ {
var packageName = (string)action.userData; var packageName = (string)action.userData;
if (_buildPackage != packageName) if (_buildPackage != packageName)
{ {
_buildPackage = packageName; _buildPackage = packageName;
RefreshBuildPipelineView(); RefreshBuildPipelineView();
} }
} }
private DropdownMenuAction.Status PackageMenuFun(DropdownMenuAction action) private DropdownMenuAction.Status PackageMenuFun(DropdownMenuAction action)
{ {
var packageName = (string)action.userData; var packageName = (string)action.userData;
if (_buildPackage == packageName) if (_buildPackage == packageName)
return DropdownMenuAction.Status.Checked; return DropdownMenuAction.Status.Checked;
else else
return DropdownMenuAction.Status.Normal; return DropdownMenuAction.Status.Normal;
} }
private void PipelineMenuAction(DropdownMenuAction action) private void PipelineMenuAction(DropdownMenuAction action)
{ {
var pipelineType = (EBuildPipeline)action.userData; var pipelineType = (EBuildPipeline)action.userData;
if (_buildPipeline != pipelineType) if (_buildPipeline != pipelineType)
{ {
_buildPipeline = pipelineType; _buildPipeline = pipelineType;
AssetBundleBuilderSetting.SetPackageBuildPipeline(_buildPackage, pipelineType); AssetBundleBuilderSetting.SetPackageBuildPipeline(_buildPackage, pipelineType);
RefreshBuildPipelineView(); RefreshBuildPipelineView();
} }
} }
private DropdownMenuAction.Status PipelineMenuFun(DropdownMenuAction action) private DropdownMenuAction.Status PipelineMenuFun(DropdownMenuAction action)
{ {
var pipelineType = (EBuildPipeline)action.userData; var pipelineType = (EBuildPipeline)action.userData;
if (_buildPipeline == pipelineType) if (_buildPipeline == pipelineType)
return DropdownMenuAction.Status.Checked; return DropdownMenuAction.Status.Checked;
else else
return DropdownMenuAction.Status.Normal; return DropdownMenuAction.Status.Normal;
} }
} }
} }
#endif #endif

View File

@@ -3,98 +3,48 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public static class AssetBundleSimulateBuilder public static class AssetBundleSimulateBuilder
{ {
/// <summary> /// <summary>
/// 模拟构建 /// 模拟构建
/// </summary> /// </summary>
public static string SimulateBuild(string buildPipelineName, string packageName) public static EditorSimulateBuildResult SimulateBuild(EditorSimulateBuildParam buildParam)
{ {
if (buildPipelineName == EBuildPipeline.BuiltinBuildPipeline.ToString()) string packageName = buildParam.PackageName;
{ string buildPipelineName = buildParam.BuildPipelineName;
BuiltinBuildParameters buildParameters = new BuiltinBuildParameters();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = buildPipelineName;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "Simulate";
buildParameters.FileNameStyle = EFileNameStyle.HashName;
buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None;
buildParameters.BuildinFileCopyParams = string.Empty;
BuiltinBuildPipeline pipeline = new BuiltinBuildPipeline(); if (buildPipelineName == "EditorSimulateBuildPipeline")
var buildResult = pipeline.Run(buildParameters, false); {
if (buildResult.Success) var buildParameters = new EditorSimulateBuildParameters();
{ buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion); buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
string manifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}"; buildParameters.BuildPipeline = EBuildPipeline.EditorSimulateBuildPipeline.ToString();
return manifestFilePath; buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle;
} buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
else buildParameters.PackageName = packageName;
{ buildParameters.PackageVersion = "Simulate";
return null; buildParameters.FileNameStyle = EFileNameStyle.HashName;
} buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None;
} buildParameters.BuildinFileCopyParams = string.Empty;
else if (buildPipelineName == EBuildPipeline.ScriptableBuildPipeline.ToString())
{
ScriptableBuildParameters buildParameters = new ScriptableBuildParameters();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = buildPipelineName;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "Simulate";
buildParameters.FileNameStyle = EFileNameStyle.HashName;
buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None;
buildParameters.BuildinFileCopyParams = string.Empty;
ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline(); var pipeline = new EditorSimulateBuildPipeline();
var buildResult = pipeline.Run(buildParameters, true); BuildResult buildResult = pipeline.Run(buildParameters, false);
if (buildResult.Success) if (buildResult.Success)
{ {
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion); var reulst = new EditorSimulateBuildResult();
string manifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}"; reulst.PackageRootDirectory = buildResult.OutputPackageDirectory;
return manifestFilePath; return reulst;
} }
else else
{ {
return null; Debug.LogError(buildResult.ErrorInfo);
} throw new System.Exception($"{nameof(EditorSimulateBuildPipeline)} build failed !");
} }
else if (buildPipelineName == EBuildPipeline.RawFileBuildPipeline.ToString()) }
{ else
RawFileBuildParameters buildParameters = new RawFileBuildParameters(); {
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); throw new System.NotImplementedException(buildPipelineName);
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); }
buildParameters.BuildPipeline = buildPipelineName; }
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; }
buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "Simulate";
buildParameters.FileNameStyle = EFileNameStyle.HashName;
buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None;
buildParameters.BuildinFileCopyParams = string.Empty;
RawFileBuildPipeline pipeline = new RawFileBuildPipeline();
var buildResult = pipeline.Run(buildParameters, true);
if (buildResult.Success)
{
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string manifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}";
return manifestFilePath;
}
else
{
return null;
}
}
else
{
throw new System.NotImplementedException(buildPipelineName);
}
}
}
} }

View File

@@ -5,155 +5,129 @@ using System.Linq;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class BuildAssetInfo public class BuildAssetInfo
{ {
private bool _isAddAssetTags = false; private bool _isAddAssetTags = false;
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>(); private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
/// <summary> /// <summary>
/// 收集器类型 /// 收集器类型
/// </summary> /// </summary>
public ECollectorType CollectorType { private set; get; } public ECollectorType CollectorType { private set; get; }
/// <summary> /// <summary>
/// 资源包完整名称 /// 资源包完整名称
/// </summary> /// </summary>
public string BundleName { private set; get; } public string BundleName { private set; get; }
/// <summary> /// <summary>
/// 可寻址地址 /// 可寻址地址
/// </summary> /// </summary>
public string Address { private set; get; } public string Address { private set; get; }
/// <summary> /// <summary>
/// 资源路径 /// 资源信息
/// </summary> /// </summary>
public string AssetPath { private set; get; } public AssetInfo AssetInfo { private set; get; }
/// <summary> /// <summary>
/// 资源GUID /// 资源的分类标签
/// </summary> /// </summary>
public string AssetGUID { private set; get; } public readonly List<string> AssetTags = new List<string>();
/// <summary> /// <summary>
/// 资源类型 /// 依赖的所有资源
/// </summary> /// 注意:包括零依赖资源和冗余资源(资源包名无效)
public System.Type AssetType { private set; get; } /// </summary>
public List<BuildAssetInfo> AllDependAssetInfos { private set; get; }
/// <summary>
/// 资源的分类标签
/// </summary>
public readonly List<string> AssetTags = new List<string>();
/// <summary>
/// 依赖的所有资源
/// 注意:包括零依赖资源和冗余资源(资源包名无效)
/// </summary>
public List<BuildAssetInfo> AllDependAssetInfos { private set; get; }
public BuildAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath) public BuildAssetInfo(ECollectorType collectorType, string bundleName, string address, AssetInfo assetInfo)
{ {
CollectorType = collectorType; CollectorType = collectorType;
BundleName = bundleName; BundleName = bundleName;
Address = address; Address = address;
AssetPath = assetPath; AssetInfo = assetInfo;
}
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath); public BuildAssetInfo(AssetInfo assetInfo)
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath); {
} CollectorType = ECollectorType.None;
public BuildAssetInfo(string assetPath) BundleName = string.Empty;
{ Address = string.Empty;
CollectorType = ECollectorType.None; AssetInfo = assetInfo;
BundleName = string.Empty; }
Address = string.Empty;
AssetPath = assetPath;
AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath);
AssetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
}
/// <summary> /// <summary>
/// 设置所有依赖的资源 /// 设置所有依赖的资源
/// </summary> /// </summary>
public void SetDependAssetInfos(List<BuildAssetInfo> dependAssetInfos) public void SetDependAssetInfos(List<BuildAssetInfo> dependAssetInfos)
{ {
if (AllDependAssetInfos != null) if (AllDependAssetInfos != null)
throw new System.Exception("Should never get here !"); throw new System.Exception("Should never get here !");
AllDependAssetInfos = dependAssetInfos; AllDependAssetInfos = dependAssetInfos;
} }
/// <summary> /// <summary>
/// 设置为统一的着色器包名 /// 设置资源包名
/// </summary> /// </summary>
public void SetShaderBundleName(string packageName, bool uniqueBundleName) public void SetBundleName(string bundleName)
{ {
// 获取着色器打包规则结果 if (HasBundleName())
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult(); throw new System.Exception("Should never get here !");
BundleName = shaderPackRuleResult.GetBundleName(packageName, uniqueBundleName);
}
/// <summary> BundleName = bundleName;
/// 添加资源的分类标签 }
/// 说明:原始定义的资源分类标签
/// </summary>
public void AddAssetTags(List<string> tags)
{
if (_isAddAssetTags)
throw new Exception("Should never get here !");
_isAddAssetTags = true;
foreach (var tag in tags) /// <summary>
{ /// 添加资源的分类标签
if (AssetTags.Contains(tag) == false) /// 说明:原始定义的资源分类标签
{ /// </summary>
AssetTags.Add(tag); public void AddAssetTags(List<string> tags)
} {
} if (_isAddAssetTags)
} throw new Exception("Should never get here !");
_isAddAssetTags = true;
/// <summary> foreach (var tag in tags)
/// 添加关联的资源包名称 {
/// </summary> if (AssetTags.Contains(tag) == false)
public void AddReferenceBundleName(string bundleName) {
{ AssetTags.Add(tag);
if (string.IsNullOrEmpty(bundleName)) }
throw new Exception("Should never get here !"); }
}
if (_referenceBundleNames.Contains(bundleName) == false) /// <summary>
_referenceBundleNames.Add(bundleName); /// 添加关联的资源包名称
} /// </summary>
public void AddReferenceBundleName(string bundleName)
{
if (string.IsNullOrEmpty(bundleName))
throw new Exception("Should never get here !");
/// <summary> if (_referenceBundleNames.Contains(bundleName) == false)
/// 资源包名是否存在 _referenceBundleNames.Add(bundleName);
/// </summary> }
public bool HasBundleName()
{
if (string.IsNullOrEmpty(BundleName))
return false;
else
return true;
}
/// <summary> /// <summary>
/// 判断是否为冗余资源 /// 资源包名是否存在
/// </summary> /// </summary>
public bool IsRedundancyAsset() public bool HasBundleName()
{ {
if (HasBundleName()) if (string.IsNullOrEmpty(BundleName))
return false; return false;
else
return true;
}
return _referenceBundleNames.Count > 1; /// <summary>
} /// 获取关联资源包的数量
/// </summary>
/// <summary> public int GetReferenceBundleCount()
/// 获取关联资源包的数量 {
/// </summary> return _referenceBundleNames.Count;
public int GetReferenceBundleCount() }
{ }
return _referenceBundleNames.Count;
}
}
} }

View File

@@ -6,171 +6,171 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class BuildBundleInfo public class BuildBundleInfo
{ {
#region #region
/// <summary> /// <summary>
/// Unity引擎生成的哈希值构建内容的哈希值 /// Unity引擎生成的哈希值构建内容的哈希值
/// </summary> /// </summary>
public string PackageUnityHash { set; get; } public string PackageUnityHash { set; get; }
/// <summary> /// <summary>
/// Unity引擎生成的CRC /// Unity引擎生成的CRC
/// </summary> /// </summary>
public uint PackageUnityCRC { set; get; } public uint PackageUnityCRC { set; get; }
/// <summary> /// <summary>
/// 文件哈希值 /// 文件哈希值
/// </summary> /// </summary>
public string PackageFileHash { set; get; } public string PackageFileHash { set; get; }
/// <summary> /// <summary>
/// 文件哈希值 /// 文件哈希值
/// </summary> /// </summary>
public string PackageFileCRC { set; get; } public string PackageFileCRC { set; get; }
/// <summary> /// <summary>
/// 文件哈希值 /// 文件哈希值
/// </summary> /// </summary>
public long PackageFileSize { set; get; } public long PackageFileSize { set; get; }
/// <summary> /// <summary>
/// 构建输出的文件路径 /// 构建输出的文件路径
/// </summary> /// </summary>
public string BuildOutputFilePath { set; get; } public string BuildOutputFilePath { set; get; }
/// <summary> /// <summary>
/// 补丁包的源文件路径 /// 补丁包的源文件路径
/// </summary> /// </summary>
public string PackageSourceFilePath { set; get; } public string PackageSourceFilePath { set; get; }
/// <summary> /// <summary>
/// 补丁包的目标文件路径 /// 补丁包的目标文件路径
/// </summary> /// </summary>
public string PackageDestFilePath { set; get; } public string PackageDestFilePath { set; get; }
/// <summary> /// <summary>
/// 加密生成文件的路径 /// 加密生成文件的路径
/// 注意:如果未加密该路径为空 /// 注意:如果未加密该路径为空
/// </summary> /// </summary>
public string EncryptedFilePath { set; get; } public string EncryptedFilePath { set; get; }
#endregion #endregion
#if UNITY_2020_3_OR_NEWER
private readonly HashSet<string> _assetPaths = new HashSet<string>(1000);
#else
private readonly HashSet<string> _assetPaths = new HashSet<string>();
#endif
/// <summary>
/// 参与构建的资源列表
/// 注意:不包含零依赖资源和冗余资源
/// </summary>
public readonly List<BuildAssetInfo> MainAssets = new List<BuildAssetInfo>();
/// <summary>
/// 资源包名称
/// </summary>
public string BundleName { private set; get; }
/// <summary>
/// 加密文件
/// </summary>
public bool Encrypted { set; get; }
/// <summary> public BuildBundleInfo(string bundleName)
/// 参与构建的资源列表 {
/// 注意:不包含零依赖资源和冗余资源 BundleName = bundleName;
/// </summary> }
public readonly List<BuildAssetInfo> MainAssets = new List<BuildAssetInfo>();
/// <summary> /// <summary>
/// 资源包名称 /// 添加一个打包资源
/// </summary> /// </summary>
public string BundleName { private set; get; } public void PackAsset(BuildAssetInfo buildAsset)
{
string assetPath = buildAsset.AssetInfo.AssetPath;
if (_assetPaths.Contains(assetPath))
throw new System.Exception($"Should never get here ! Asset is existed : {assetPath}");
/// <summary> _assetPaths.Add(assetPath);
/// 加密文件 MainAssets.Add(buildAsset);
/// </summary> }
public bool Encrypted { set; get; }
/// <summary>
/// 是否包含指定资源
/// </summary>
public bool IsContainsAsset(string assetPath)
{
return _assetPaths.Contains(assetPath);
}
public BuildBundleInfo(string bundleName) /// <summary>
{ /// 获取构建的资源路径列表
BundleName = bundleName; /// </summary>
} public string[] GetAllMainAssetPaths()
{
return MainAssets.Select(t => t.AssetInfo.AssetPath).ToArray();
}
/// <summary> /// <summary>
/// 添加一个打包资源 /// 获取该资源包内的所有资源(包括零依赖资源和冗余资源)
/// </summary> /// </summary>
public void PackAsset(BuildAssetInfo assetInfo) public List<string> GetAllBuiltinAssetPaths()
{ {
if (IsContainsAsset(assetInfo.AssetPath)) var packAssets = GetAllMainAssetPaths();
throw new System.Exception($"Should never get here ! Asset is existed : {assetInfo.AssetPath}"); List<string> result = new List<string>(packAssets);
foreach (var buildAsset in MainAssets)
{
if (buildAsset.AllDependAssetInfos == null)
continue;
foreach (var dependAssetInfo in buildAsset.AllDependAssetInfos)
{
// 注意:依赖资源里只添加零依赖资源和冗余资源
if (dependAssetInfo.HasBundleName() == false)
{
if (result.Contains(dependAssetInfo.AssetInfo.AssetPath) == false)
result.Add(dependAssetInfo.AssetInfo.AssetPath);
}
}
}
return result;
}
MainAssets.Add(assetInfo); /// <summary>
} /// 创建AssetBundleBuild类
/// </summary>
public UnityEditor.AssetBundleBuild CreatePipelineBuild()
{
// 注意我们不再支持AssetBundle的变种机制
AssetBundleBuild build = new AssetBundleBuild();
build.assetBundleName = BundleName;
build.assetBundleVariant = string.Empty;
build.assetNames = GetAllMainAssetPaths();
return build;
}
/// <summary> /// <summary>
/// 是否包含指定资源 /// 获取所有写入补丁清单的资源
/// </summary> /// </summary>
public bool IsContainsAsset(string assetPath) public BuildAssetInfo[] GetAllManifestAssetInfos()
{ {
foreach (var assetInfo in MainAssets) return MainAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
{ }
if (assetInfo.AssetPath == assetPath)
{
return true;
}
}
return false;
}
/// <summary> /// <summary>
/// 获取构建的资源路径列表 /// 创建PackageBundle类
/// </summary> /// </summary>
public string[] GetAllMainAssetPaths() internal PackageBundle CreatePackageBundle()
{ {
return MainAssets.Select(t => t.AssetPath).ToArray(); PackageBundle packageBundle = new PackageBundle();
} packageBundle.BundleName = BundleName;
packageBundle.UnityCRC = PackageUnityCRC;
/// <summary> packageBundle.FileHash = PackageFileHash;
/// 获取该资源包内的所有资源(包括零依赖资源和冗余资源) packageBundle.FileCRC = PackageFileCRC;
/// </summary> packageBundle.FileSize = PackageFileSize;
public List<string> GetAllBuiltinAssetPaths() packageBundle.Encrypted = Encrypted;
{ return packageBundle;
var packAssets = GetAllMainAssetPaths(); }
List<string> result = new List<string>(packAssets); }
foreach (var assetInfo in MainAssets)
{
if (assetInfo.AllDependAssetInfos == null)
continue;
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
{
// 注意:依赖资源里只添加零依赖资源和冗余资源
if (dependAssetInfo.HasBundleName() == false)
{
if (result.Contains(dependAssetInfo.AssetPath) == false)
result.Add(dependAssetInfo.AssetPath);
}
}
}
return result;
}
/// <summary>
/// 创建AssetBundleBuild类
/// </summary>
public UnityEditor.AssetBundleBuild CreatePipelineBuild()
{
// 注意我们不在支持AssetBundle的变种机制
AssetBundleBuild build = new AssetBundleBuild();
build.assetBundleName = BundleName;
build.assetBundleVariant = string.Empty;
build.assetNames = GetAllMainAssetPaths();
return build;
}
/// <summary>
/// 获取所有写入补丁清单的资源
/// </summary>
public BuildAssetInfo[] GetAllManifestAssetInfos()
{
return MainAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
}
/// <summary>
/// 创建PackageBundle类
/// </summary>
internal PackageBundle CreatePackageBundle()
{
PackageBundle packageBundle = new PackageBundle();
packageBundle.BundleName = BundleName;
packageBundle.FileHash = PackageFileHash;
packageBundle.FileCRC = PackageFileCRC;
packageBundle.FileSize = PackageFileSize;
packageBundle.UnityCRC = PackageUnityCRC;
packageBundle.Encrypted = Encrypted;
return packageBundle;
}
}
} }

View File

@@ -6,106 +6,105 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class BuildMapContext : IContextObject public class BuildMapContext : IContextObject
{ {
/// <summary> /// <summary>
/// 资源包集合 /// 资源包集合
/// </summary> /// </summary>
private readonly Dictionary<string, BuildBundleInfo> _bundleInfoDic = new Dictionary<string, BuildBundleInfo>(10000); private readonly Dictionary<string, BuildBundleInfo> _bundleInfoDic = new Dictionary<string, BuildBundleInfo>(10000);
/// <summary> /// <summary>
/// 冗余的资源列表 /// 未被依赖的资源列表
/// </summary> /// </summary>
public readonly List<ReportRedundancyInfo> RedundancyInfos = new List<ReportRedundancyInfo>(1000); public readonly List<ReportIndependAsset> IndependAssets = new List<ReportIndependAsset>(1000);
/// <summary>
/// 参与构建的资源总数
/// 说明:包括主动收集的资源以及其依赖的所有资源
/// </summary>
public int AssetFileCount;
/// <summary>
/// 资源收集命令
/// </summary>
public CollectCommand Command { set; get; }
/// <summary>
/// 资源包信息列表
/// </summary>
public Dictionary<string, BuildBundleInfo>.ValueCollection Collection
{
get
{
return _bundleInfoDic.Values;
}
}
/// <summary> /// <summary>
/// 参与构建的资源总数 /// 添加一个打包资源
/// 说明:包括主动收集的资源以及其依赖的所有资源 /// </summary>
/// </summary> public void PackAsset(BuildAssetInfo assetInfo)
public int AssetFileCount; {
string bundleName = assetInfo.BundleName;
if (string.IsNullOrEmpty(bundleName))
throw new Exception("Should never get here !");
/// <summary> if (_bundleInfoDic.TryGetValue(bundleName, out BuildBundleInfo bundleInfo))
/// 资源收集命令 {
/// </summary> bundleInfo.PackAsset(assetInfo);
public CollectCommand Command { set; get; } }
else
{
BuildBundleInfo newBundleInfo = new BuildBundleInfo(bundleName);
newBundleInfo.PackAsset(assetInfo);
_bundleInfoDic.Add(bundleName, newBundleInfo);
}
}
/// <summary> /// <summary>
/// 资源包信息列表 /// 是否包含资源包
/// </summary> /// </summary>
public Dictionary<string, BuildBundleInfo>.ValueCollection Collection public bool IsContainsBundle(string bundleName)
{ {
get return _bundleInfoDic.ContainsKey(bundleName);
{ }
return _bundleInfoDic.Values;
}
}
/// <summary>
/// 获取资源包信息如果没找到返回NULL
/// </summary>
public BuildBundleInfo GetBundleInfo(string bundleName)
{
if (_bundleInfoDic.TryGetValue(bundleName, out BuildBundleInfo result))
{
return result;
}
throw new Exception($"Should never get here ! Not found bundle : {bundleName}");
}
/// <summary> /// <summary>
/// 添加一个打包资源 /// 获取构建管线里需要的数据
/// </summary> /// </summary>
public void PackAsset(BuildAssetInfo assetInfo) public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
{ {
string bundleName = assetInfo.BundleName; List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(_bundleInfoDic.Count);
if (string.IsNullOrEmpty(bundleName)) foreach (var bundleInfo in _bundleInfoDic.Values)
throw new Exception("Should never get here !"); {
builds.Add(bundleInfo.CreatePipelineBuild());
}
return builds.ToArray();
}
if (_bundleInfoDic.TryGetValue(bundleName, out BuildBundleInfo bundleInfo)) /// <summary>
{ /// 创建着色器信息类
bundleInfo.PackAsset(assetInfo); /// </summary>
} public void CreateShadersBundleInfo(string shadersBundleName)
else {
{ if (IsContainsBundle(shadersBundleName) == false)
BuildBundleInfo newBundleInfo = new BuildBundleInfo(bundleName); {
newBundleInfo.PackAsset(assetInfo); var shaderBundleInfo = new BuildBundleInfo(shadersBundleName);
_bundleInfoDic.Add(bundleName, newBundleInfo); _bundleInfoDic.Add(shadersBundleName, shaderBundleInfo);
} }
} }
}
/// <summary>
/// 是否包含资源包
/// </summary>
public bool IsContainsBundle(string bundleName)
{
return _bundleInfoDic.ContainsKey(bundleName);
}
/// <summary>
/// 获取资源包信息如果没找到返回NULL
/// </summary>
public BuildBundleInfo GetBundleInfo(string bundleName)
{
if (_bundleInfoDic.TryGetValue(bundleName, out BuildBundleInfo result))
{
return result;
}
throw new Exception($"Should never get here ! Not found bundle : {bundleName}");
}
/// <summary>
/// 获取构建管线里需要的数据
/// </summary>
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
{
List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(_bundleInfoDic.Count);
foreach (var bundleInfo in _bundleInfoDic.Values)
{
builds.Add(bundleInfo.CreatePipelineBuild());
}
return builds.ToArray();
}
/// <summary>
/// 创建着色器信息类
/// </summary>
public void CreateShadersBundleInfo(string shadersBundleName)
{
if (IsContainsBundle(shadersBundleName) == false)
{
var shaderBundleInfo = new BuildBundleInfo(shadersBundleName);
_bundleInfoDic.Add(shadersBundleName, shaderBundleInfo);
}
}
}
} }

View File

@@ -6,204 +6,192 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
/// <summary> /// <summary>
/// 构建参数 /// 构建参数
/// </summary> /// </summary>
public abstract class BuildParameters public abstract class BuildParameters
{ {
/// <summary> /// <summary>
/// 构建输出的根目录 /// 构建输出的根目录
/// </summary> /// </summary>
public string BuildOutputRoot; public string BuildOutputRoot;
/// <summary> /// <summary>
/// 内置文件的根目录 /// 内置文件的根目录
/// </summary> /// </summary>
public string BuildinFileRoot; public string BuildinFileRoot;
/// <summary> /// <summary>
/// 构建管线 /// 构建管线名称
/// </summary> /// </summary>
public string BuildPipeline; public string BuildPipeline;
/// <summary> /// <summary>
/// 构建的平台 /// 构建资源包类型
/// </summary> /// </summary>
public BuildTarget BuildTarget; public int BuildBundleType;
/// <summary> /// <summary>
/// 构建模式 /// 构建的平台
/// </summary> /// </summary>
public EBuildMode BuildMode; public BuildTarget BuildTarget;
/// <summary> /// <summary>
/// 构建的包裹名称 /// 构建的包裹名称
/// </summary> /// </summary>
public string PackageName; public string PackageName;
/// <summary> /// <summary>
/// 构建的包裹版本 /// 构建的包裹版本
/// </summary> /// </summary>
public string PackageVersion; public string PackageVersion;
/// <summary>
/// 构建的包裹备注
/// </summary>
public string PackageNote;
/// <summary>
/// 清空构建缓存文件
/// </summary>
public bool ClearBuildCacheFiles = false;
/// <summary>
/// 使用资源依赖缓存数据库
/// 说明:开启此项可以极大提高资源收集速度
/// </summary>
public bool UseAssetDependencyDB = false;
/// <summary>
/// 启用共享资源打包
/// </summary>
public bool EnableSharePackRule = false;
/// <summary>
/// 验证构建结果
/// </summary>
public bool VerifyBuildingResult = false;
/// <summary>
/// 资源包名称样式
/// </summary>
public EFileNameStyle FileNameStyle;
/// <summary>
/// 内置文件的拷贝选项
/// </summary>
public EBuildinFileCopyOption BuildinFileCopyOption;
/// <summary>
/// 内置文件的拷贝参数
/// </summary>
public string BuildinFileCopyParams;
/// <summary>
/// 资源包加密服务类
/// </summary>
public IEncryptionServices EncryptionServices;
/// <summary> private string _pipelineOutputDirectory = string.Empty;
/// 验证构建结果 private string _packageOutputDirectory = string.Empty;
/// </summary> private string _packageRootDirectory = string.Empty;
public bool VerifyBuildingResult = false; private string _buildinRootDirectory = string.Empty;
/// <summary> /// <summary>
/// 资源包名称样式 /// 检测构建参数是否合法
/// </summary> /// </summary>
public EFileNameStyle FileNameStyle; public virtual void CheckBuildParameters()
{
// 检测当前是否正在构建资源包
if (UnityEditor.BuildPipeline.isBuildingPlayer)
{
string message = BuildLogger.GetErrorMessage(ErrorCode.ThePipelineIsBuiding, "The pipeline is buiding, please try again after finish !");
throw new Exception(message);
}
/// <summary> // 检测构建参数合法性
/// 内置文件的拷贝选项 if (BuildTarget == BuildTarget.NoTarget)
/// </summary> {
public EBuildinFileCopyOption BuildinFileCopyOption; string message = BuildLogger.GetErrorMessage(ErrorCode.NoBuildTarget, "Please select the build target platform !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(PackageName))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageNameIsNullOrEmpty, "Package name is null or empty !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(PackageVersion))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageVersionIsNullOrEmpty, "Package version is null or empty !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(BuildOutputRoot))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildOutputRootIsNullOrEmpty, "Build output root is null or empty !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(BuildinFileRoot))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildinFileRootIsNullOrEmpty, "Buildin file root is null or empty !");
throw new Exception(message);
}
/// <summary> // 设置默认备注信息
/// 内置文件的拷贝参数 if (string.IsNullOrEmpty(PackageNote))
/// </summary> {
public string BuildinFileCopyParams; PackageNote = DateTime.Now.ToString();
}
/// <summary> }
/// 资源包加密服务类
/// </summary>
public IEncryptionServices EncryptionServices;
private string _pipelineOutputDirectory = string.Empty; /// <summary>
private string _packageOutputDirectory = string.Empty; /// 获取构建管线的输出目录
private string _packageRootDirectory = string.Empty; /// </summary>
private string _buildinRootDirectory = string.Empty; /// <returns></returns>
public virtual string GetPipelineOutputDirectory()
{
if (string.IsNullOrEmpty(_pipelineOutputDirectory))
{
_pipelineOutputDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}/{YooAssetSettings.OutputFolderName}";
}
return _pipelineOutputDirectory;
}
/// <summary> /// <summary>
/// 检测构建参数是否合法 /// 获取本次构建的补丁输出目录
/// </summary> /// </summary>
public virtual void CheckBuildParameters() public virtual string GetPackageOutputDirectory()
{ {
// 检测当前是否正在构建资源包 if (string.IsNullOrEmpty(_packageOutputDirectory))
if (UnityEditor.BuildPipeline.isBuildingPlayer) {
{ _packageOutputDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}/{PackageVersion}";
string message = BuildLogger.GetErrorMessage(ErrorCode.ThePipelineIsBuiding, "The pipeline is buiding, please try again after finish !"); }
throw new Exception(message); return _packageOutputDirectory;
} }
// 检测是否有未保存场景 /// <summary>
if (BuildMode != EBuildMode.SimulateBuild) /// 获取本次构建的补丁根目录
{ /// </summary>
if (EditorTools.HasDirtyScenes()) public virtual string GetPackageRootDirectory()
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.FoundUnsavedScene, "Found unsaved scene !"); if (string.IsNullOrEmpty(_packageRootDirectory))
throw new Exception(message); {
} _packageRootDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}";
} }
return _packageRootDirectory;
}
// 检测构建参数合法性 /// <summary>
if (BuildTarget == BuildTarget.NoTarget) /// 获取内置资源的根目录
{ /// </summary>
string message = BuildLogger.GetErrorMessage(ErrorCode.NoBuildTarget, "Please select the build target platform !"); public virtual string GetBuildinRootDirectory()
throw new Exception(message); {
} if (string.IsNullOrEmpty(_buildinRootDirectory))
if (string.IsNullOrEmpty(PackageName)) {
{ _buildinRootDirectory = $"{BuildinFileRoot}/{PackageName}";
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageNameIsNullOrEmpty, "Package name is null or empty !"); }
throw new Exception(message); return _buildinRootDirectory;
} }
if (string.IsNullOrEmpty(PackageVersion)) }
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageVersionIsNullOrEmpty, "Package version is null or empty !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(BuildOutputRoot))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildOutputRootIsNullOrEmpty, "Build output root is null or empty !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(BuildinFileRoot))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildinFileRootIsNullOrEmpty, "Buildin file root is null or empty !");
throw new Exception(message);
}
// 强制构建删除包裹目录
if (BuildMode == EBuildMode.ForceRebuild)
{
string packageRootDirectory = GetPackageRootDirectory();
if (EditorTools.DeleteDirectory(packageRootDirectory))
{
BuildLogger.Log($"Delete package root directory: {packageRootDirectory}");
}
}
// 检测包裹输出目录是否存在
if (BuildMode != EBuildMode.SimulateBuild)
{
string packageOutputDirectory = GetPackageOutputDirectory();
if (Directory.Exists(packageOutputDirectory))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageOutputDirectoryExists, $"Package outout directory exists: {packageOutputDirectory}");
throw new Exception(message);
}
}
// 如果输出目录不存在
string pipelineOutputDirectory = GetPipelineOutputDirectory();
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
{
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
}
}
/// <summary>
/// 获取构建管线的输出目录
/// </summary>
/// <returns></returns>
public string GetPipelineOutputDirectory()
{
if (string.IsNullOrEmpty(_pipelineOutputDirectory))
{
_pipelineOutputDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}/{YooAssetSettings.OutputFolderName}";
}
return _pipelineOutputDirectory;
}
/// <summary>
/// 获取本次构建的补丁输出目录
/// </summary>
public string GetPackageOutputDirectory()
{
if (string.IsNullOrEmpty(_packageOutputDirectory))
{
_packageOutputDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}/{PackageVersion}";
}
return _packageOutputDirectory;
}
/// <summary>
/// 获取本次构建的补丁根目录
/// </summary>
public string GetPackageRootDirectory()
{
if (string.IsNullOrEmpty(_packageRootDirectory))
{
_packageRootDirectory = $"{BuildOutputRoot}/{BuildTarget}/{PackageName}";
}
return _packageRootDirectory;
}
/// <summary>
/// 获取内置资源的根目录
/// </summary>
public string GetBuildinRootDirectory()
{
if (string.IsNullOrEmpty(_buildinRootDirectory))
{
_buildinRootDirectory = $"{BuildinFileRoot}/{PackageName}";
}
return _buildinRootDirectory;
}
}
} }

View File

@@ -6,58 +6,58 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class BuildParametersContext : IContextObject public class BuildParametersContext : IContextObject
{ {
/// <summary> /// <summary>
/// 构建参数 /// 构建参数
/// </summary> /// </summary>
public BuildParameters Parameters { private set; get; } public BuildParameters Parameters { private set; get; }
public BuildParametersContext(BuildParameters parameters) public BuildParametersContext(BuildParameters parameters)
{ {
Parameters = parameters; Parameters = parameters;
} }
/// <summary> /// <summary>
/// 检测构建参数是否合法 /// 检测构建参数是否合法
/// </summary> /// </summary>
public void CheckBuildParameters() public void CheckBuildParameters()
{ {
Parameters.CheckBuildParameters(); Parameters.CheckBuildParameters();
} }
/// <summary> /// <summary>
/// 获取构建管线的输出目录 /// 获取构建管线的输出目录
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public string GetPipelineOutputDirectory() public string GetPipelineOutputDirectory()
{ {
return Parameters.GetPipelineOutputDirectory(); return Parameters.GetPipelineOutputDirectory();
} }
/// <summary> /// <summary>
/// 获取本次构建的补丁输出目录 /// 获取本次构建的补丁输出目录
/// </summary> /// </summary>
public string GetPackageOutputDirectory() public string GetPackageOutputDirectory()
{ {
return Parameters.GetPackageOutputDirectory(); return Parameters.GetPackageOutputDirectory();
} }
/// <summary> /// <summary>
/// 获取本次构建的补丁根目录 /// 获取本次构建的补丁根目录
/// </summary> /// </summary>
public string GetPackageRootDirectory() public string GetPackageRootDirectory()
{ {
return Parameters.GetPackageRootDirectory(); return Parameters.GetPackageRootDirectory();
} }
/// <summary> /// <summary>
/// 获取内置资源的根目录 /// 获取内置资源的根目录
/// </summary> /// </summary>
public string GetBuildinRootDirectory() public string GetBuildinRootDirectory()
{ {
return Parameters.GetBuildinRootDirectory(); return Parameters.GetBuildinRootDirectory();
} }
} }
} }

View File

@@ -6,77 +6,77 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCopyBuildinFiles public class TaskCopyBuildinFiles
{ {
/// <summary> /// <summary>
/// 拷贝首包资源文件 /// 拷贝首包资源文件
/// </summary> /// </summary>
internal void CopyBuildinFilesToStreaming(BuildParametersContext buildParametersContext, PackageManifest manifest) internal void CopyBuildinFilesToStreaming(BuildParametersContext buildParametersContext, PackageManifest manifest)
{ {
EBuildinFileCopyOption copyOption = buildParametersContext.Parameters.BuildinFileCopyOption; EBuildinFileCopyOption copyOption = buildParametersContext.Parameters.BuildinFileCopyOption;
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory(); string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
string buildinRootDirectory = buildParametersContext.GetBuildinRootDirectory(); string buildinRootDirectory = buildParametersContext.GetBuildinRootDirectory();
string buildPackageName = buildParametersContext.Parameters.PackageName; string buildPackageName = buildParametersContext.Parameters.PackageName;
string buildPackageVersion = buildParametersContext.Parameters.PackageVersion; string buildPackageVersion = buildParametersContext.Parameters.PackageVersion;
// 清空内置文件的目录 // 清空内置文件的目录
if (copyOption == EBuildinFileCopyOption.ClearAndCopyAll || copyOption == EBuildinFileCopyOption.ClearAndCopyByTags) if (copyOption == EBuildinFileCopyOption.ClearAndCopyAll || copyOption == EBuildinFileCopyOption.ClearAndCopyByTags)
{ {
EditorTools.ClearFolder(buildinRootDirectory); EditorTools.ClearFolder(buildinRootDirectory);
} }
// 拷贝补丁清单文件 // 拷贝补丁清单文件
{ {
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildPackageName, buildPackageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildPackageName, buildPackageVersion);
string sourcePath = $"{packageOutputDirectory}/{fileName}"; string sourcePath = $"{packageOutputDirectory}/{fileName}";
string destPath = $"{buildinRootDirectory}/{fileName}"; string destPath = $"{buildinRootDirectory}/{fileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝补丁清单哈希文件 // 拷贝补丁清单哈希文件
{ {
string fileName = YooAssetSettingsData.GetPackageHashFileName(buildPackageName, buildPackageVersion); string fileName = YooAssetSettingsData.GetPackageHashFileName(buildPackageName, buildPackageVersion);
string sourcePath = $"{packageOutputDirectory}/{fileName}"; string sourcePath = $"{packageOutputDirectory}/{fileName}";
string destPath = $"{buildinRootDirectory}/{fileName}"; string destPath = $"{buildinRootDirectory}/{fileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝补丁清单版本文件 // 拷贝补丁清单版本文件
{ {
string fileName = YooAssetSettingsData.GetPackageVersionFileName(buildPackageName); string fileName = YooAssetSettingsData.GetPackageVersionFileName(buildPackageName);
string sourcePath = $"{packageOutputDirectory}/{fileName}"; string sourcePath = $"{packageOutputDirectory}/{fileName}";
string destPath = $"{buildinRootDirectory}/{fileName}"; string destPath = $"{buildinRootDirectory}/{fileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝文件列表(所有文件) // 拷贝文件列表(所有文件)
if (copyOption == EBuildinFileCopyOption.ClearAndCopyAll || copyOption == EBuildinFileCopyOption.OnlyCopyAll) if (copyOption == EBuildinFileCopyOption.ClearAndCopyAll || copyOption == EBuildinFileCopyOption.OnlyCopyAll)
{ {
foreach (var packageBundle in manifest.BundleList) foreach (var packageBundle in manifest.BundleList)
{ {
string sourcePath = $"{packageOutputDirectory}/{packageBundle.FileName}"; string sourcePath = $"{packageOutputDirectory}/{packageBundle.FileName}";
string destPath = $"{buildinRootDirectory}/{packageBundle.FileName}"; string destPath = $"{buildinRootDirectory}/{packageBundle.FileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
} }
// 拷贝文件列表(带标签的文件) // 拷贝文件列表(带标签的文件)
if (copyOption == EBuildinFileCopyOption.ClearAndCopyByTags || copyOption == EBuildinFileCopyOption.OnlyCopyByTags) if (copyOption == EBuildinFileCopyOption.ClearAndCopyByTags || copyOption == EBuildinFileCopyOption.OnlyCopyByTags)
{ {
string[] tags = buildParametersContext.Parameters.BuildinFileCopyParams.Split(';'); string[] tags = buildParametersContext.Parameters.BuildinFileCopyParams.Split(';');
foreach (var packageBundle in manifest.BundleList) foreach (var packageBundle in manifest.BundleList)
{ {
if (packageBundle.HasTag(tags) == false) if (packageBundle.HasTag(tags) == false)
continue; continue;
string sourcePath = $"{packageOutputDirectory}/{packageBundle.FileName}"; string sourcePath = $"{packageOutputDirectory}/{packageBundle.FileName}";
string destPath = $"{buildinRootDirectory}/{packageBundle.FileName}"; string destPath = $"{buildinRootDirectory}/{packageBundle.FileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
} }
// 刷新目录 // 刷新目录
AssetDatabase.Refresh(); AssetDatabase.Refresh();
BuildLogger.Log($"Buildin files copy complete: {buildinRootDirectory}"); BuildLogger.Log($"Buildin files copy complete: {buildinRootDirectory}");
} }
} }
} }

View File

@@ -5,215 +5,264 @@ using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class ManifestContext : IContextObject public class ManifestContext : IContextObject
{ {
internal PackageManifest Manifest; internal PackageManifest Manifest;
} }
public abstract class TaskCreateManifest public abstract class TaskCreateManifest
{ {
private readonly Dictionary<string, int> _cachedBundleID = new Dictionary<string, int>(10000); private readonly Dictionary<string, int> _cachedBundleIndexIDs = new Dictionary<string, int>(10000);
private readonly Dictionary<int, HashSet<string>> _cacheBundleTags = new Dictionary<int, HashSet<string>>(10000); private readonly Dictionary<int, HashSet<string>> _cacheBundleTags = new Dictionary<int, HashSet<string>>(10000);
/// <summary> /// <summary>
/// 创建补丁清单文件到输出目录 /// 创建补丁清单文件到输出目录
/// </summary> /// </summary>
protected void CreateManifestFile(BuildContext context) protected void CreateManifestFile(bool processBundleDepends, bool processBundleTags, BuildContext context)
{ {
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters; var buildParameters = buildParametersContext.Parameters;
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory(); string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
// 创建新补丁清单 // 检测资源包哈希冲突
PackageManifest manifest = new PackageManifest(); CheckBundleHashConflict(buildMapContext);
manifest.FileVersion = YooAssetSettings.ManifestFileVersion;
manifest.EnableAddressable = buildMapContext.Command.EnableAddressable;
manifest.LocationToLower = buildMapContext.Command.LocationToLower;
manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
manifest.OutputNameStyle = (int)buildParameters.FileNameStyle;
manifest.BuildPipeline = buildParameters.BuildPipeline;
manifest.PackageName = buildParameters.PackageName;
manifest.PackageVersion = buildParameters.PackageVersion;
manifest.BundleList = GetAllPackageBundle(buildMapContext);
manifest.AssetList = GetAllPackageAsset(buildMapContext);
if (buildParameters.BuildMode != EBuildMode.SimulateBuild) // 创建新补丁清单
{ PackageManifest manifest = new PackageManifest();
// 处理资源包的依赖列表 manifest.FileVersion = YooAssetSettings.ManifestFileVersion;
ProcessBundleDepends(context, manifest); manifest.EnableAddressable = buildMapContext.Command.EnableAddressable;
manifest.LocationToLower = buildMapContext.Command.LocationToLower;
manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
manifest.OutputNameStyle = (int)buildParameters.FileNameStyle;
manifest.BuildBundleType = buildParameters.BuildBundleType;
manifest.BuildPipeline = buildParameters.BuildPipeline;
manifest.PackageName = buildParameters.PackageName;
manifest.PackageVersion = buildParameters.PackageVersion;
manifest.PackageNote = buildParameters.PackageNote;
manifest.AssetList = CreatePackageAssetList(buildMapContext);
manifest.BundleList = CreatePackageBundleList(buildMapContext);
// 处理资源包的标签集合 // 处理资源清单的ID数据
ProcessBundleTags(manifest); ProcessPacakgeIDs(manifest);
}
// 创建补丁清单文本文件 // 处理资源包的依赖列表
{ if (processBundleDepends)
string fileName = YooAssetSettingsData.GetManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion); ProcessBundleDepends(context, manifest);
string filePath = $"{packageOutputDirectory}/{fileName}";
ManifestTools.SerializeToJson(filePath, manifest);
BuildLogger.Log($"Create package manifest file: {filePath}");
}
// 创建补丁清单二进制文件 // 处理资源包的标签集合
string packageHash; if (processBundleTags)
{ ProcessBundleTags(manifest);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string filePath = $"{packageOutputDirectory}/{fileName}";
ManifestTools.SerializeToBinary(filePath, manifest);
packageHash = HashUtility.FileMD5(filePath);
BuildLogger.Log($"Create package manifest file: {filePath}");
ManifestContext manifestContext = new ManifestContext(); // 创建补丁清单文本文件
byte[] bytesData = FileUtility.ReadAllBytes(filePath); {
manifestContext.Manifest = ManifestTools.DeserializeFromBinary(bytesData); string fileName = YooAssetSettingsData.GetManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion);
context.SetContextObject(manifestContext); string filePath = $"{packageOutputDirectory}/{fileName}";
} ManifestTools.SerializeToJson(filePath, manifest);
BuildLogger.Log($"Create package manifest file: {filePath}");
}
// 创建补丁清单哈希文件 // 创建补丁清单二进制文件
{ string packageHash;
string fileName = YooAssetSettingsData.GetPackageHashFileName(buildParameters.PackageName, buildParameters.PackageVersion); {
string filePath = $"{packageOutputDirectory}/{fileName}"; string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
FileUtility.WriteAllText(filePath, packageHash); string filePath = $"{packageOutputDirectory}/{fileName}";
BuildLogger.Log($"Create package manifest hash file: {filePath}"); ManifestTools.SerializeToBinary(filePath, manifest);
} packageHash = HashUtility.FileMD5(filePath);
BuildLogger.Log($"Create package manifest file: {filePath}");
// 创建补丁清单版本文件 ManifestContext manifestContext = new ManifestContext();
{ byte[] bytesData = FileUtility.ReadAllBytes(filePath);
string fileName = YooAssetSettingsData.GetPackageVersionFileName(buildParameters.PackageName); manifestContext.Manifest = ManifestTools.DeserializeFromBinary(bytesData);
string filePath = $"{packageOutputDirectory}/{fileName}"; context.SetContextObject(manifestContext);
FileUtility.WriteAllText(filePath, buildParameters.PackageVersion); }
BuildLogger.Log($"Create package manifest version file: {filePath}");
}
}
/// <summary> // 创建补丁清单哈希文件
/// 获取资源包的依赖集合 {
/// </summary> string fileName = YooAssetSettingsData.GetPackageHashFileName(buildParameters.PackageName, buildParameters.PackageVersion);
protected abstract string[] GetBundleDepends(BuildContext context, string bundleName); string filePath = $"{packageOutputDirectory}/{fileName}";
FileUtility.WriteAllText(filePath, packageHash);
BuildLogger.Log($"Create package manifest hash file: {filePath}");
}
/// <summary> // 创建补丁清单版本文件
/// 获取主资源对象列表 {
/// </summary> string fileName = YooAssetSettingsData.GetPackageVersionFileName(buildParameters.PackageName);
private List<PackageAsset> GetAllPackageAsset(BuildMapContext buildMapContext) string filePath = $"{packageOutputDirectory}/{fileName}";
{ FileUtility.WriteAllText(filePath, buildParameters.PackageVersion);
List<PackageAsset> result = new List<PackageAsset>(1000); BuildLogger.Log($"Create package manifest version file: {filePath}");
foreach (var bundleInfo in buildMapContext.Collection) }
{ }
var assetInfos = bundleInfo.GetAllManifestAssetInfos();
foreach (var assetInfo in assetInfos)
{
PackageAsset packageAsset = new PackageAsset();
packageAsset.Address = buildMapContext.Command.EnableAddressable ? assetInfo.Address : string.Empty;
packageAsset.AssetPath = assetInfo.AssetPath;
packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetGUID : string.Empty;
packageAsset.AssetTags = assetInfo.AssetTags.ToArray();
packageAsset.BundleID = GetCachedBundleID(assetInfo.BundleName);
result.Add(packageAsset);
}
}
return result;
}
/// <summary> /// <summary>
/// 获取资源包列表 /// 检测资源包哈希冲突
/// </summary> /// </summary>
private List<PackageBundle> GetAllPackageBundle(BuildMapContext buildMapContext) private void CheckBundleHashConflict(BuildMapContext buildMapContext)
{ {
List<PackageBundle> result = new List<PackageBundle>(1000); // 说明:在特殊情况下,例如某些文件加密算法会导致加密后的文件哈希值冲突!
foreach (var bundleInfo in buildMapContext.Collection) // 说明:二进制完全相同的原生文件也会冲突!
{ HashSet<string> guids = new HashSet<string>();
var packageBundle = bundleInfo.CreatePackageBundle(); foreach (var bundleInfo in buildMapContext.Collection)
result.Add(packageBundle); {
} if (guids.Contains(bundleInfo.PackageFileHash))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BundleHashConflict, $"Bundle hash conflict : {bundleInfo.BundleName}");
throw new Exception(message);
}
else
{
guids.Add(bundleInfo.PackageFileHash);
}
}
}
// 注意:缓存资源包索引 /// <summary>
for (int index = 0; index < result.Count; index++) /// 获取资源包的依赖集合
{ /// </summary>
string bundleName = result[index].BundleName; protected abstract string[] GetBundleDepends(BuildContext context, string bundleName);
_cachedBundleID.Add(bundleName, index);
}
return result; /// <summary>
} /// 创建资源对象列表
/// </summary>
private List<PackageAsset> CreatePackageAssetList(BuildMapContext buildMapContext)
{
List<PackageAsset> result = new List<PackageAsset>(1000);
foreach (var bundleInfo in buildMapContext.Collection)
{
var assetInfos = bundleInfo.GetAllManifestAssetInfos();
foreach (var assetInfo in assetInfos)
{
PackageAsset packageAsset = new PackageAsset();
packageAsset.Address = buildMapContext.Command.EnableAddressable ? assetInfo.Address : string.Empty;
packageAsset.AssetPath = assetInfo.AssetInfo.AssetPath;
packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetInfo.AssetGUID : string.Empty;
packageAsset.AssetTags = assetInfo.AssetTags.ToArray();
packageAsset.BundleNameInEditor = assetInfo.BundleName;
result.Add(packageAsset);
}
}
/// <summary> // 按照AssetPath排序
/// 处理资源包的依赖集合 result.Sort((a, b) => a.AssetPath.CompareTo(b.AssetPath));
/// </summary> return result;
private void ProcessBundleDepends(BuildContext context, PackageManifest manifest) }
{
// 查询引擎生成的资源包依赖关系,然后记录到清单
foreach (var packageBundle in manifest.BundleList)
{
int mainBundleID = GetCachedBundleID(packageBundle.BundleName);
var depends = GetBundleDepends(context, packageBundle.BundleName);
List<int> dependIDs = new List<int>(depends.Length);
foreach (var dependBundleName in depends)
{
int bundleID = GetCachedBundleID(dependBundleName);
if (bundleID != mainBundleID)
dependIDs.Add(bundleID);
}
packageBundle.DependIDs = dependIDs.ToArray();
}
}
/// <summary> /// <summary>
/// 处理资源包的标签集合 /// 创建资源包列表
/// </summary> /// </summary>
private void ProcessBundleTags(PackageManifest manifest) private List<PackageBundle> CreatePackageBundleList(BuildMapContext buildMapContext)
{ {
// 将主资源的标签信息传染给其依赖的资源包集合 List<PackageBundle> result = new List<PackageBundle>(1000);
foreach (var packageAsset in manifest.AssetList) foreach (var bundleInfo in buildMapContext.Collection)
{ {
var assetTags = packageAsset.AssetTags; var packageBundle = bundleInfo.CreatePackageBundle();
int bundleID = packageAsset.BundleID; result.Add(packageBundle);
CacheBundleTags(bundleID, assetTags); }
var packageBundle = manifest.BundleList[bundleID]; // 按照BundleName排序
foreach (var dependBundleID in packageBundle.DependIDs) result.Sort((a, b) => a.BundleName.CompareTo(b.BundleName));
{ return result;
CacheBundleTags(dependBundleID, assetTags); }
}
}
for (int index = 0; index < manifest.BundleList.Count; index++) /// <summary>
{ /// 处理资源清单的ID数据
var packageBundle = manifest.BundleList[index]; /// </summary>
if (_cacheBundleTags.ContainsKey(index)) private void ProcessPacakgeIDs(PackageManifest manifest)
{ {
packageBundle.Tags = _cacheBundleTags[index].ToArray(); // 注意:优先缓存资源包索引
} for (int index = 0; index < manifest.BundleList.Count; index++)
else {
{ string bundleName = manifest.BundleList[index].BundleName;
// 注意SBP构建管线会自动剔除一些冗余资源的引用关系导致游离资源包没有被任何主资源包引用。 _cachedBundleIndexIDs.Add(bundleName, index);
string warning = BuildLogger.GetErrorMessage(ErrorCode.FoundStrayBundle, $"Found stray bundle ! Bundle ID : {index} Bundle name : {packageBundle.BundleName}"); }
BuildLogger.Warning(warning);
}
}
}
private void CacheBundleTags(int bundleID, string[] assetTags)
{
if (_cacheBundleTags.ContainsKey(bundleID) == false)
_cacheBundleTags.Add(bundleID, new HashSet<string>());
foreach (var assetTag in assetTags) foreach (var packageAsset in manifest.AssetList)
{ {
if (_cacheBundleTags[bundleID].Contains(assetTag) == false) string bundleName = packageAsset.BundleNameInEditor;
_cacheBundleTags[bundleID].Add(assetTag); packageAsset.BundleID = GetCachedBundleIndexID(bundleName);
} }
} }
/// <summary> /// <summary>
/// 获取资源包的索引ID /// 处理资源包的依赖集合
/// </summary> /// </summary>
private int GetCachedBundleID(string bundleName) private void ProcessBundleDepends(BuildContext context, PackageManifest manifest)
{ {
if (_cachedBundleID.TryGetValue(bundleName, out int value) == false) // 查询引擎生成的资源包依赖关系,然后记录到清单
{ foreach (var packageBundle in manifest.BundleList)
throw new Exception($"Should never get here ! Not found bundle ID : {bundleName}"); {
} int mainBundleID = GetCachedBundleIndexID(packageBundle.BundleName);
return value; var depends = GetBundleDepends(context, packageBundle.BundleName);
} List<int> dependIDs = new List<int>(depends.Length);
} foreach (var dependBundleName in depends)
{
int bundleID = GetCachedBundleIndexID(dependBundleName);
if (bundleID != mainBundleID)
dependIDs.Add(bundleID);
}
packageBundle.DependIDs = dependIDs.ToArray();
}
}
/// <summary>
/// 处理资源包的标签集合
/// </summary>
private void ProcessBundleTags(PackageManifest manifest)
{
// 将主资源的标签信息传染给其依赖的资源包集合
foreach (var packageAsset in manifest.AssetList)
{
var assetTags = packageAsset.AssetTags;
int bundleID = packageAsset.BundleID;
CacheBundleTags(bundleID, assetTags);
var packageBundle = manifest.BundleList[bundleID];
if (packageBundle.DependIDs != null)
{
foreach (var dependBundleID in packageBundle.DependIDs)
{
CacheBundleTags(dependBundleID, assetTags);
}
}
}
for (int index = 0; index < manifest.BundleList.Count; index++)
{
var packageBundle = manifest.BundleList[index];
if (_cacheBundleTags.TryGetValue(index, out var value))
{
packageBundle.Tags = value.ToArray();
}
else
{
// 注意SBP构建管线会自动剔除一些冗余资源的引用关系导致游离资源包没有被任何主资源包引用。
string warning = BuildLogger.GetErrorMessage(ErrorCode.FoundStrayBundle, $"Found stray bundle ! Bundle ID : {index} Bundle name : {packageBundle.BundleName}");
BuildLogger.Warning(warning);
}
}
}
private void CacheBundleTags(int bundleID, string[] assetTags)
{
if (_cacheBundleTags.ContainsKey(bundleID) == false)
_cacheBundleTags.Add(bundleID, new HashSet<string>());
foreach (var assetTag in assetTags)
{
if (_cacheBundleTags[bundleID].Contains(assetTag) == false)
_cacheBundleTags[bundleID].Add(assetTag);
}
}
/// <summary>
/// 获取缓存的资源包的索引ID
/// </summary>
private int GetCachedBundleIndexID(string bundleName)
{
if (_cachedBundleIndexIDs.TryGetValue(bundleName, out int value) == false)
{
throw new Exception($"Should never get here ! Not found bundle index ID : {bundleName}");
}
return value;
}
}
} }

View File

@@ -6,205 +6,213 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCreateReport public class TaskCreateReport
{ {
protected void CreateReportFile(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext, ManifestContext manifestContext) protected void CreateReportFile(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext, ManifestContext manifestContext)
{ {
var buildParameters = buildParametersContext.Parameters; var buildParameters = buildParametersContext.Parameters;
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory(); string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
PackageManifest manifest = manifestContext.Manifest; PackageManifest manifest = manifestContext.Manifest;
BuildReport buildReport = new BuildReport(); BuildReport buildReport = new BuildReport();
// 概述信息 // 概述信息
{ {
#if UNITY_2019_4_OR_NEWER #if UNITY_2019_4_OR_NEWER
UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(BuildReport).Assembly); UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(BuildReport).Assembly);
if (packageInfo != null) if (packageInfo != null)
buildReport.Summary.YooVersion = packageInfo.version; buildReport.Summary.YooVersion = packageInfo.version;
#endif #endif
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion; buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
buildReport.Summary.BuildDate = DateTime.Now.ToString(); buildReport.Summary.BuildDate = DateTime.Now.ToString();
buildReport.Summary.BuildSeconds = BuildRunner.TotalSeconds; buildReport.Summary.BuildSeconds = BuildRunner.TotalSeconds;
buildReport.Summary.BuildTarget = buildParameters.BuildTarget; buildReport.Summary.BuildTarget = buildParameters.BuildTarget;
buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline; buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline;
buildReport.Summary.BuildMode = buildParameters.BuildMode; buildReport.Summary.BuildPackageName = buildParameters.PackageName;
buildReport.Summary.BuildPackageName = buildParameters.PackageName; buildReport.Summary.BuildPackageVersion = buildParameters.PackageVersion;
buildReport.Summary.BuildPackageVersion = buildParameters.PackageVersion; buildReport.Summary.BuildPackageNote = buildParameters.PackageNote;
buildReport.Summary.UniqueBundleName = buildMapContext.Command.UniqueBundleName;
buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable;
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
buildReport.Summary.IgnoreDefaultType = buildMapContext.Command.IgnoreDefaultType;
buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
buildReport.Summary.EncryptionClassName = buildParameters.EncryptionServices == null ?
"null" : buildParameters.EncryptionServices.GetType().FullName;
// 构建参数 // 收集器配置
if (buildParameters.BuildPipeline == nameof(BuiltinBuildPipeline)) buildReport.Summary.UniqueBundleName = buildMapContext.Command.UniqueBundleName;
{ buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable;
var builtinBuildParameters = buildParameters as BuiltinBuildParameters; buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle; buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
buildReport.Summary.CompressOption = builtinBuildParameters.CompressOption; buildReport.Summary.IgnoreRuleName = buildMapContext.Command.IgnoreRule.GetType().FullName;
buildReport.Summary.DisableWriteTypeTree = builtinBuildParameters.DisableWriteTypeTree; buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
buildReport.Summary.IgnoreTypeTreeChanges = builtinBuildParameters.IgnoreTypeTreeChanges;
}
else if (buildParameters.BuildPipeline == nameof(ScriptableBuildPipeline))
{
var scriptableBuildParameters = buildParameters as ScriptableBuildParameters;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.CompressOption = scriptableBuildParameters.CompressOption;
buildReport.Summary.DisableWriteTypeTree = scriptableBuildParameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = scriptableBuildParameters.IgnoreTypeTreeChanges;
}
else
{
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.CompressOption = ECompressOption.Uncompressed;
buildReport.Summary.DisableWriteTypeTree = false;
buildReport.Summary.IgnoreTypeTreeChanges = false;
}
// 构建结果 // 构建参数
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount; buildReport.Summary.ClearBuildCacheFiles = buildParameters.ClearBuildCacheFiles;
buildReport.Summary.MainAssetTotalCount = GetMainAssetCount(manifest); buildReport.Summary.UseAssetDependencyDB = buildParameters.UseAssetDependencyDB;
buildReport.Summary.AllBundleTotalCount = GetAllBundleCount(manifest); buildReport.Summary.EnableSharePackRule = buildParameters.EnableSharePackRule;
buildReport.Summary.AllBundleTotalSize = GetAllBundleSize(manifest); buildReport.Summary.EncryptionClassName = buildParameters.EncryptionServices == null ? "null" : buildParameters.EncryptionServices.GetType().FullName;
buildReport.Summary.EncryptedBundleTotalCount = GetEncryptedBundleCount(manifest); if (buildParameters.BuildPipeline == nameof(BuiltinBuildPipeline))
buildReport.Summary.EncryptedBundleTotalSize = GetEncryptedBundleSize(manifest); {
} var builtinBuildParameters = buildParameters as BuiltinBuildParameters;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.CompressOption = builtinBuildParameters.CompressOption;
buildReport.Summary.DisableWriteTypeTree = builtinBuildParameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = builtinBuildParameters.IgnoreTypeTreeChanges;
}
else if (buildParameters.BuildPipeline == nameof(ScriptableBuildPipeline))
{
var scriptableBuildParameters = buildParameters as ScriptableBuildParameters;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.CompressOption = scriptableBuildParameters.CompressOption;
buildReport.Summary.DisableWriteTypeTree = scriptableBuildParameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = scriptableBuildParameters.IgnoreTypeTreeChanges;
}
else
{
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.CompressOption = ECompressOption.Uncompressed;
buildReport.Summary.DisableWriteTypeTree = false;
buildReport.Summary.IgnoreTypeTreeChanges = false;
}
// 资源对象列表 // 构建结果
buildReport.AssetInfos = new List<ReportAssetInfo>(manifest.AssetList.Count); buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
foreach (var packageAsset in manifest.AssetList) buildReport.Summary.MainAssetTotalCount = GetMainAssetCount(manifest);
{ buildReport.Summary.AllBundleTotalCount = GetAllBundleCount(manifest);
var mainBundle = manifest.BundleList[packageAsset.BundleID]; buildReport.Summary.AllBundleTotalSize = GetAllBundleSize(manifest);
ReportAssetInfo reportAssetInfo = new ReportAssetInfo(); buildReport.Summary.EncryptedBundleTotalCount = GetEncryptedBundleCount(manifest);
reportAssetInfo.Address = packageAsset.Address; buildReport.Summary.EncryptedBundleTotalSize = GetEncryptedBundleSize(manifest);
reportAssetInfo.AssetPath = packageAsset.AssetPath; }
reportAssetInfo.AssetTags = packageAsset.AssetTags;
reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(packageAsset.AssetPath);
reportAssetInfo.MainBundleName = mainBundle.BundleName;
reportAssetInfo.MainBundleSize = mainBundle.FileSize;
reportAssetInfo.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, packageAsset.AssetPath);
buildReport.AssetInfos.Add(reportAssetInfo);
}
// 资源列表 // 资源对象列表
buildReport.BundleInfos = new List<ReportBundleInfo>(manifest.BundleList.Count); buildReport.AssetInfos = new List<ReportAssetInfo>(manifest.AssetList.Count);
foreach (var packageBundle in manifest.BundleList) foreach (var packageAsset in manifest.AssetList)
{ {
ReportBundleInfo reportBundleInfo = new ReportBundleInfo(); var mainBundle = manifest.BundleList[packageAsset.BundleID];
reportBundleInfo.BundleName = packageBundle.BundleName; ReportAssetInfo reportAssetInfo = new ReportAssetInfo();
reportBundleInfo.FileName = packageBundle.FileName; reportAssetInfo.Address = packageAsset.Address;
reportBundleInfo.FileHash = packageBundle.FileHash; reportAssetInfo.AssetPath = packageAsset.AssetPath;
reportBundleInfo.FileCRC = packageBundle.FileCRC; reportAssetInfo.AssetTags = packageAsset.AssetTags;
reportBundleInfo.FileSize = packageBundle.FileSize; reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(packageAsset.AssetPath);
reportBundleInfo.Encrypted = packageBundle.Encrypted; reportAssetInfo.MainBundleName = mainBundle.BundleName;
reportBundleInfo.Tags = packageBundle.Tags; reportAssetInfo.MainBundleSize = mainBundle.FileSize;
reportBundleInfo.DependBundles = GetDependBundles(manifest, packageBundle); reportAssetInfo.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, packageAsset.AssetPath);
reportBundleInfo.AllBuiltinAssets = GetAllBuiltinAssets(buildMapContext, packageBundle.BundleName); buildReport.AssetInfos.Add(reportAssetInfo);
buildReport.BundleInfos.Add(reportBundleInfo); }
}
// 冗余资源列表 // 资源列表
buildReport.RedundancyInfos = new List<ReportRedundancyInfo>(buildMapContext.RedundancyInfos); buildReport.BundleInfos = new List<ReportBundleInfo>(manifest.BundleList.Count);
foreach (var packageBundle in manifest.BundleList)
{
ReportBundleInfo reportBundleInfo = new ReportBundleInfo();
reportBundleInfo.BundleName = packageBundle.BundleName;
reportBundleInfo.FileName = packageBundle.FileName;
reportBundleInfo.FileHash = packageBundle.FileHash;
reportBundleInfo.FileCRC = packageBundle.FileCRC;
reportBundleInfo.FileSize = packageBundle.FileSize;
reportBundleInfo.Encrypted = packageBundle.Encrypted;
reportBundleInfo.Tags = packageBundle.Tags;
reportBundleInfo.DependBundles = GetDependBundles(manifest, packageBundle);
reportBundleInfo.AllBuiltinAssets = GetAllBuiltinAssets(buildMapContext, packageBundle.BundleName);
buildReport.BundleInfos.Add(reportBundleInfo);
}
// 序列化文件 // 其它资源列表
string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.PackageName, buildParameters.PackageVersion); buildReport.IndependAssets = new List<ReportIndependAsset>(buildMapContext.IndependAssets);
string filePath = $"{packageOutputDirectory}/{fileName}";
BuildReport.Serialize(filePath, buildReport);
BuildLogger.Log($"Create build report file: {filePath}");
}
/// <summary> // 序列化文件
/// 获取资源对象依赖的所有资源包 string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
/// </summary> string filePath = $"{packageOutputDirectory}/{fileName}";
private List<string> GetDependBundles(PackageManifest manifest, PackageBundle packageBundle) BuildReport.Serialize(filePath, buildReport);
{ BuildLogger.Log($"Create build report file: {filePath}");
List<string> dependBundles = new List<string>(packageBundle.DependIDs.Length); }
foreach (int index in packageBundle.DependIDs)
{
string dependBundleName = manifest.BundleList[index].BundleName;
dependBundles.Add(dependBundleName);
}
return dependBundles;
}
/// <summary> /// <summary>
/// 获取资源对象依赖的其它所有资源 /// 获取资源对象依赖的所有资源
/// </summary> /// </summary>
private List<string> GetDependAssets(BuildMapContext buildMapContext, string bundleName, string assetPath) private List<string> GetDependBundles(PackageManifest manifest, PackageBundle packageBundle)
{ {
List<string> result = new List<string>(); List<string> dependBundles = new List<string>(packageBundle.DependIDs.Length);
var bundleInfo = buildMapContext.GetBundleInfo(bundleName); foreach (int index in packageBundle.DependIDs)
{ {
BuildAssetInfo findAssetInfo = null; string dependBundleName = manifest.BundleList[index].BundleName;
foreach (var assetInfo in bundleInfo.MainAssets) dependBundles.Add(dependBundleName);
{ }
if (assetInfo.AssetPath == assetPath) dependBundles.Sort();
{ return dependBundles;
findAssetInfo = assetInfo; }
break;
}
}
if (findAssetInfo == null)
{
throw new Exception($"Should never get here ! Not found asset {assetPath} in bunlde {bundleName}");
}
foreach (var dependAssetInfo in findAssetInfo.AllDependAssetInfos)
{
result.Add(dependAssetInfo.AssetPath);
}
}
return result;
}
/// <summary> /// <summary>
/// 获取资源包内的所有资源 /// 获取资源对象依赖的其它所有资源
/// </summary> /// </summary>
private List<string> GetAllBuiltinAssets(BuildMapContext buildMapContext, string bundleName) private List<string> GetDependAssets(BuildMapContext buildMapContext, string bundleName, string assetPath)
{ {
var bundleInfo = buildMapContext.GetBundleInfo(bundleName); List<string> result = new List<string>();
return bundleInfo.GetAllBuiltinAssetPaths(); var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
} {
BuildAssetInfo findAssetInfo = null;
foreach (var buildAsset in bundleInfo.MainAssets)
{
if (buildAsset.AssetInfo.AssetPath == assetPath)
{
findAssetInfo = buildAsset;
break;
}
}
if (findAssetInfo == null)
{
throw new Exception($"Should never get here ! Not found asset {assetPath} in bunlde {bundleName}");
}
foreach (var dependAssetInfo in findAssetInfo.AllDependAssetInfos)
{
result.Add(dependAssetInfo.AssetInfo.AssetPath);
}
}
result.Sort();
return result;
}
private int GetMainAssetCount(PackageManifest manifest) /// <summary>
{ /// 获取该资源包内的所有资源
return manifest.AssetList.Count; /// </summary>
} private List<string> GetAllBuiltinAssets(BuildMapContext buildMapContext, string bundleName)
private int GetAllBundleCount(PackageManifest manifest) {
{ var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
return manifest.BundleList.Count; List<string> result = bundleInfo.GetAllBuiltinAssetPaths();
} result.Sort();
private long GetAllBundleSize(PackageManifest manifest) return result;
{ }
long fileBytes = 0;
foreach (var packageBundle in manifest.BundleList) private int GetMainAssetCount(PackageManifest manifest)
{ {
fileBytes += packageBundle.FileSize; return manifest.AssetList.Count;
} }
return fileBytes; private int GetAllBundleCount(PackageManifest manifest)
} {
private int GetEncryptedBundleCount(PackageManifest manifest) return manifest.BundleList.Count;
{ }
int fileCount = 0; private long GetAllBundleSize(PackageManifest manifest)
foreach (var packageBundle in manifest.BundleList) {
{ long fileBytes = 0;
if (packageBundle.Encrypted) foreach (var packageBundle in manifest.BundleList)
fileCount++; {
} fileBytes += packageBundle.FileSize;
return fileCount; }
} return fileBytes;
private long GetEncryptedBundleSize(PackageManifest manifest) }
{ private int GetEncryptedBundleCount(PackageManifest manifest)
long fileBytes = 0; {
foreach (var packageBundle in manifest.BundleList) int fileCount = 0;
{ foreach (var packageBundle in manifest.BundleList)
if (packageBundle.Encrypted) {
fileBytes += packageBundle.FileSize; if (packageBundle.Encrypted)
} fileCount++;
return fileBytes; }
} return fileCount;
} }
private long GetEncryptedBundleSize(PackageManifest manifest)
{
long fileBytes = 0;
foreach (var packageBundle in manifest.BundleList)
{
if (packageBundle.Encrypted)
fileBytes += packageBundle.FileSize;
}
return fileBytes;
}
}
} }

View File

@@ -6,45 +6,45 @@ using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskEncryption public class TaskEncryption
{ {
/// <summary> /// <summary>
/// 加密文件 /// 加密文件
/// </summary> /// </summary>
public void EncryptingBundleFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext) public void EncryptingBundleFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
{ {
var encryptionServices = buildParametersContext.Parameters.EncryptionServices; var encryptionServices = buildParametersContext.Parameters.EncryptionServices;
if (encryptionServices == null) if (encryptionServices == null)
return; return;
if (encryptionServices.GetType() == typeof(EncryptionNone)) if (encryptionServices.GetType() == typeof(EncryptionNone))
return; return;
int progressValue = 0; int progressValue = 0;
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
EncryptFileInfo fileInfo = new EncryptFileInfo(); EncryptFileInfo fileInfo = new EncryptFileInfo();
fileInfo.BundleName = bundleInfo.BundleName; fileInfo.BundleName = bundleInfo.BundleName;
fileInfo.FilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; fileInfo.FileLoadPath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
var encryptResult = encryptionServices.Encrypt(fileInfo); var encryptResult = encryptionServices.Encrypt(fileInfo);
if (encryptResult.Encrypted) if (encryptResult.Encrypted)
{ {
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt"; string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt";
FileUtility.WriteAllBytes(filePath, encryptResult.EncryptedData); FileUtility.WriteAllBytes(filePath, encryptResult.EncryptedData);
bundleInfo.EncryptedFilePath = filePath; bundleInfo.EncryptedFilePath = filePath;
bundleInfo.Encrypted = true; bundleInfo.Encrypted = true;
BuildLogger.Log($"Bundle file encryption complete: {filePath}"); BuildLogger.Log($"Bundle file encryption complete: {filePath}");
} }
else else
{ {
bundleInfo.Encrypted = false; bundleInfo.Encrypted = false;
} }
// 进度条 // 进度条
EditorTools.DisplayProgressBar("Encrypting bundle", ++progressValue, buildMapContext.Collection.Count); EditorTools.DisplayProgressBar("Encrypting bundle", ++progressValue, buildMapContext.Collection.Count);
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();
} }
} }
} }

View File

@@ -7,184 +7,223 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskGetBuildMap public class TaskGetBuildMap
{ {
/// <summary> /// <summary>
/// 生成资源构建上下文 /// 生成资源构建上下文
/// </summary> /// </summary>
public BuildMapContext CreateBuildMap(BuildParameters buildParameters) public BuildMapContext CreateBuildMap(bool simulateBuild, BuildParameters buildParameters)
{ {
var buildMode = buildParameters.BuildMode; BuildMapContext context = new BuildMapContext();
var packageName = buildParameters.PackageName; var packageName = buildParameters.PackageName;
Dictionary<string, BuildAssetInfo> allBuildAssetInfos = new Dictionary<string, BuildAssetInfo>(1000); Dictionary<string, BuildAssetInfo> allBuildAssetInfos = new Dictionary<string, BuildAssetInfo>(1000);
// 1. 获取所有收集器收集的资源 // 1. 获取所有收集器收集的资源
var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName); bool useAssetDependencyDB = buildParameters.UseAssetDependencyDB;
List<CollectAssetInfo> allCollectAssetInfos = collectResult.CollectAssets; var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(simulateBuild, useAssetDependencyDB, packageName);
List<CollectAssetInfo> allCollectAssets = collectResult.CollectAssets;
// 2. 剔除未被引用的依赖项资源 // 2. 剔除未被引用的依赖项资源
RemoveZeroReferenceAssets(allCollectAssetInfos); RemoveZeroReferenceAssets(context, allCollectAssets);
// 3. 录入所有收集器主动收集的资源 // 3. 录入所有收集器主动收集的资源
foreach (var collectAssetInfo in allCollectAssetInfos) foreach (var collectAssetInfo in allCollectAssets)
{ {
if (allBuildAssetInfos.ContainsKey(collectAssetInfo.AssetPath) == false) if (allBuildAssetInfos.ContainsKey(collectAssetInfo.AssetInfo.AssetPath))
{ {
if (collectAssetInfo.CollectorType != ECollectorType.MainAssetCollector) throw new Exception($"Should never get here !");
{ }
if (collectAssetInfo.AssetTags.Count > 0)
{
collectAssetInfo.AssetTags.Clear();
string warning = BuildLogger.GetErrorMessage(ErrorCode.RemoveInvalidTags, $"Remove asset tags that don't work, see the asset collector type : {collectAssetInfo.AssetPath}");
BuildLogger.Warning(warning);
}
}
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetPath); if (collectAssetInfo.CollectorType != ECollectorType.MainAssetCollector)
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); {
allBuildAssetInfos.Add(collectAssetInfo.AssetPath, buildAssetInfo); if (collectAssetInfo.AssetTags.Count > 0)
} {
else collectAssetInfo.AssetTags.Clear();
{ string warning = BuildLogger.GetErrorMessage(ErrorCode.RemoveInvalidTags, $"Remove asset tags that don't work, see the asset collector type : {collectAssetInfo.AssetInfo.AssetPath}");
throw new Exception($"Should never get here !"); BuildLogger.Warning(warning);
} }
} }
// 4. 录入所有收集资源依赖的其它资源 var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetInfo);
foreach (var collectAssetInfo in allCollectAssetInfos) buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
{ allBuildAssetInfos.Add(collectAssetInfo.AssetInfo.AssetPath, buildAssetInfo);
string bundleName = collectAssetInfo.BundleName; }
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
{
if (allBuildAssetInfos.ContainsKey(dependAssetPath))
{
allBuildAssetInfos[dependAssetPath].AddReferenceBundleName(bundleName);
}
else
{
var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
buildAssetInfo.AddReferenceBundleName(bundleName);
allBuildAssetInfos.Add(dependAssetPath, buildAssetInfo);
}
}
}
// 5. 填充所有收集资源依赖列表 // 4. 录入所有收集资源依赖的其它资源
foreach (var collectAssetInfo in allCollectAssetInfos) foreach (var collectAssetInfo in allCollectAssets)
{ {
var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count); string bundleName = collectAssetInfo.BundleName;
foreach (var dependAssetPath in collectAssetInfo.DependAssets) foreach (var dependAsset in collectAssetInfo.DependAssets)
{ {
if (allBuildAssetInfos.TryGetValue(dependAssetPath, out BuildAssetInfo value)) if (allBuildAssetInfos.TryGetValue(dependAsset.AssetPath, out var value))
dependAssetInfos.Add(value); {
else value.AddReferenceBundleName(bundleName);
throw new Exception("Should never get here !"); }
} else
allBuildAssetInfos[collectAssetInfo.AssetPath].SetDependAssetInfos(dependAssetInfos); {
} var buildAssetInfo = new BuildAssetInfo(dependAsset);
buildAssetInfo.AddReferenceBundleName(bundleName);
allBuildAssetInfos.Add(dependAsset.AssetPath, buildAssetInfo);
}
}
}
// 6. 自动收集所有依赖的着色器 // 5. 填充所有收集资源的依赖列表
if (collectResult.Command.AutoCollectShaders) foreach (var collectAssetInfo in allCollectAssets)
{ {
foreach (var buildAssetInfo in allBuildAssetInfos.Values) var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count);
{ foreach (var dependAsset in collectAssetInfo.DependAssets)
if (buildAssetInfo.CollectorType == ECollectorType.None) {
{ if (allBuildAssetInfos.TryGetValue(dependAsset.AssetPath, out BuildAssetInfo value))
if (buildAssetInfo.AssetType == typeof(UnityEngine.Shader) || buildAssetInfo.AssetType == typeof(UnityEngine.ShaderVariantCollection)) dependAssetInfos.Add(value);
{ else
buildAssetInfo.SetShaderBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName); throw new Exception("Should never get here !");
} }
} allBuildAssetInfos[collectAssetInfo.AssetInfo.AssetPath].SetDependAssetInfos(dependAssetInfos);
} }
}
// 7. 记录关键信息 // 6. 自动收集所有依赖的着色器
BuildMapContext context = new BuildMapContext(); if (collectResult.Command.AutoCollectShaders)
context.AssetFileCount = allBuildAssetInfos.Count; {
context.Command = collectResult.Command; // 获取着色器打包规则结果
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
string shaderBundleName = shaderPackRuleResult.GetBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName);
foreach (var buildAssetInfo in allBuildAssetInfos.Values)
{
if (buildAssetInfo.CollectorType == ECollectorType.None)
{
if (buildAssetInfo.AssetInfo.IsShaderAsset())
{
buildAssetInfo.SetBundleName(shaderBundleName);
}
}
}
}
// 8. 记录冗余资源 // 7. 计算共享资源的包名
foreach (var buildAssetInfo in allBuildAssetInfos.Values) if (buildParameters.EnableSharePackRule)
{ {
if (buildAssetInfo.IsRedundancyAsset()) PreProcessPackShareBundle(buildParameters, collectResult.Command, allBuildAssetInfos);
{ foreach (var buildAssetInfo in allBuildAssetInfos.Values)
var redundancyInfo = new ReportRedundancyInfo(); {
redundancyInfo.AssetPath = buildAssetInfo.AssetPath; if (buildAssetInfo.HasBundleName() == false)
redundancyInfo.AssetType = buildAssetInfo.AssetType.Name; {
redundancyInfo.AssetGUID = buildAssetInfo.AssetGUID; PackRuleResult packRuleResult = GetShareBundleName(buildAssetInfo);
redundancyInfo.FileSize = FileUtility.GetFileSize(buildAssetInfo.AssetPath); if (packRuleResult.IsValid())
redundancyInfo.Number = buildAssetInfo.GetReferenceBundleCount(); {
context.RedundancyInfos.Add(redundancyInfo); string shareBundleName = packRuleResult.GetShareBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName);
} buildAssetInfo.SetBundleName(shareBundleName);
} }
}
}
PostProcessPackShareBundle();
}
// 9. 移除不参与构建的资源 // 8. 记录关键信息
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>(); context.AssetFileCount = allBuildAssetInfos.Count;
foreach (var buildAssetInfo in allBuildAssetInfos.Values) context.Command = collectResult.Command;
{
if (buildAssetInfo.HasBundleName() == false)
removeBuildList.Add(buildAssetInfo);
}
foreach (var removeValue in removeBuildList)
{
allBuildAssetInfos.Remove(removeValue.AssetPath);
}
// 10. 构建资源列表 // 9. 移除不参与构建资源
var allPackAssets = allBuildAssetInfos.Values.ToList(); List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
if (allPackAssets.Count == 0) foreach (var buildAssetInfo in allBuildAssetInfos.Values)
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.PackAssetListIsEmpty, "The pack asset info is empty !"); if (buildAssetInfo.HasBundleName() == false)
throw new Exception(message); removeBuildList.Add(buildAssetInfo);
} }
foreach (var assetInfo in allPackAssets) foreach (var removeValue in removeBuildList)
{ {
context.PackAsset(assetInfo); allBuildAssetInfos.Remove(removeValue.AssetInfo.AssetPath);
} }
return context; // 10. 构建资源列表
} var allPackAssets = allBuildAssetInfos.Values.ToList();
private void RemoveZeroReferenceAssets(List<CollectAssetInfo> allCollectAssetInfos) if (allPackAssets.Count == 0)
{ {
// 1. 检测是否任何存在依赖资源 string message = BuildLogger.GetErrorMessage(ErrorCode.PackAssetListIsEmpty, "The pack asset info is empty !");
if (allCollectAssetInfos.Exists(x => x.CollectorType == ECollectorType.DependAssetCollector) == false) throw new Exception(message);
return; }
foreach (var assetInfo in allPackAssets)
{
context.PackAsset(assetInfo);
}
// 2. 获取所有主资源的依赖资源集合 return context;
HashSet<string> allDependAsset = new HashSet<string>(); }
foreach (var collectAssetInfo in allCollectAssetInfos) private void RemoveZeroReferenceAssets(BuildMapContext context, List<CollectAssetInfo> allCollectAssets)
{ {
var collectorType = collectAssetInfo.CollectorType; // 1. 检测依赖资源收集器是否存在
if (collectorType == ECollectorType.MainAssetCollector || collectorType == ECollectorType.StaticAssetCollector) if (allCollectAssets.Exists(x => x.CollectorType == ECollectorType.DependAssetCollector) == false)
{ return;
foreach (var dependAsset in collectAssetInfo.DependAssets)
{
if (allDependAsset.Contains(dependAsset) == false)
allDependAsset.Add(dependAsset);
}
}
}
// 3. 找出所有零引用的依赖资源集合 // 2. 获取所有主资源的依赖资源集合
List<CollectAssetInfo> removeList = new List<CollectAssetInfo>(); HashSet<string> allDependAsset = new HashSet<string>();
foreach (var collectAssetInfo in allCollectAssetInfos) foreach (var collectAsset in allCollectAssets)
{ {
var collectorType = collectAssetInfo.CollectorType; var collectorType = collectAsset.CollectorType;
if (collectorType == ECollectorType.DependAssetCollector) if (collectorType == ECollectorType.MainAssetCollector || collectorType == ECollectorType.StaticAssetCollector)
{ {
if (allDependAsset.Contains(collectAssetInfo.AssetPath) == false) foreach (var dependAsset in collectAsset.DependAssets)
removeList.Add(collectAssetInfo); {
} if (allDependAsset.Contains(dependAsset.AssetPath) == false)
} allDependAsset.Add(dependAsset.AssetPath);
}
}
}
// 4. 移除所有零引用的依赖资源 // 3. 找出所有零引用的依赖资源集合
foreach (var removeValue in removeList) List<CollectAssetInfo> removeList = new List<CollectAssetInfo>();
{ foreach (var collectAssetInfo in allCollectAssets)
string warning = BuildLogger.GetErrorMessage(ErrorCode.FoundUndependedAsset, $"Found undepended asset and remove it : {removeValue.AssetPath}"); {
BuildLogger.Warning(warning); var collectorType = collectAssetInfo.CollectorType;
allCollectAssetInfos.Remove(removeValue); if (collectorType == ECollectorType.DependAssetCollector)
} {
} if (allDependAsset.Contains(collectAssetInfo.AssetInfo.AssetPath) == false)
} removeList.Add(collectAssetInfo);
}
}
// 4. 移除所有零引用的依赖资源
foreach (var removeValue in removeList)
{
string warning = BuildLogger.GetErrorMessage(ErrorCode.FoundUndependedAsset, $"Found undepended asset and remove it : {removeValue.AssetInfo.AssetPath}");
BuildLogger.Warning(warning);
var independAsset = new ReportIndependAsset();
independAsset.AssetPath = removeValue.AssetInfo.AssetPath;
independAsset.AssetGUID = removeValue.AssetInfo.AssetGUID;
independAsset.AssetType = removeValue.AssetInfo.AssetType.ToString();
independAsset.FileSize = FileUtility.GetFileSize(removeValue.AssetInfo.AssetPath);
context.IndependAssets.Add(independAsset);
allCollectAssets.Remove(removeValue);
}
}
#region
/// <summary>
/// 共享资源打包前置处理
/// </summary>
protected virtual void PreProcessPackShareBundle(BuildParameters buildParameters, CollectCommand command, Dictionary<string, BuildAssetInfo> allBuildAssetInfos)
{
}
/// <summary>
/// 共享资源打包后置处理
/// </summary>
protected virtual void PostProcessPackShareBundle()
{
}
/// <summary>
/// 获取共享资源包名称
/// </summary>
protected virtual PackRuleResult GetShareBundleName(BuildAssetInfo buildAssetInfo)
{
string bundleName = Path.GetDirectoryName(buildAssetInfo.AssetInfo.AssetPath);
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
return result;
}
#endregion
}
} }

View File

@@ -7,72 +7,63 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public abstract class TaskUpdateBundleInfo public abstract class TaskUpdateBundleInfo
{ {
public void UpdateBundleInfo(BuildContext context) public void UpdateBundleInfo(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory(); string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
int outputNameStyle = (int)buildParametersContext.Parameters.FileNameStyle; int outputNameStyle = (int)buildParametersContext.Parameters.FileNameStyle;
// 1.检测文件名长度 // 1.检测文件名长度
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
// NOTE检测文件名长度不要超过260字符。 // NOTE检测文件名长度不要超过260字符。
string fileName = bundleInfo.BundleName; string fileName = bundleInfo.BundleName;
if (fileName.Length >= 260) if (fileName.Length >= 260)
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.CharactersOverTheLimit, $"Bundle file name character count exceeds limit : {fileName}"); string message = BuildLogger.GetErrorMessage(ErrorCode.CharactersOverTheLimit, $"Bundle file name character count exceeds limit : {fileName}");
throw new Exception(message); throw new Exception(message);
} }
} }
// 2.更新构建输出的文件路径 // 2.更新构建输出的文件路径
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
bundleInfo.BuildOutputFilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; bundleInfo.BuildOutputFilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
if (bundleInfo.Encrypted) if (bundleInfo.Encrypted)
bundleInfo.PackageSourceFilePath = bundleInfo.EncryptedFilePath; bundleInfo.PackageSourceFilePath = bundleInfo.EncryptedFilePath;
else else
bundleInfo.PackageSourceFilePath = bundleInfo.BuildOutputFilePath; bundleInfo.PackageSourceFilePath = bundleInfo.BuildOutputFilePath;
} }
// 3.更新文件其它信息 // 3.更新文件其它信息
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
bundleInfo.PackageUnityHash = GetUnityHash(bundleInfo, context); bundleInfo.PackageUnityHash = GetUnityHash(bundleInfo, context);
bundleInfo.PackageUnityCRC = GetUnityCRC(bundleInfo, context); bundleInfo.PackageUnityCRC = GetUnityCRC(bundleInfo, context);
bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo.PackageSourceFilePath, buildParametersContext); bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo, buildParametersContext);
bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo.PackageSourceFilePath, buildParametersContext); bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo, buildParametersContext);
bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo.PackageSourceFilePath, buildParametersContext); bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo, buildParametersContext);
} }
// 4.更新补丁包输出的文件路径 // 4.更新补丁包输出的文件路径
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
string bundleName = bundleInfo.BundleName; string bundleName = bundleInfo.BundleName;
string fileHash = bundleInfo.PackageFileHash; string fileHash = bundleInfo.PackageFileHash;
string fileExtension = ManifestTools.GetRemoteBundleFileExtension(bundleName); string fileExtension = ManifestTools.GetRemoteBundleFileExtension(bundleName);
string fileName = ManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleName, fileExtension, fileHash); string fileName = ManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleName, fileExtension, fileHash);
bundleInfo.PackageDestFilePath = $"{packageOutputDirectory}/{fileName}"; bundleInfo.PackageDestFilePath = $"{packageOutputDirectory}/{fileName}";
} }
} }
protected abstract string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context); protected abstract string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context);
protected abstract uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context); protected abstract uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context);
protected abstract string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext); protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
protected abstract string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext); protected abstract string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
protected abstract long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext); protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
}
protected string GetFilePathTempHash(string filePath)
{
byte[] bytes = Encoding.UTF8.GetBytes(filePath);
return HashUtility.BytesMD5(bytes);
// 注意:在文件路径的哈希值冲突的情况下,可以使用下面的方法
//return $"{HashUtility.BytesMD5(bytes)}-{Guid.NewGuid():N}";
}
}
} }

View File

@@ -7,48 +7,41 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskBuilding_BBP : IBuildTask public class TaskBuilding_BBP : IBuildTask
{ {
public class BuildResultContext : IContextObject public class BuildResultContext : IContextObject
{ {
public AssetBundleManifest UnityManifest; public AssetBundleManifest UnityManifest;
} }
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var builtinBuildParameters = buildParametersContext.Parameters as BuiltinBuildParameters; var builtinBuildParameters = buildParametersContext.Parameters as BuiltinBuildParameters;
// 模拟构建模式下跳过引擎构建 // 开始构建
var buildMode = buildParametersContext.Parameters.BuildMode; string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
if (buildMode == EBuildMode.SimulateBuild) BuildAssetBundleOptions buildOptions = builtinBuildParameters.GetBundleBuildOptions();
return; AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), buildOptions, buildParametersContext.Parameters.BuildTarget);
if (unityManifest == null)
{
string message = BuildLogger.GetErrorMessage(ErrorCode.UnityEngineBuildFailed, "UnityEngine build failed !");
throw new Exception(message);
}
// 开始构建 // 检测输出目录
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); string unityOutputManifestFilePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}";
BuildAssetBundleOptions buildOptions = builtinBuildParameters.GetBundleBuildOptions(); if (System.IO.File.Exists(unityOutputManifestFilePath) == false)
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), buildOptions, buildParametersContext.Parameters.BuildTarget); {
if (unityManifest == null) string message = BuildLogger.GetErrorMessage(ErrorCode.UnityEngineBuildFatal, $"Not found output {nameof(AssetBundleManifest)} file : {unityOutputManifestFilePath}");
{ throw new Exception(message);
string message = BuildLogger.GetErrorMessage(ErrorCode.UnityEngineBuildFailed, "UnityEngine build failed !"); }
throw new Exception(message);
}
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) BuildLogger.Log("UnityEngine build success !");
{ BuildResultContext buildResultContext = new BuildResultContext();
string unityOutputManifestFilePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}"; buildResultContext.UnityManifest = unityManifest;
if (System.IO.File.Exists(unityOutputManifestFilePath) == false) context.SetContextObject(buildResultContext);
{ }
string message = BuildLogger.GetErrorMessage(ErrorCode.UnityEngineBuildFatal, $"Not found output {nameof(AssetBundleManifest)} file : {unityOutputManifestFilePath}"); }
throw new Exception(message);
}
}
BuildLogger.Log("UnityEngine build success !");
BuildResultContext buildResultContext = new BuildResultContext();
buildResultContext.UnityManifest = unityManifest;
context.SetContextObject(buildResultContext);
}
}
} }

View File

@@ -6,21 +6,16 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCopyBuildinFiles_BBP : TaskCopyBuildinFiles, IBuildTask public class TaskCopyBuildinFiles_BBP : TaskCopyBuildinFiles, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var manifestContext = context.GetContextObject<ManifestContext>(); var manifestContext = context.GetContextObject<ManifestContext>();
var buildMode = buildParametersContext.Parameters.BuildMode; if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
{
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
{ }
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None) }
{ }
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
}
}
}
}
} }

View File

@@ -5,21 +5,21 @@ using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCreateManifest_BBP : TaskCreateManifest, IBuildTask public class TaskCreateManifest_BBP : TaskCreateManifest, IBuildTask
{ {
private TaskBuilding_BBP.BuildResultContext _buildResultContext = null; private TaskBuilding_BBP.BuildResultContext _buildResultContext = null;
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
CreateManifestFile(context); CreateManifestFile(true, true, context);
} }
protected override string[] GetBundleDepends(BuildContext context, string bundleName) protected override string[] GetBundleDepends(BuildContext context, string bundleName)
{ {
if (_buildResultContext == null) if (_buildResultContext == null)
_buildResultContext = context.GetContextObject<TaskBuilding_BBP.BuildResultContext>(); _buildResultContext = context.GetContextObject<TaskBuilding_BBP.BuildResultContext>();
return _buildResultContext.UnityManifest.GetAllDependencies(bundleName); return _buildResultContext.UnityManifest.GetAllDependencies(bundleName);
} }
} }
} }

View File

@@ -3,51 +3,47 @@ using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCreatePackage_BBP : IBuildTask public class TaskCreatePackage_BBP : IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var buildMode = buildParameters.Parameters.BuildMode; CreatePackagePatch(buildParameters, buildMapContext);
if (buildMode != EBuildMode.SimulateBuild && buildMode != EBuildMode.DryRunBuild) }
{
CreatePackageCatalog(buildParameters, buildMapContext);
}
}
/// <summary> /// <summary>
/// 拷贝补丁文件到补丁包目录 /// 拷贝补丁文件到补丁包目录
/// </summary> /// </summary>
private void CreatePackageCatalog(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext) private void CreatePackagePatch(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
{ {
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory(); string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
BuildLogger.Log($"Start making patch package: {packageOutputDirectory}"); BuildLogger.Log($"Start making patch package: {packageOutputDirectory}");
// 拷贝UnityManifest序列化文件 // 拷贝UnityManifest序列化文件
{ {
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}"; string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}";
string destPath = $"{packageOutputDirectory}/{YooAssetSettings.OutputFolderName}"; string destPath = $"{packageOutputDirectory}/{YooAssetSettings.OutputFolderName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝UnityManifest文本文件 // 拷贝UnityManifest文本文件
{ {
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest"; string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest";
string destPath = $"{packageOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest"; string destPath = $"{packageOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝所有补丁文件 // 拷贝所有补丁文件
int progressValue = 0; int progressValue = 0;
int fileTotalCount = buildMapContext.Collection.Count; int fileTotalCount = buildMapContext.Collection.Count;
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
EditorTools.CopyFile(bundleInfo.PackageSourceFilePath, bundleInfo.PackageDestFilePath, true); EditorTools.CopyFile(bundleInfo.PackageSourceFilePath, bundleInfo.PackageDestFilePath, true);
EditorTools.DisplayProgressBar("Copy patch file", ++progressValue, fileTotalCount); EditorTools.DisplayProgressBar("Copy patch file", ++progressValue, fileTotalCount);
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();
} }
} }
} }

View File

@@ -6,19 +6,14 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCreateReport_BBP : TaskCreateReport, IBuildTask public class TaskCreateReport_BBP : TaskCreateReport, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var manifestContext = context.GetContextObject<ManifestContext>(); var manifestContext = context.GetContextObject<ManifestContext>();
CreateReportFile(buildParameters, buildMapContext, manifestContext);
var buildMode = buildParameters.Parameters.BuildMode; }
if (buildMode != EBuildMode.SimulateBuild) }
{
CreateReportFile(buildParameters, buildMapContext, manifestContext);
}
}
}
} }

View File

@@ -1,23 +1,13 @@
using System; 
using System.Linq;
using System.IO;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskEncryption_BBP : TaskEncryption, IBuildTask public class TaskEncryption_BBP : TaskEncryption, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
EncryptingBundleFiles(buildParameters, buildMapContext);
var buildMode = buildParameters.Parameters.BuildMode; }
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) }
{
EncryptingBundleFiles(buildParameters, buildMapContext);
}
}
}
} }

View File

@@ -7,13 +7,13 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskGetBuildMap_BBP : TaskGetBuildMap, IBuildTask public class TaskGetBuildMap_BBP : TaskGetBuildMap, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = CreateBuildMap(buildParametersContext.Parameters); var buildMapContext = CreateBuildMap(false, buildParametersContext.Parameters);
context.SetContextObject(buildMapContext); context.SetContextObject(buildMapContext);
} }
} }
} }

View File

@@ -6,25 +6,54 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskPrepare_BBP : IBuildTask public class TaskPrepare_BBP : IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters; var buildParameters = buildParametersContext.Parameters;
var builtinBuildParameters = buildParameters as BuiltinBuildParameters; var builtinBuildParameters = buildParameters as BuiltinBuildParameters;
// 检测基础构建参数 // 检测基础构建参数
buildParametersContext.CheckBuildParameters(); buildParametersContext.CheckBuildParameters();
// 检测Unity版本 // 检测是否有未保存场景
if (EditorTools.HasDirtyScenes())
{
string message = BuildLogger.GetErrorMessage(ErrorCode.FoundUnsavedScene, "Found unsaved scene !");
throw new Exception(message);
}
// 删除包裹目录
if (buildParameters.ClearBuildCacheFiles)
{
string packageRootDirectory = buildParameters.GetPackageRootDirectory();
if (EditorTools.DeleteDirectory(packageRootDirectory))
{
BuildLogger.Log($"Delete package root directory: {packageRootDirectory}");
}
}
// 检测包裹输出目录是否存在
string packageOutputDirectory = buildParameters.GetPackageOutputDirectory();
if (Directory.Exists(packageOutputDirectory))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageOutputDirectoryExists, $"Package outout directory exists: {packageOutputDirectory}");
throw new Exception(message);
}
// 如果输出目录不存在
string pipelineOutputDirectory = buildParameters.GetPipelineOutputDirectory();
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
{
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
}
// 检测Unity版本
#if UNITY_2021_3_OR_NEWER #if UNITY_2021_3_OR_NEWER
if (buildParameters.BuildMode != EBuildMode.SimulateBuild) string warning = BuildLogger.GetErrorMessage(ErrorCode.RecommendScriptBuildPipeline, $"Starting with UnityEngine2021, recommend use script build pipeline (SBP) !");
{ BuildLogger.Warning(warning);
string warning = BuildLogger.GetErrorMessage(ErrorCode.RecommendScriptBuildPipeline, $"Starting with UnityEngine2021, recommend use script build pipeline (SBP) !");
BuildLogger.Warning(warning);
}
#endif #endif
} }
} }
} }

View File

@@ -6,83 +6,54 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskUpdateBundleInfo_BBP : TaskUpdateBundleInfo, IBuildTask public class TaskUpdateBundleInfo_BBP : TaskUpdateBundleInfo, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
UpdateBundleInfo(context); UpdateBundleInfo(context);
} }
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context) protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildResult = context.GetContextObject<TaskBuilding_BBP.BuildResultContext>();
var parameters = buildParametersContext.Parameters; var hash = buildResult.UnityManifest.GetAssetBundleHash(bundleInfo.BundleName);
var buildMode = parameters.BuildMode; if (hash.isValid)
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) {
{ return hash.ToString();
return "00000000000000000000000000000000"; //32位 }
} else
else {
{ string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleHash, $"Not found unity bundle hash : {bundleInfo.BundleName}");
var buildResult = context.GetContextObject<TaskBuilding_BBP.BuildResultContext>(); throw new Exception(message);
var hash = buildResult.UnityManifest.GetAssetBundleHash(bundleInfo.BundleName); }
if (hash.isValid) }
{ protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
return hash.ToString(); {
} string filePath = bundleInfo.BuildOutputFilePath;
else if (BuildPipeline.GetCRCForAssetBundle(filePath, out uint crc))
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleHash, $"Not found unity bundle hash : {bundleInfo.BundleName}"); return crc;
throw new Exception(message); }
} else
} {
} string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleCRC, $"Not found unity bundle crc : {bundleInfo.BundleName}");
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context) throw new Exception(message);
{ }
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); }
var parameters = buildParametersContext.Parameters; protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
var buildMode = parameters.BuildMode; {
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) string filePath = bundleInfo.PackageSourceFilePath;
{ return HashUtility.FileMD5(filePath);
return 0; }
} protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
else {
{ string filePath = bundleInfo.PackageSourceFilePath;
string filePath = bundleInfo.BuildOutputFilePath; return HashUtility.FileCRC32(filePath);
if (BuildPipeline.GetCRCForAssetBundle(filePath, out uint crc)) }
{ protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
return crc; {
} string filePath = bundleInfo.PackageSourceFilePath;
else return FileUtility.GetFileSize(filePath);
{ }
string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleCRC, $"Not found unity bundle crc : {bundleInfo.BundleName}"); }
throw new Exception(message);
}
}
}
protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return GetFilePathTempHash(filePath);
else
return HashUtility.FileMD5(filePath);
}
protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return "00000000"; //8位
else
return HashUtility.FileCRC32(filePath);
}
protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return 0;
else
return FileUtility.GetFileSize(filePath);
}
}
} }

View File

@@ -8,66 +8,61 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskVerifyBuildResult_BBP : IBuildTask public class TaskVerifyBuildResult_BBP : IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters as BuiltinBuildParameters; var buildParameters = buildParametersContext.Parameters as BuiltinBuildParameters;
// 模拟构建模式下跳过验证 // 验证构建结果
if (buildParameters.BuildMode == EBuildMode.SimulateBuild) if (buildParameters.VerifyBuildingResult)
return; {
var buildResultContext = context.GetContextObject<TaskBuilding_BBP.BuildResultContext>();
VerifyingBuildingResult(context, buildResultContext.UnityManifest);
}
}
// 验证构建结果 /// <summary>
if (buildParameters.VerifyBuildingResult) /// 验证构建结果
{ /// </summary>
var buildResultContext = context.GetContextObject<TaskBuilding_BBP.BuildResultContext>(); private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest)
VerifyingBuildingResult(context, buildResultContext.UnityManifest); {
} var buildMapContext = context.GetContextObject<BuildMapContext>();
} string[] unityBuildContent = unityManifest.GetAllAssetBundles();
/// <summary> // 1. 计划内容
/// 验证构建结果 string[] planningContent = buildMapContext.Collection.Select(t => t.BundleName).ToArray();
/// </summary>
private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
string[] unityCreateBundles = unityManifest.GetAllAssetBundles();
// 1. 过滤掉原生Bundle // 2. 验证差异
string[] mapBundles = buildMapContext.Collection.Select(t => t.BundleName).ToArray(); List<string> exceptBundleList1 = unityBuildContent.Except(planningContent).ToList();
if (exceptBundleList1.Count > 0)
{
foreach (var exceptBundle in exceptBundleList1)
{
string warning = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildBundle, $"Found unintended build bundle : {exceptBundle}");
BuildLogger.Warning(warning);
}
// 2. 验证Bundle string exception = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildResult, $"Unintended build, See the detailed warnings !");
List<string> exceptBundleList1 = unityCreateBundles.Except(mapBundles).ToList(); throw new Exception(exception);
if (exceptBundleList1.Count > 0) }
{
foreach (var exceptBundle in exceptBundleList1)
{
string warning = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildBundle, $"Found unintended build bundle : {exceptBundle}");
BuildLogger.Warning(warning);
}
string exception = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildResult, $"Unintended build, See the detailed warnings !"); // 3. 验证差异
throw new Exception(exception); List<string> exceptBundleList2 = planningContent.Except(unityBuildContent).ToList();
} if (exceptBundleList2.Count > 0)
{
foreach (var exceptBundle in exceptBundleList2)
{
string warning = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildBundle, $"Found unintended build bundle : {exceptBundle}");
BuildLogger.Warning(warning);
}
// 3. 验证Bundle string exception = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildResult, $"Unintended build, See the detailed warnings !");
List<string> exceptBundleList2 = mapBundles.Except(unityCreateBundles).ToList(); throw new Exception(exception);
if (exceptBundleList2.Count > 0) }
{
foreach (var exceptBundle in exceptBundleList2)
{
string warning = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildBundle, $"Found unintended build bundle : {exceptBundle}");
BuildLogger.Warning(warning);
}
string exception = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildResult, $"Unintended build, See the detailed warnings !"); BuildLogger.Log("Build results verify success!");
throw new Exception(exception); }
} }
BuildLogger.Log("Build results verify success!");
}
}
} }

View File

@@ -5,57 +5,51 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class BuiltinBuildParameters : BuildParameters public class BuiltinBuildParameters : BuildParameters
{ {
/// <summary> /// <summary>
/// 压缩选项 /// 压缩选项
/// </summary> /// </summary>
public ECompressOption CompressOption = ECompressOption.Uncompressed; public ECompressOption CompressOption = ECompressOption.Uncompressed;
/// <summary> /// <summary>
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率) /// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
/// </summary> /// </summary>
public bool DisableWriteTypeTree = false; public bool DisableWriteTypeTree = false;
/// <summary> /// <summary>
/// 忽略类型树变化 /// 忽略类型树变化
/// </summary> /// </summary>
public bool IgnoreTypeTreeChanges = true; public bool IgnoreTypeTreeChanges = true;
/// <summary> /// <summary>
/// 获取内置构建管线的构建选项 /// 获取内置构建管线的构建选项
/// </summary> /// </summary>
public BuildAssetBundleOptions GetBundleBuildOptions() public BuildAssetBundleOptions GetBundleBuildOptions()
{ {
// For the new build system, unity always need BuildAssetBundleOptions.CollectDependencies and BuildAssetBundleOptions.DeterministicAssetBundle // For the new build system, unity always need BuildAssetBundleOptions.CollectDependencies and BuildAssetBundleOptions.DeterministicAssetBundle
// 除非设置ForceRebuildAssetBundle标记否则会进行增量打包 // 除非设置ForceRebuildAssetBundle标记否则会进行增量打包
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None; BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it. opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
if (BuildMode == EBuildMode.DryRunBuild) if (CompressOption == ECompressOption.Uncompressed)
{ opt |= BuildAssetBundleOptions.UncompressedAssetBundle;
opt |= BuildAssetBundleOptions.DryRunBuild; else if (CompressOption == ECompressOption.LZ4)
return opt; opt |= BuildAssetBundleOptions.ChunkBasedCompression;
}
if (CompressOption == ECompressOption.Uncompressed) if (ClearBuildCacheFiles)
opt |= BuildAssetBundleOptions.UncompressedAssetBundle; opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
else if (CompressOption == ECompressOption.LZ4) if (DisableWriteTypeTree)
opt |= BuildAssetBundleOptions.ChunkBasedCompression; opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
if (IgnoreTypeTreeChanges)
opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check.
if (BuildMode == EBuildMode.ForceRebuild) opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
if (DisableWriteTypeTree)
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
if (IgnoreTypeTreeChanges)
opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check.
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name. return opt;
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension. }
}
return opt;
}
}
} }

View File

@@ -1,38 +1,43 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class BuiltinBuildPipeline : IBuildPipeline public class BuiltinBuildPipeline : IBuildPipeline
{ {
public BuildResult Run(BuildParameters buildParameters, bool enableLog) public BuildResult Run(BuildParameters buildParameters, bool enableLog)
{ {
AssetBundleBuilder builder = new AssetBundleBuilder(); if (buildParameters is BuiltinBuildParameters)
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog); {
} AssetBundleBuilder builder = new AssetBundleBuilder();
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
}
else
{
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
}
}
/// <summary> /// <summary>
/// 获取默认的构建流程 /// 获取默认的构建流程
/// </summary> /// </summary>
private List<IBuildTask> GetDefaultBuildPipeline() private List<IBuildTask> GetDefaultBuildPipeline()
{ {
List<IBuildTask> pipeline = new List<IBuildTask> List<IBuildTask> pipeline = new List<IBuildTask>
{ {
new TaskPrepare_BBP(), new TaskPrepare_BBP(),
new TaskGetBuildMap_BBP(), new TaskGetBuildMap_BBP(),
new TaskBuilding_BBP(), new TaskBuilding_BBP(),
new TaskVerifyBuildResult_BBP(), new TaskVerifyBuildResult_BBP(),
new TaskUpdateBundleInfo_BBP(), new TaskEncryption_BBP(),
new TaskCreateManifest_BBP(), new TaskUpdateBundleInfo_BBP(),
new TaskCreateReport_BBP(), new TaskCreateManifest_BBP(),
new TaskCreatePackage_BBP(), new TaskCreateReport_BBP(),
new TaskCopyBuildinFiles_BBP(), new TaskCreatePackage_BBP(),
}; new TaskCopyBuildinFiles_BBP(),
return pipeline; };
} return pipeline;
} }
}
} }

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: a82eeb6a47cd02c4cb38e851c8ed8784 guid: 12f78ad22f0513c44b6037469dbd6363
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 8a97534752300584a9b8c60c04c6a6a8 guid: 1138888cdba447345abb498b0c89affa
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View File

@@ -0,0 +1,18 @@

using System;
namespace YooAsset.Editor
{
public class TaskCreateManifest_ESBP : TaskCreateManifest, IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
CreateManifestFile(false, false, context);
}
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
{
return Array.Empty<string>();
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 7fbb7b27f54d3b0439a951348fd9d785 guid: 120e126cc10604c4f811c3b6377f7452
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -0,0 +1,15 @@

using System;
namespace YooAsset.Editor
{
public class TaskGetBuildMap_ESBP : TaskGetBuildMap, IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = CreateBuildMap(true, buildParametersContext.Parameters);
context.SetContextObject(buildMapContext);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: f01d5c82be95c8f4b93aeefc0454ae5c guid: 789c337b5b82f1c438a588982dfca346
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -0,0 +1,17 @@

using System;
namespace YooAsset.Editor
{
public class TaskPrepare_ESBP : IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters;
// 检测基础构建参数
buildParametersContext.CheckBuildParameters();
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: a72c4edf1a81c9942a9d43e9d2a77b53 guid: abbe56a7120e34349b10f20956ed51a7
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -0,0 +1,63 @@

using System.Text;
using System;
namespace YooAsset.Editor
{
public class TaskUpdateBundleInfo_ESBP : TaskUpdateBundleInfo, IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
UpdateBundleInfo(context);
}
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
{
return "00000000000000000000000000000000"; //32位
}
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
{
return 0;
}
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{
string filePath = bundleInfo.PackageSourceFilePath;
return GetFilePathTempHash(filePath);
}
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{
return "00000000"; //8位
}
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{
return GetBundleTempSize(bundleInfo);
}
private string GetFilePathTempHash(string filePath)
{
byte[] bytes = Encoding.UTF8.GetBytes(filePath);
return HashUtility.BytesMD5(bytes);
// 注意:在文件路径的哈希值冲突的情况下,可以使用下面的方法
//return $"{HashUtility.BytesMD5(bytes)}-{Guid.NewGuid():N}";
}
private long GetBundleTempSize(BuildBundleInfo bundleInfo)
{
long tempSize = 0;
var assetPaths = bundleInfo.GetAllMainAssetPaths();
foreach (var assetPath in assetPaths)
{
long size = FileUtility.GetFileSize(assetPath);
tempSize += size;
}
if (tempSize == 0)
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BundleTempSizeIsZero, $"Bundle temp size is zero, check bundle main asset list : {bundleInfo.BundleName}");
throw new Exception(message);
}
return tempSize;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 0b6f2523a865e454d8fa3f48a2852d5a guid: 990b41f647b80a34ab666a3b0c1ba3f6
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -0,0 +1,7 @@

namespace YooAsset.Editor
{
public class EditorSimulateBuildParameters : BuildParameters
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03ea37371e6dc644cb2e6eabf9e7e2ad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,37 @@

using System.Collections.Generic;
using System;
namespace YooAsset.Editor
{
public class EditorSimulateBuildPipeline : IBuildPipeline
{
public BuildResult Run(BuildParameters buildParameters, bool enableLog)
{
if (buildParameters is EditorSimulateBuildParameters)
{
AssetBundleBuilder builder = new AssetBundleBuilder();
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
}
else
{
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
}
}
/// <summary>
/// 获取默认的构建流程
/// </summary>
private List<IBuildTask> GetDefaultBuildPipeline()
{
List<IBuildTask> pipeline = new List<IBuildTask>
{
new TaskPrepare_ESBP(),
new TaskGetBuildMap_ESBP(),
new TaskUpdateBundleInfo_ESBP(),
new TaskCreateManifest_ESBP()
};
return pipeline;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9caf8e4846ad8b64eb04a4d5179942ff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -5,35 +5,29 @@ using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskBuilding_RFBP : IBuildTask public class TaskBuilding_RFBP : IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); CopyRawBundle(buildMapContext, buildParametersContext);
}
var buildMode = buildParameters.Parameters.BuildMode; /// <summary>
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) /// 拷贝原生文件
{ /// </summary>
CopyRawBundle(buildMapContext, buildParametersContext); private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext)
} {
} string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.Collection)
/// <summary> {
/// 拷贝原生文件 string dest = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
/// </summary> foreach (var buildAsset in bundleInfo.MainAssets)
private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext) {
{ EditorTools.CopyFile(buildAsset.AssetInfo.AssetPath, dest, true);
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); }
foreach (var bundleInfo in buildMapContext.Collection) }
{ }
string dest = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; }
foreach (var assetInfo in bundleInfo.MainAssets)
{
EditorTools.CopyFile(assetInfo.AssetPath, dest, true);
}
}
}
}
} }

View File

@@ -6,21 +6,17 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCopyBuildinFiles_RFBP : TaskCopyBuildinFiles, IBuildTask public class TaskCopyBuildinFiles_RFBP : TaskCopyBuildinFiles, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters; var buildParameters = buildParametersContext.Parameters;
var manifestContext = context.GetContextObject<ManifestContext>(); var manifestContext = context.GetContextObject<ManifestContext>();
if (buildParameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
if (buildParameters.BuildMode != EBuildMode.SimulateBuild) {
{ CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
if (buildParameters.BuildinFileCopyOption != EBuildinFileCopyOption.None) }
{ }
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest); }
}
}
}
}
} }

View File

@@ -5,16 +5,16 @@ using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCreateManifest_RFBP : TaskCreateManifest, IBuildTask public class TaskCreateManifest_RFBP : TaskCreateManifest, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
CreateManifestFile(context); CreateManifestFile(false, true, context);
} }
protected override string[] GetBundleDepends(BuildContext context, string bundleName) protected override string[] GetBundleDepends(BuildContext context, string bundleName)
{ {
return new string[] { }; return Array.Empty<string>();
} }
} }
} }

View File

@@ -3,36 +3,32 @@ using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCreatePackage_RFBP : IBuildTask public class TaskCreatePackage_RFBP : IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var buildMode = buildParameters.Parameters.BuildMode; CreatePackagePatch(buildParameters, buildMapContext);
if (buildMode != EBuildMode.SimulateBuild) }
{
CreatePackageCatalog(buildParameters, buildMapContext);
}
}
/// <summary> /// <summary>
/// 拷贝补丁文件到补丁包目录 /// 拷贝补丁文件到补丁包目录
/// </summary> /// </summary>
private void CreatePackageCatalog(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext) private void CreatePackagePatch(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
{ {
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory(); string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
BuildLogger.Log($"Start making patch package: {packageOutputDirectory}"); BuildLogger.Log($"Start making patch package: {packageOutputDirectory}");
// 拷贝所有补丁文件 // 拷贝所有补丁文件
int progressValue = 0; int progressValue = 0;
int fileTotalCount = buildMapContext.Collection.Count; int fileTotalCount = buildMapContext.Collection.Count;
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
EditorTools.CopyFile(bundleInfo.PackageSourceFilePath, bundleInfo.PackageDestFilePath, true); EditorTools.CopyFile(bundleInfo.PackageSourceFilePath, bundleInfo.PackageDestFilePath, true);
EditorTools.DisplayProgressBar("Copy patch file", ++progressValue, fileTotalCount); EditorTools.DisplayProgressBar("Copy patch file", ++progressValue, fileTotalCount);
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();
} }
} }
} }

View File

@@ -6,19 +6,14 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCreateReport_RFBP : TaskCreateReport, IBuildTask public class TaskCreateReport_RFBP : TaskCreateReport, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var manifestContext = context.GetContextObject<ManifestContext>(); var manifestContext = context.GetContextObject<ManifestContext>();
CreateReportFile(buildParameters, buildMapContext, manifestContext);
var buildMode = buildParameters.Parameters.BuildMode; }
if (buildMode != EBuildMode.SimulateBuild) }
{
CreateReportFile(buildParameters, buildMapContext, manifestContext);
}
}
}
} }

View File

@@ -0,0 +1,13 @@

namespace YooAsset.Editor
{
public class TaskEncryption_RFBP : TaskEncryption, IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
EncryptingBundleFiles(buildParameters, buildMapContext);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3e156139dcc25f4c9440ec3d6cb96d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,32 +7,32 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskGetBuildMap_RFBP : TaskGetBuildMap, IBuildTask public class TaskGetBuildMap_RFBP : TaskGetBuildMap, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = CreateBuildMap(buildParametersContext.Parameters); var buildMapContext = CreateBuildMap(true, buildParametersContext.Parameters);
context.SetContextObject(buildMapContext); context.SetContextObject(buildMapContext);
// 检测构建结果 // 检测构建结果
CheckBuildMapContent(buildMapContext); CheckBuildMapContent(buildMapContext);
} }
/// <summary> /// <summary>
/// 检测资源构建上下文 /// 检测资源构建上下文
/// </summary> /// </summary>
private void CheckBuildMapContent(BuildMapContext buildMapContext) private void CheckBuildMapContent(BuildMapContext buildMapContext)
{ {
// 注意:原生文件资源包只能包含一个原生文件 // 注意:原生文件资源包只能包含一个原生文件
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
if (bundleInfo.MainAssets.Count != 1) if (bundleInfo.MainAssets.Count != 1)
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.NotSupportMultipleRawAsset, $"The bundle does not support multiple raw asset : {bundleInfo.BundleName}"); string message = BuildLogger.GetErrorMessage(ErrorCode.NotSupportMultipleRawAsset, $"The bundle does not support multiple raw asset : {bundleInfo.BundleName}");
throw new Exception(message); throw new Exception(message);
} }
} }
} }
} }
} }

View File

@@ -6,27 +6,40 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskPrepare_RFBP : IBuildTask public class TaskPrepare_RFBP : IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters; var buildParameters = buildParametersContext.Parameters;
// 检测基础构建参数 // 检测基础构建参数
buildParametersContext.CheckBuildParameters(); buildParametersContext.CheckBuildParameters();
// 检测不被支持的构建模式 // 删除包裹目录
if (buildParameters.BuildMode == EBuildMode.DryRunBuild) if (buildParameters.ClearBuildCacheFiles)
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportBuildMode, $"{nameof(EBuildPipeline.RawFileBuildPipeline)} not support {nameof(EBuildMode.DryRunBuild)} build mode !"); string packageRootDirectory = buildParameters.GetPackageRootDirectory();
throw new Exception(message); if (EditorTools.DeleteDirectory(packageRootDirectory))
} {
if (buildParameters.BuildMode == EBuildMode.IncrementalBuild) BuildLogger.Log($"Delete package root directory: {packageRootDirectory}");
{ }
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportBuildMode, $"{nameof(EBuildPipeline.RawFileBuildPipeline)} not support {nameof(EBuildMode.IncrementalBuild)} build mode !"); }
throw new Exception(message);
} // 检测包裹输出目录是否存在
} string packageOutputDirectory = buildParameters.GetPackageOutputDirectory();
} if (Directory.Exists(packageOutputDirectory))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageOutputDirectoryExists, $"Package outout directory exists: {packageOutputDirectory}");
throw new Exception(message);
}
// 如果输出目录不存在
string pipelineOutputDirectory = buildParameters.GetPipelineOutputDirectory();
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
{
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
}
}
}
} }

View File

@@ -6,55 +6,36 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskUpdateBundleInfo_RFBP : TaskUpdateBundleInfo, IBuildTask public class TaskUpdateBundleInfo_RFBP : TaskUpdateBundleInfo, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
UpdateBundleInfo(context); UpdateBundleInfo(context);
} }
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context) protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); string filePath = bundleInfo.PackageSourceFilePath;
var parameters = buildParametersContext.Parameters; return HashUtility.FileMD5(filePath);
var buildMode = parameters.BuildMode; }
if (buildMode == EBuildMode.SimulateBuild) protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
{ {
return "00000000000000000000000000000000"; //32位 return 0;
} }
else protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
string filePath = bundleInfo.PackageSourceFilePath; string filePath = bundleInfo.PackageSourceFilePath;
return HashUtility.FileMD5(filePath); return HashUtility.FileMD5(filePath);
} }
} protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context) {
{ string filePath = bundleInfo.PackageSourceFilePath;
return 0; return HashUtility.FileCRC32(filePath);
} }
protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext) protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
{ {
var buildMode = buildParametersContext.Parameters.BuildMode; string filePath = bundleInfo.PackageSourceFilePath;
if (buildMode == EBuildMode.SimulateBuild) return FileUtility.GetFileSize(filePath);
return GetFilePathTempHash(filePath); }
else }
return HashUtility.FileMD5(filePath);
}
protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild)
return "00000000"; //8位
else
return HashUtility.FileCRC32(filePath);
}
protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild)
return 0;
else
return FileUtility.GetFileSize(filePath);
}
}
} }

View File

@@ -4,7 +4,7 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class RawFileBuildParameters : BuildParameters public class RawFileBuildParameters : BuildParameters
{ {
} }
} }

View File

@@ -7,31 +7,39 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class RawFileBuildPipeline : IBuildPipeline public class RawFileBuildPipeline : IBuildPipeline
{ {
public BuildResult Run(BuildParameters buildParameters, bool enableLog) public BuildResult Run(BuildParameters buildParameters, bool enableLog)
{ {
AssetBundleBuilder builder = new AssetBundleBuilder(); if (buildParameters is RawFileBuildParameters)
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog); {
} AssetBundleBuilder builder = new AssetBundleBuilder();
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
}
else
{
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
}
}
/// <summary> /// <summary>
/// 获取默认的构建流程 /// 获取默认的构建流程
/// </summary> /// </summary>
private List<IBuildTask> GetDefaultBuildPipeline() private List<IBuildTask> GetDefaultBuildPipeline()
{ {
List<IBuildTask> pipeline = new List<IBuildTask> List<IBuildTask> pipeline = new List<IBuildTask>
{ {
new TaskPrepare_RFBP(), new TaskPrepare_RFBP(),
new TaskGetBuildMap_RFBP(), new TaskGetBuildMap_RFBP(),
new TaskBuilding_RFBP(), new TaskBuilding_RFBP(),
new TaskUpdateBundleInfo_RFBP(), new TaskEncryption_RFBP(),
new TaskCreateManifest_RFBP(), new TaskUpdateBundleInfo_RFBP(),
new TaskCreateReport_RFBP(), new TaskCreateManifest_RFBP(),
new TaskCreatePackage_RFBP(), new TaskCreateReport_RFBP(),
new TaskCopyBuildinFiles_RFBP(), new TaskCreatePackage_RFBP(),
}; new TaskCopyBuildinFiles_RFBP(),
return pipeline; };
} return pipeline;
} }
}
} }

View File

@@ -8,51 +8,46 @@ using UnityEditor.Build.Pipeline.Tasks;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskBuilding_SBP : IBuildTask public class TaskBuilding_SBP : IBuildTask
{ {
public class BuildResultContext : IContextObject public class BuildResultContext : IContextObject
{ {
public IBundleBuildResults Results; public IBundleBuildResults Results;
} }
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters; var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
// 模拟构建模式下跳过引擎构建 // 构建内容
var buildMode = buildParametersContext.Parameters.BuildMode; var buildContent = new BundleBuildContent(buildMapContext.GetPipelineBuilds());
if (buildMode == EBuildMode.SimulateBuild)
return;
// 构建内容 // 开始构建
var buildContent = new BundleBuildContent(buildMapContext.GetPipelineBuilds()); IBundleBuildResults buildResults;
var buildParameters = scriptableBuildParameters.GetBundleBuildParameters();
var taskList = SBPBuildTasks.Create(buildMapContext.Command.ShadersBundleName, null);
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
if (exitCode < 0)
{
string message = BuildLogger.GetErrorMessage(ErrorCode.UnityEngineBuildFailed, $"UnityEngine build failed ! ReturnCode : {exitCode}");
throw new Exception(message);
}
// 开始构建 // 创建着色器信息
IBundleBuildResults buildResults; // 说明:解决因为着色器资源包导致验证失败。
var buildParameters = scriptableBuildParameters.GetBundleBuildParameters(); // 例如:当项目里没有着色器,如果有依赖内置着色器就会验证失败。
var taskList = SBPBuildTasks.Create(buildMapContext.Command.ShadersBundleName); string shadersBundleName = buildMapContext.Command.ShadersBundleName;
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList); if (buildResults.BundleInfos.ContainsKey(shadersBundleName))
if (exitCode < 0) {
{ buildMapContext.CreateShadersBundleInfo(shadersBundleName);
string message = BuildLogger.GetErrorMessage(ErrorCode.UnityEngineBuildFailed, $"UnityEngine build failed ! ReturnCode : {exitCode}"); }
throw new Exception(message);
}
// 创建着色器信息 BuildLogger.Log("UnityEngine build success!");
// 说明:解决因为着色器资源包导致验证失败。 BuildResultContext buildResultContext = new BuildResultContext();
// 例如:当项目里没有着色器,如果有依赖内置着色器就会验证失败。 buildResultContext.Results = buildResults;
string shadersBundleName = buildMapContext.Command.ShadersBundleName; context.SetContextObject(buildResultContext);
if (buildResults.BundleInfos.ContainsKey(shadersBundleName)) }
{ }
buildMapContext.CreateShadersBundleInfo(shadersBundleName);
}
BuildLogger.Log("UnityEngine build success!");
BuildResultContext buildResultContext = new BuildResultContext();
buildResultContext.Results = buildResults;
context.SetContextObject(buildResultContext);
}
}
} }

View File

@@ -6,21 +6,16 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCopyBuildinFiles_SBP : TaskCopyBuildinFiles, IBuildTask public class TaskCopyBuildinFiles_SBP : TaskCopyBuildinFiles, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var manifestContext = context.GetContextObject<ManifestContext>(); var manifestContext = context.GetContextObject<ManifestContext>();
var buildMode = buildParametersContext.Parameters.BuildMode; if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
{
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
{ }
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None) }
{ }
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
}
}
}
}
} }

View File

@@ -7,26 +7,26 @@ using UnityEditor.Build.Pipeline.Interfaces;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCreateManifest_SBP : TaskCreateManifest, IBuildTask public class TaskCreateManifest_SBP : TaskCreateManifest, IBuildTask
{ {
private TaskBuilding_SBP.BuildResultContext _buildResultContext = null; private TaskBuilding_SBP.BuildResultContext _buildResultContext = null;
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
CreateManifestFile(context); CreateManifestFile(true, true, context);
} }
protected override string[] GetBundleDepends(BuildContext context, string bundleName) protected override string[] GetBundleDepends(BuildContext context, string bundleName)
{ {
if (_buildResultContext == null) if (_buildResultContext == null)
_buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>(); _buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
if (_buildResultContext.Results.BundleInfos.ContainsKey(bundleName) == false) if (_buildResultContext.Results.BundleInfos.ContainsKey(bundleName) == false)
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleInBuildResult, $"Not found bundle in engine build result : {bundleName}"); string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleInBuildResult, $"Not found bundle in engine build result : {bundleName}");
throw new Exception(message); throw new Exception(message);
} }
return _buildResultContext.Results.BundleInfos[bundleName].Dependencies; return _buildResultContext.Results.BundleInfos[bundleName].Dependencies;
} }
} }
} }

View File

@@ -3,53 +3,49 @@ using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCreatePackage_SBP : IBuildTask public class TaskCreatePackage_SBP : IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var buildMode = buildParameters.Parameters.BuildMode; CreatePackagePatch(buildParameters, buildMapContext);
if (buildMode != EBuildMode.SimulateBuild) }
{
CreatePackageCatalog(buildParameters, buildMapContext);
}
}
/// <summary> /// <summary>
/// 拷贝补丁文件到补丁包目录 /// 拷贝补丁文件到补丁包目录
/// </summary> /// </summary>
private void CreatePackageCatalog(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext) private void CreatePackagePatch(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
{ {
var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters; var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory(); string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
BuildLogger.Log($"Start making patch package: {packageOutputDirectory}"); BuildLogger.Log($"Start making patch package: {packageOutputDirectory}");
// 拷贝构建日志 // 拷贝构建日志
{ {
string sourcePath = $"{pipelineOutputDirectory}/buildlogtep.json"; string sourcePath = $"{pipelineOutputDirectory}/buildlogtep.json";
string destPath = $"{packageOutputDirectory}/buildlogtep.json"; string destPath = $"{packageOutputDirectory}/buildlogtep.json";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝代码防裁剪配置 // 拷贝代码防裁剪配置
if (scriptableBuildParameters.WriteLinkXML) if (scriptableBuildParameters.WriteLinkXML)
{ {
string sourcePath = $"{pipelineOutputDirectory}/link.xml"; string sourcePath = $"{pipelineOutputDirectory}/link.xml";
string destPath = $"{packageOutputDirectory}/link.xml"; string destPath = $"{packageOutputDirectory}/link.xml";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝所有补丁文件 // 拷贝所有补丁文件
int progressValue = 0; int progressValue = 0;
int fileTotalCount = buildMapContext.Collection.Count; int fileTotalCount = buildMapContext.Collection.Count;
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
EditorTools.CopyFile(bundleInfo.PackageSourceFilePath, bundleInfo.PackageDestFilePath, true); EditorTools.CopyFile(bundleInfo.PackageSourceFilePath, bundleInfo.PackageDestFilePath, true);
EditorTools.DisplayProgressBar("Copy patch file", ++progressValue, fileTotalCount); EditorTools.DisplayProgressBar("Copy patch file", ++progressValue, fileTotalCount);
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();
} }
} }
} }

View File

@@ -6,19 +6,14 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskCreateReport_SBP : TaskCreateReport, IBuildTask public class TaskCreateReport_SBP : TaskCreateReport, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var manifestContext = context.GetContextObject<ManifestContext>(); var manifestContext = context.GetContextObject<ManifestContext>();
CreateReportFile(buildParameters, buildMapContext, manifestContext);
var buildMode = buildParameters.Parameters.BuildMode; }
if (buildMode != EBuildMode.SimulateBuild) }
{
CreateReportFile(buildParameters, buildMapContext, manifestContext);
}
}
}
} }

View File

@@ -1,23 +1,13 @@
using System; 
using System.Linq;
using System.IO;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskEncryption_SBP : TaskEncryption, IBuildTask public class TaskEncryption_SBP : TaskEncryption, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
EncryptingBundleFiles(buildParameters, buildMapContext);
var buildMode = buildParameters.Parameters.BuildMode; }
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) }
{
EncryptingBundleFiles(buildParameters, buildMapContext);
}
}
}
} }

View File

@@ -7,13 +7,13 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskGetBuildMap_SBP : TaskGetBuildMap, IBuildTask public class TaskGetBuildMap_SBP : TaskGetBuildMap, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = CreateBuildMap(buildParametersContext.Parameters); var buildMapContext = CreateBuildMap(false, buildParametersContext.Parameters);
context.SetContextObject(buildMapContext); context.SetContextObject(buildMapContext);
} }
} }
} }

View File

@@ -6,27 +6,50 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskPrepare_SBP : IBuildTask public class TaskPrepare_SBP : IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters; var buildParameters = buildParametersContext.Parameters;
// 检测基础构建参数 // 检测基础构建参数
buildParametersContext.CheckBuildParameters(); buildParametersContext.CheckBuildParameters();
// 检测不被支持的构建模式 // 检测是否有未保存场景
if (buildParameters.BuildMode == EBuildMode.DryRunBuild) if (EditorTools.HasDirtyScenes())
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportBuildMode, $"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.DryRunBuild)} build mode !"); string message = BuildLogger.GetErrorMessage(ErrorCode.FoundUnsavedScene, "Found unsaved scene !");
throw new Exception(message); throw new Exception(message);
} }
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
{ // 删除包裹目录
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportBuildMode, $"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.ForceRebuild)} build mode !"); if (buildParameters.ClearBuildCacheFiles)
throw new Exception(message); {
} // Deletes the build cache directory.
} UnityEditor.Build.Pipeline.Utilities.BuildCache.PurgeCache(false);
}
string packageRootDirectory = buildParameters.GetPackageRootDirectory();
if (EditorTools.DeleteDirectory(packageRootDirectory))
{
BuildLogger.Log($"Delete package root directory: {packageRootDirectory}");
}
}
// 检测包裹输出目录是否存在
string packageOutputDirectory = buildParameters.GetPackageOutputDirectory();
if (Directory.Exists(packageOutputDirectory))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageOutputDirectoryExists, $"Package outout directory exists: {packageOutputDirectory}");
throw new Exception(message);
}
// 如果输出目录不存在
string pipelineOutputDirectory = buildParameters.GetPipelineOutputDirectory();
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
{
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
}
}
}
} }

View File

@@ -6,83 +6,54 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskUpdateBundleInfo_SBP : TaskUpdateBundleInfo, IBuildTask public class TaskUpdateBundleInfo_SBP : TaskUpdateBundleInfo, IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
UpdateBundleInfo(context); UpdateBundleInfo(context);
} }
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context) protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); // 注意当资源包的依赖列表发生变化的时候ContentHash也会发生变化
var parameters = buildParametersContext.Parameters; var buildResult = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
var buildMode = parameters.BuildMode; if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value))
if (buildMode == EBuildMode.SimulateBuild) {
{ return value.Hash.ToString();
return "00000000000000000000000000000000"; //32位 }
} else
else {
{ string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleHash, $"Not found unity bundle hash : {bundleInfo.BundleName}");
// 注意当资源包的依赖列表发生变化的时候ContentHash也会发生变化 throw new Exception(message);
var buildResult = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>(); }
if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value)) }
{ protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
return value.Hash.ToString(); {
} var buildResult = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
else if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value))
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleHash, $"Not found unity bundle hash : {bundleInfo.BundleName}"); return value.Crc;
throw new Exception(message); }
} else
} {
} string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleCRC, $"Not found unity bundle crc : {bundleInfo.BundleName}");
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context) throw new Exception(message);
{ }
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); }
var parameters = buildParametersContext.Parameters; protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
var buildMode = parameters.BuildMode; {
if (buildMode == EBuildMode.SimulateBuild) string filePath = bundleInfo.PackageSourceFilePath;
{ return HashUtility.FileMD5(filePath);
return 0; }
} protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
else {
{ string filePath = bundleInfo.PackageSourceFilePath;
var buildResult = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>(); return HashUtility.FileCRC32(filePath);
if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value)) }
{ protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
return value.Crc; {
} string filePath = bundleInfo.PackageSourceFilePath;
else return FileUtility.GetFileSize(filePath);
{ }
string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleCRC, $"Not found unity bundle crc : {bundleInfo.BundleName}"); }
throw new Exception(message);
}
}
}
protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild)
return GetFilePathTempHash(filePath);
else
return HashUtility.FileMD5(filePath);
}
protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild)
return "00000000"; //8位
else
return HashUtility.FileCRC32(filePath);
}
protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext)
{
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild)
return 0;
else
return FileUtility.GetFileSize(filePath);
}
}
} }

View File

@@ -9,66 +9,61 @@ using UnityEditor.Build.Pipeline.Interfaces;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class TaskVerifyBuildResult_SBP : IBuildTask public class TaskVerifyBuildResult_SBP : IBuildTask
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters as ScriptableBuildParameters; var buildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
// 模拟构建模式下跳过验证 // 验证构建结果
if (buildParameters.BuildMode == EBuildMode.SimulateBuild) if (buildParameters.VerifyBuildingResult)
return; {
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
VerifyingBuildingResult(context, buildResultContext.Results);
}
}
// 验证构建结果 /// <summary>
if (buildParameters.VerifyBuildingResult) /// 验证构建结果
{ /// </summary>
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>(); private void VerifyingBuildingResult(BuildContext context, IBundleBuildResults buildResults)
VerifyingBuildingResult(context, buildResultContext.Results); {
} var buildMapContext = context.GetContextObject<BuildMapContext>();
} List<string> unityBuildContent = buildResults.BundleInfos.Keys.ToList();
/// <summary> // 1. 计划内容
/// 验证构建结果 List<string> planningContent = buildMapContext.Collection.Select(t => t.BundleName).ToList();
/// </summary>
private void VerifyingBuildingResult(BuildContext context, IBundleBuildResults buildResults)
{
var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
List<string> unityCreateBundles = buildResults.BundleInfos.Keys.ToList();
// 1. 过滤掉原生Bundle // 2. 验证差异
List<string> expectBundles = buildMapContext.Collection.Select(t => t.BundleName).ToList(); List<string> exceptBundleList1 = unityBuildContent.Except(planningContent).ToList();
if (exceptBundleList1.Count > 0)
{
foreach (var exceptBundle in exceptBundleList1)
{
string warning = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildBundle, $"Found unintended build bundle : {exceptBundle}");
BuildLogger.Warning(warning);
}
// 2. 验证Bundle string exception = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildResult, $"Unintended build, See the detailed warnings !");
List<string> exceptBundleList1 = unityCreateBundles.Except(expectBundles).ToList(); throw new Exception(exception);
if (exceptBundleList1.Count > 0) }
{
foreach (var exceptBundle in exceptBundleList1)
{
string warning = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildBundle, $"Found unintended build bundle : {exceptBundle}");
BuildLogger.Warning(warning);
}
string exception = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildResult, $"Unintended build, See the detailed warnings !"); // 3. 验证差异
throw new Exception(exception); List<string> exceptBundleList2 = planningContent.Except(unityBuildContent).ToList();
} if (exceptBundleList2.Count > 0)
{
foreach (var exceptBundle in exceptBundleList2)
{
string warning = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildBundle, $"Found unintended build bundle : {exceptBundle}");
BuildLogger.Warning(warning);
}
// 3. 验证Bundle string exception = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildResult, $"Unintended build, See the detailed warnings !");
List<string> exceptBundleList2 = expectBundles.Except(unityCreateBundles).ToList(); throw new Exception(exception);
if (exceptBundleList2.Count > 0) }
{
foreach (var exceptBundle in exceptBundleList2)
{
string warning = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildBundle, $"Found unintended build bundle : {exceptBundle}");
BuildLogger.Warning(warning);
}
string exception = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildResult, $"Unintended build, See the detailed warnings !"); BuildLogger.Log("Build results verify success!");
throw new Exception(exception); }
} }
BuildLogger.Log("Build results verify success!");
}
}
} }

View File

@@ -1,67 +0,0 @@
using System.Collections.Generic;
using UnityEditor.Build.Content;
using UnityEngine.U2D;
using UnityEditor.Build.Pipeline.Injector;
using UnityEditor.Build.Pipeline.Interfaces;
using UnityEngine;
namespace UnityEditor.Build.Pipeline.Tasks
{
/// <summary>
/// Ref https://zhuanlan.zhihu.com/p/586918159
/// </summary>
public class RemoveSpriteAtlasRedundancy : IBuildTask
{
public int Version => 1;
[InjectContext]
IBundleWriteData writeDataParam;
public ReturnCode Run()
{
#if UNITY_2020_3_OR_NEWER
BundleWriteData writeData = (BundleWriteData)writeDataParam;
// 图集引用的精灵图片集合
HashSet<GUID> spriteGuids = new HashSet<GUID>();
foreach (var pair in writeData.FileToObjects)
{
foreach (ObjectIdentifier objectIdentifier in pair.Value)
{
var assetPath = AssetDatabase.GUIDToAssetPath(objectIdentifier.guid);
var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (assetType == typeof(SpriteAtlas))
{
var spritePaths = AssetDatabase.GetDependencies(assetPath, false);
foreach (string spritePath in spritePaths)
{
GUID spriteGuild = AssetDatabase.GUIDFromAssetPath(spritePath);
spriteGuids.Add(spriteGuild);
}
}
}
}
// 移除图集引用的精力图片对象
foreach (var pair in writeData.FileToObjects)
{
List<ObjectIdentifier> objectIdentifiers = pair.Value;
for (int i = objectIdentifiers.Count - 1; i >= 0; i--)
{
ObjectIdentifier objectIdentifier = objectIdentifiers[i];
if (spriteGuids.Contains(objectIdentifier.guid))
{
if (objectIdentifier.localIdentifierInFile == 2800000)
{
// 删除图集散图的冗余纹理
objectIdentifiers.RemoveAt(i);
}
}
}
}
#endif
return ReturnCode.Success;
}
}
}

View File

@@ -7,47 +7,49 @@ using UnityEditor.Build.Pipeline.Interfaces;
namespace UnityEditor.Build.Pipeline.Tasks namespace UnityEditor.Build.Pipeline.Tasks
{ {
public static class SBPBuildTasks public static class SBPBuildTasks
{ {
public static IList<IBuildTask> Create(string builtInShaderBundleName) public static IList<IBuildTask> Create(string builtInShaderBundleName, string unityMonoScriptsBundleName)
{ {
var buildTasks = new List<IBuildTask>(); var buildTasks = new List<IBuildTask>();
// Setup
buildTasks.Add(new SwitchToBuildPlatform());
buildTasks.Add(new RebuildSpriteAtlasCache());
// Player Scripts // Setup
buildTasks.Add(new BuildPlayerScripts()); buildTasks.Add(new SwitchToBuildPlatform());
buildTasks.Add(new PostScriptsCallback()); buildTasks.Add(new RebuildSpriteAtlasCache());
// Dependency // Player Scripts
buildTasks.Add(new CalculateSceneDependencyData()); buildTasks.Add(new BuildPlayerScripts());
buildTasks.Add(new PostScriptsCallback());
// Dependency
buildTasks.Add(new CalculateSceneDependencyData());
#if UNITY_2019_3_OR_NEWER #if UNITY_2019_3_OR_NEWER
buildTasks.Add(new CalculateCustomDependencyData()); buildTasks.Add(new CalculateCustomDependencyData());
#endif #endif
buildTasks.Add(new CalculateAssetDependencyData()); buildTasks.Add(new CalculateAssetDependencyData());
buildTasks.Add(new StripUnusedSpriteSources()); buildTasks.Add(new StripUnusedSpriteSources());
buildTasks.Add(new CreateBuiltInShadersBundle(builtInShaderBundleName)); if (string.IsNullOrEmpty(builtInShaderBundleName) == false)
buildTasks.Add(new PostDependencyCallback()); buildTasks.Add(new CreateBuiltInShadersBundle(builtInShaderBundleName));
if (string.IsNullOrEmpty(unityMonoScriptsBundleName) == false)
buildTasks.Add(new CreateMonoScriptBundle(unityMonoScriptsBundleName));
buildTasks.Add(new PostDependencyCallback());
// Packing // Packing
buildTasks.Add(new GenerateBundlePacking()); buildTasks.Add(new GenerateBundlePacking());
buildTasks.Add(new RemoveSpriteAtlasRedundancy()); // Fix for SpriteAtlas Redundancy buildTasks.Add(new UpdateBundleObjectLayout());
buildTasks.Add(new UpdateBundleObjectLayout()); buildTasks.Add(new GenerateBundleCommands());
buildTasks.Add(new GenerateBundleCommands()); buildTasks.Add(new GenerateSubAssetPathMaps());
buildTasks.Add(new GenerateSubAssetPathMaps()); buildTasks.Add(new GenerateBundleMaps());
buildTasks.Add(new GenerateBundleMaps()); buildTasks.Add(new PostPackingCallback());
buildTasks.Add(new PostPackingCallback());
// Writing
// Writing buildTasks.Add(new WriteSerializedFiles());
buildTasks.Add(new WriteSerializedFiles()); buildTasks.Add(new ArchiveAndCompressBundles());
buildTasks.Add(new ArchiveAndCompressBundles()); buildTasks.Add(new AppendBundleHash());
buildTasks.Add(new AppendBundleHash()); buildTasks.Add(new GenerateLinkXml());
buildTasks.Add(new GenerateLinkXml()); buildTasks.Add(new PostWritingCallback());
buildTasks.Add(new PostWritingCallback());
return buildTasks;
return buildTasks; }
} }
}
} }

View File

@@ -7,67 +7,67 @@ using UnityEditor.Build.Pipeline.Interfaces;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class ScriptableBuildParameters : BuildParameters public class ScriptableBuildParameters : BuildParameters
{ {
/// <summary> /// <summary>
/// 压缩选项 /// 压缩选项
/// </summary> /// </summary>
public ECompressOption CompressOption = ECompressOption.Uncompressed; public ECompressOption CompressOption = ECompressOption.Uncompressed;
/// <summary> /// <summary>
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率) /// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
/// </summary> /// </summary>
public bool DisableWriteTypeTree = false; public bool DisableWriteTypeTree = false;
/// <summary> /// <summary>
/// 忽略类型树变化 /// 忽略类型树变化
/// </summary> /// </summary>
public bool IgnoreTypeTreeChanges = true; public bool IgnoreTypeTreeChanges = true;
/// <summary> /// <summary>
/// 生成代码防裁剪配置 /// 生成代码防裁剪配置
/// </summary> /// </summary>
public bool WriteLinkXML = true; public bool WriteLinkXML = true;
/// <summary> /// <summary>
/// 缓存服务器地址 /// 缓存服务器地址
/// </summary> /// </summary>
public string CacheServerHost; public string CacheServerHost;
/// <summary> /// <summary>
/// 缓存服务器端口 /// 缓存服务器端口
/// </summary> /// </summary>
public int CacheServerPort; public int CacheServerPort;
/// <summary> /// <summary>
/// 获取可编程构建管线的构建参数 /// 获取可编程构建管线的构建参数
/// </summary> /// </summary>
public BundleBuildParameters GetBundleBuildParameters() public BundleBuildParameters GetBundleBuildParameters()
{ {
var targetGroup = UnityEditor.BuildPipeline.GetBuildTargetGroup(BuildTarget); var targetGroup = UnityEditor.BuildPipeline.GetBuildTargetGroup(BuildTarget);
var pipelineOutputDirectory = GetPipelineOutputDirectory(); var pipelineOutputDirectory = GetPipelineOutputDirectory();
var buildParams = new BundleBuildParameters(BuildTarget, targetGroup, pipelineOutputDirectory); var buildParams = new BundleBuildParameters(BuildTarget, targetGroup, pipelineOutputDirectory);
if (CompressOption == ECompressOption.Uncompressed) if (CompressOption == ECompressOption.Uncompressed)
buildParams.BundleCompression = UnityEngine.BuildCompression.Uncompressed; buildParams.BundleCompression = UnityEngine.BuildCompression.Uncompressed;
else if (CompressOption == ECompressOption.LZMA) else if (CompressOption == ECompressOption.LZMA)
buildParams.BundleCompression = UnityEngine.BuildCompression.LZMA; buildParams.BundleCompression = UnityEngine.BuildCompression.LZMA;
else if (CompressOption == ECompressOption.LZ4) else if (CompressOption == ECompressOption.LZ4)
buildParams.BundleCompression = UnityEngine.BuildCompression.LZ4; buildParams.BundleCompression = UnityEngine.BuildCompression.LZ4;
else else
throw new System.NotImplementedException(CompressOption.ToString()); throw new System.NotImplementedException(CompressOption.ToString());
if (DisableWriteTypeTree) if (DisableWriteTypeTree)
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree; buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree;
buildParams.UseCache = true; buildParams.UseCache = true;
buildParams.CacheServerHost = CacheServerHost; buildParams.CacheServerHost = CacheServerHost;
buildParams.CacheServerPort = CacheServerPort; buildParams.CacheServerPort = CacheServerPort;
buildParams.WriteLinkXML = WriteLinkXML; buildParams.WriteLinkXML = WriteLinkXML;
return buildParams; return buildParams;
} }
} }
} }

View File

@@ -1,38 +1,43 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class ScriptableBuildPipeline : IBuildPipeline public class ScriptableBuildPipeline : IBuildPipeline
{ {
public BuildResult Run(BuildParameters buildParameters, bool enableLog) public BuildResult Run(BuildParameters buildParameters, bool enableLog)
{ {
AssetBundleBuilder builder = new AssetBundleBuilder(); if (buildParameters is ScriptableBuildParameters)
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog); {
} AssetBundleBuilder builder = new AssetBundleBuilder();
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
}
else
{
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
}
}
/// <summary> /// <summary>
/// 获取默认的构建流程 /// 获取默认的构建流程
/// </summary> /// </summary>
private List<IBuildTask> GetDefaultBuildPipeline() private List<IBuildTask> GetDefaultBuildPipeline()
{ {
List<IBuildTask> pipeline = new List<IBuildTask> List<IBuildTask> pipeline = new List<IBuildTask>
{ {
new TaskPrepare_SBP(), new TaskPrepare_SBP(),
new TaskGetBuildMap_SBP(), new TaskGetBuildMap_SBP(),
new TaskBuilding_SBP(), new TaskBuilding_SBP(),
new TaskVerifyBuildResult_SBP(), new TaskVerifyBuildResult_SBP(),
new TaskUpdateBundleInfo_SBP(), new TaskEncryption_SBP(),
new TaskCreateManifest_SBP(), new TaskUpdateBundleInfo_SBP(),
new TaskCreateReport_SBP(), new TaskCreateManifest_SBP(),
new TaskCreatePackage_SBP(), new TaskCreateReport_SBP(),
new TaskCopyBuildinFiles_SBP(), new TaskCreatePackage_SBP(),
}; new TaskCopyBuildinFiles_SBP(),
return pipeline; };
} return pipeline;
} }
}
} }

View File

@@ -4,47 +4,47 @@ using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class BuildContext public class BuildContext
{ {
private readonly Dictionary<System.Type, IContextObject> _contextObjects = new Dictionary<System.Type, IContextObject>(); private readonly Dictionary<System.Type, IContextObject> _contextObjects = new Dictionary<System.Type, IContextObject>();
/// <summary> /// <summary>
/// 清空所有情景对象 /// 清空所有情景对象
/// </summary> /// </summary>
public void ClearAllContext() public void ClearAllContext()
{ {
_contextObjects.Clear(); _contextObjects.Clear();
} }
/// <summary> /// <summary>
/// 设置情景对象 /// 设置情景对象
/// </summary> /// </summary>
public void SetContextObject(IContextObject contextObject) public void SetContextObject(IContextObject contextObject)
{ {
if (contextObject == null) if (contextObject == null)
throw new ArgumentNullException("contextObject"); throw new ArgumentNullException("contextObject");
var type = contextObject.GetType(); var type = contextObject.GetType();
if (_contextObjects.ContainsKey(type)) if (_contextObjects.ContainsKey(type))
throw new Exception($"Context object {type} is already existed."); throw new Exception($"Context object {type} is already existed.");
_contextObjects.Add(type, contextObject); _contextObjects.Add(type, contextObject);
} }
/// <summary> /// <summary>
/// 获取情景对象 /// 获取情景对象
/// </summary> /// </summary>
public T GetContextObject<T>() where T : IContextObject public T GetContextObject<T>() where T : IContextObject
{ {
var type = typeof(T); var type = typeof(T);
if (_contextObjects.TryGetValue(type, out IContextObject contextObject)) if (_contextObjects.TryGetValue(type, out IContextObject contextObject))
{ {
return (T)contextObject; return (T)contextObject;
} }
else else
{ {
throw new Exception($"Not found context object : {type}"); throw new Exception($"Not found context object : {type}");
} }
} }
} }
} }

View File

@@ -5,34 +5,34 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal static class BuildLogger internal static class BuildLogger
{ {
private static bool _enableLog = true; private static bool _enableLog = true;
public static void InitLogger(bool enableLog) public static void InitLogger(bool enableLog)
{ {
_enableLog = enableLog; _enableLog = enableLog;
} }
public static void Log(string message) public static void Log(string message)
{ {
if (_enableLog) if (_enableLog)
{ {
Debug.Log(message); Debug.Log(message);
} }
} }
public static void Warning(string message) public static void Warning(string message)
{ {
Debug.LogWarning(message); Debug.LogWarning(message);
} }
public static void Error(string message) public static void Error(string message)
{ {
Debug.LogError(message); Debug.LogError(message);
} }
public static string GetErrorMessage(ErrorCode code, string message) public static string GetErrorMessage(ErrorCode code, string message)
{ {
return $"[ErrorCode{(int)code}] {message}"; return $"[ErrorCode{(int)code}] {message}";
} }
} }
} }

View File

@@ -7,64 +7,64 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class BuildRunner public class BuildRunner
{ {
private static Stopwatch _buildWatch; private static Stopwatch _buildWatch;
/// <summary> /// <summary>
/// 总耗时 /// 总耗时
/// </summary> /// </summary>
public static int TotalSeconds = 0; public static int TotalSeconds = 0;
/// <summary> /// <summary>
/// 执行构建流程 /// 执行构建流程
/// </summary> /// </summary>
/// <returns>如果成功返回TRUE否则返回FALSE</returns> /// <returns>如果成功返回TRUE否则返回FALSE</returns>
public static BuildResult Run(List<IBuildTask> pipeline, BuildContext context) public static BuildResult Run(List<IBuildTask> pipeline, BuildContext context)
{ {
if (pipeline == null) if (pipeline == null)
throw new ArgumentNullException("pipeline"); throw new ArgumentNullException("pipeline");
if (context == null) if (context == null)
throw new ArgumentNullException("context"); throw new ArgumentNullException("context");
BuildResult buildResult = new BuildResult(); BuildResult buildResult = new BuildResult();
buildResult.Success = true; buildResult.Success = true;
TotalSeconds = 0; TotalSeconds = 0;
for (int i = 0; i < pipeline.Count; i++) for (int i = 0; i < pipeline.Count; i++)
{ {
IBuildTask task = pipeline[i]; IBuildTask task = pipeline[i];
try try
{ {
_buildWatch = Stopwatch.StartNew(); _buildWatch = Stopwatch.StartNew();
string taskName = task.GetType().Name.Split('_')[0]; string taskName = task.GetType().Name.Split('_')[0];
BuildLogger.Log($"--------------------------------------------->{taskName}<--------------------------------------------"); BuildLogger.Log($"--------------------------------------------->{taskName}<--------------------------------------------");
task.Run(context); task.Run(context);
_buildWatch.Stop(); _buildWatch.Stop();
// 统计耗时 // 统计耗时
int seconds = GetBuildSeconds(); int seconds = GetBuildSeconds();
TotalSeconds += seconds; TotalSeconds += seconds;
BuildLogger.Log($"{taskName} It takes {seconds} seconds in total"); BuildLogger.Log($"{taskName} It takes {seconds} seconds in total");
} }
catch (Exception e) catch (Exception e)
{ {
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();
buildResult.FailedTask = task.GetType().Name; buildResult.FailedTask = task.GetType().Name;
buildResult.ErrorInfo = e.ToString(); buildResult.ErrorInfo = e.ToString();
buildResult.Success = false; buildResult.Success = false;
break; break;
} }
} }
// 返回运行结果 // 返回运行结果
BuildLogger.Log($"Total build process time: {TotalSeconds} seconds"); BuildLogger.Log($"Total build process time: {TotalSeconds} seconds");
return buildResult; return buildResult;
} }
private static int GetBuildSeconds() private static int GetBuildSeconds()
{ {
float seconds = _buildWatch.ElapsedMilliseconds / 1000f; float seconds = _buildWatch.ElapsedMilliseconds / 1000f;
return (int)seconds; return (int)seconds;
} }
} }
} }

View File

@@ -1,41 +1,42 @@
 
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal enum ErrorCode internal enum ErrorCode
{ {
// TaskPrepare // TaskPrepare
ThePipelineIsBuiding = 100, ThePipelineIsBuiding = 100,
FoundUnsavedScene = 101, FoundUnsavedScene = 101,
NoBuildTarget = 110, NoBuildTarget = 110,
PackageNameIsNullOrEmpty = 111, PackageNameIsNullOrEmpty = 111,
PackageVersionIsNullOrEmpty = 112, PackageVersionIsNullOrEmpty = 112,
BuildOutputRootIsNullOrEmpty = 113, BuildOutputRootIsNullOrEmpty = 113,
BuildinFileRootIsNullOrEmpty = 114, BuildinFileRootIsNullOrEmpty = 114,
PackageOutputDirectoryExists = 115, PackageOutputDirectoryExists = 115,
RecommendScriptBuildPipeline = 130, RecommendScriptBuildPipeline = 130,
BuildPipelineNotSupportBuildMode = 140,
// TaskGetBuildMap // TaskGetBuildMap
RemoveInvalidTags = 200, RemoveInvalidTags = 200,
FoundUndependedAsset = 201, FoundUndependedAsset = 201,
PackAssetListIsEmpty = 202, PackAssetListIsEmpty = 202,
NotSupportMultipleRawAsset = 210, NotSupportMultipleRawAsset = 210,
// TaskBuilding // TaskBuilding
UnityEngineBuildFailed = 300, UnityEngineBuildFailed = 300,
UnityEngineBuildFatal = 301, UnityEngineBuildFatal = 301,
// TaskUpdateBundleInfo // TaskUpdateBundleInfo
CharactersOverTheLimit = 400, CharactersOverTheLimit = 400,
NotFoundUnityBundleHash = 401, NotFoundUnityBundleHash = 401,
NotFoundUnityBundleCRC = 402, NotFoundUnityBundleCRC = 402,
BundleTempSizeIsZero = 403,
// TaskVerifyBuildResult // TaskVerifyBuildResult
UnintendedBuildBundle = 500, UnintendedBuildBundle = 500,
UnintendedBuildResult = 501, UnintendedBuildResult = 501,
// TaskCreateManifest // TaskCreateManifest
NotFoundUnityBundleInBuildResult = 600, NotFoundUnityBundleInBuildResult = 600,
FoundStrayBundle = 601, FoundStrayBundle = 601,
} BundleHashConflict = 602,
}
} }

View File

@@ -1,7 +1,7 @@
 
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public interface IContextObject public interface IContextObject
{ {
} }
} }

View File

@@ -1,11 +1,11 @@
 
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class EncryptionNone : IEncryptionServices public class EncryptionNone : IEncryptionServices
{ {
public EncryptResult Encrypt(EncryptFileInfo fileInfo) public EncryptResult Encrypt(EncryptFileInfo fileInfo)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
} }
} }

View File

@@ -1,29 +0,0 @@

namespace YooAsset.Editor
{
/// <summary>
/// 资源包流水线的构建模式
/// </summary>
public enum EBuildMode
{
/// <summary>
/// 强制重建模式
/// </summary>
ForceRebuild,
/// <summary>
/// 增量构建模式
/// </summary>
IncrementalBuild,
/// <summary>
/// 演练构建模式
/// </summary>
DryRunBuild,
/// <summary>
/// 模拟构建模式
/// </summary>
SimulateBuild,
}
}

View File

@@ -1,24 +1,29 @@
 
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
/// <summary> /// <summary>
/// 构建管线类型 /// 构建管线类型
/// </summary> /// </summary>
public enum EBuildPipeline public enum EBuildPipeline
{ {
/// <summary> /// <summary>
/// 传统内置构建管线 (BBP) /// 编辑器下的模拟构建管线ESBP
/// </summary> /// </summary>
BuiltinBuildPipeline, EditorSimulateBuildPipeline,
/// <summary>
/// 可编程构建管线 (SBP)
/// </summary>
ScriptableBuildPipeline,
/// <summary> /// <summary>
/// 原生文件构建管线 (RFBP) /// 传统内置构建管线 (BBP)
/// </summary> /// </summary>
RawFileBuildPipeline, BuiltinBuildPipeline,
}
/// <summary>
/// 可编程构建管线 (SBP)
/// </summary>
ScriptableBuildPipeline,
/// <summary>
/// 原生文件构建管线 (RFBP)
/// </summary>
RawFileBuildPipeline,
}
} }

View File

@@ -1,34 +1,34 @@
 
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
/// <summary> /// <summary>
/// 首包资源文件的拷贝方式 /// 首包资源文件的拷贝方式
/// </summary> /// </summary>
public enum EBuildinFileCopyOption public enum EBuildinFileCopyOption
{ {
/// <summary> /// <summary>
/// 不拷贝任何文件 /// 不拷贝任何文件
/// </summary> /// </summary>
None = 0, None = 0,
/// <summary> /// <summary>
/// 先清空已有文件,然后拷贝所有文件 /// 先清空已有文件,然后拷贝所有文件
/// </summary> /// </summary>
ClearAndCopyAll, ClearAndCopyAll,
/// <summary> /// <summary>
/// 先清空已有文件,然后按照资源标签拷贝文件 /// 先清空已有文件,然后按照资源标签拷贝文件
/// </summary> /// </summary>
ClearAndCopyByTags, ClearAndCopyByTags,
/// <summary> /// <summary>
/// 不清空已有文件,直接拷贝所有文件 /// 不清空已有文件,直接拷贝所有文件
/// </summary> /// </summary>
OnlyCopyAll, OnlyCopyAll,
/// <summary> /// <summary>
/// 不清空已有文件,直接按照资源标签拷贝文件 /// 不清空已有文件,直接按照资源标签拷贝文件
/// </summary> /// </summary>
OnlyCopyByTags, OnlyCopyByTags,
} }
} }

View File

@@ -1,13 +1,13 @@
 
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
/// <summary> /// <summary>
/// AssetBundle压缩选项 /// AssetBundle压缩选项
/// </summary> /// </summary>
public enum ECompressOption public enum ECompressOption
{ {
Uncompressed = 0, Uncompressed = 0,
LZMA, LZMA,
LZ4, LZ4,
} }
} }

View File

@@ -1,24 +1,24 @@
 
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
/// <summary> /// <summary>
/// 补丁包内的文件样式 /// 补丁包内的文件样式
/// </summary> /// </summary>
public enum EFileNameStyle public enum EFileNameStyle
{ {
/// <summary> /// <summary>
/// 哈希值名称 /// 哈希值名称
/// </summary> /// </summary>
HashName = 0, HashName = 0,
/// <summary> /// <summary>
/// 资源包名称(不推荐) /// 资源包名称(不推荐)
/// </summary> /// </summary>
BundleName = 1, BundleName = 1,
/// <summary> /// <summary>
/// 资源包名称 + 哈希值名称 /// 资源包名称 + 哈希值名称
/// </summary> /// </summary>
BundleName_HashName = 2, BundleName_HashName = 2,
} }
} }

View File

@@ -1,8 +1,8 @@
 
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public interface IBuildPipeline public interface IBuildPipeline
{ {
public BuildResult Run(BuildParameters buildParameters, bool enableLog); BuildResult Run(BuildParameters buildParameters, bool enableLog);
} }
} }

View File

@@ -10,201 +10,213 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal abstract class BuildPipelineViewerBase internal abstract class BuildPipelineViewerBase
{ {
private const int StyleWidth = 400; private const int StyleWidth = 400;
private const int LabelMinWidth = 180;
protected readonly string PackageName; protected readonly string PackageName;
protected readonly BuildTarget BuildTarget; protected readonly BuildTarget BuildTarget;
protected readonly EBuildPipeline BuildPipeline; protected readonly EBuildPipeline BuildPipeline;
protected TemplateContainer Root; protected TemplateContainer Root;
private TextField _buildOutputField; private TextField _buildOutputField;
private TextField _buildVersionField; private TextField _buildVersionField;
private PopupField<Enum> _buildModeField; private PopupField<Enum> _buildModeField;
private PopupField<Type> _encryptionField; private PopupField<Type> _encryptionField;
private EnumField _compressionField; private EnumField _compressionField;
private EnumField _outputNameStyleField; private EnumField _outputNameStyleField;
private EnumField _copyBuildinFileOptionField; private EnumField _copyBuildinFileOptionField;
private TextField _copyBuildinFileTagsField; private TextField _copyBuildinFileTagsField;
private Toggle _clearBuildCacheToggle;
private Toggle _useAssetDependencyDBToggle;
public BuildPipelineViewerBase(string packageName, EBuildPipeline buildPipeline, BuildTarget buildTarget, VisualElement parent) public BuildPipelineViewerBase(string packageName, EBuildPipeline buildPipeline, BuildTarget buildTarget, VisualElement parent)
{ {
PackageName = packageName; PackageName = packageName;
BuildTarget = buildTarget; BuildTarget = buildTarget;
BuildPipeline = buildPipeline; BuildPipeline = buildPipeline;
CreateView(parent); CreateView(parent);
RefreshView(); RefreshView();
} }
private void CreateView(VisualElement parent) private void CreateView(VisualElement parent)
{ {
// 加载布局文件 // 加载布局文件
var visualAsset = UxmlLoader.LoadWindowUXML<BuildPipelineViewerBase>(); var visualAsset = UxmlLoader.LoadWindowUXML<BuildPipelineViewerBase>();
if (visualAsset == null) if (visualAsset == null)
return; return;
Root = visualAsset.CloneTree(); Root = visualAsset.CloneTree();
Root.style.flexGrow = 1f; Root.style.flexGrow = 1f;
parent.Add(Root); parent.Add(Root);
// 输出目录 // 输出目录
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
_buildOutputField = Root.Q<TextField>("BuildOutput"); _buildOutputField = Root.Q<TextField>("BuildOutput");
_buildOutputField.SetValueWithoutNotify(defaultOutputRoot); _buildOutputField.SetValueWithoutNotify(defaultOutputRoot);
_buildOutputField.SetEnabled(false); _buildOutputField.SetEnabled(false);
// 构建版本 // 构建版本
_buildVersionField = Root.Q<TextField>("BuildVersion"); _buildVersionField = Root.Q<TextField>("BuildVersion");
_buildVersionField.style.width = StyleWidth; _buildVersionField.style.width = StyleWidth;
_buildVersionField.SetValueWithoutNotify(GetDefaultPackageVersion()); _buildVersionField.SetValueWithoutNotify(GetDefaultPackageVersion());
// 构建模式 // 加密方法
{ {
var buildModeContainer = Root.Q("BuildModeContainer"); var encryptionContainer = Root.Q("EncryptionContainer");
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline); var encryptionClassTypes = EditorTools.GetAssignableTypes(typeof(IEncryptionServices));
var buildModeList = GetSupportBuildModes(); if (encryptionClassTypes.Count > 0)
int defaultIndex = buildModeList.FindIndex(x => x.Equals(buildMode)); {
_buildModeField = new PopupField<Enum>(buildModeList, defaultIndex); var encyptionClassName = AssetBundleBuilderSetting.GetPackageEncyptionClassName(PackageName, BuildPipeline);
_buildModeField.label = "Build Mode"; int defaultIndex = encryptionClassTypes.FindIndex(x => x.FullName.Equals(encyptionClassName));
_buildModeField.style.width = StyleWidth; if (defaultIndex < 0)
_buildModeField.RegisterValueChangedCallback(evt => defaultIndex = 0;
{ _encryptionField = new PopupField<Type>(encryptionClassTypes, defaultIndex);
AssetBundleBuilderSetting.SetPackageBuildMode(PackageName, BuildPipeline, (EBuildMode)_buildModeField.value); _encryptionField.label = "Encryption";
}); _encryptionField.style.width = StyleWidth;
buildModeContainer.Add(_buildModeField); _encryptionField.RegisterValueChangedCallback(evt =>
} {
AssetBundleBuilderSetting.SetPackageEncyptionClassName(PackageName, BuildPipeline, _encryptionField.value.FullName);
});
encryptionContainer.Add(_encryptionField);
}
else
{
_encryptionField = new PopupField<Type>();
_encryptionField.label = "Encryption";
_encryptionField.style.width = StyleWidth;
encryptionContainer.Add(_encryptionField);
}
}
// 加密方法 // 压缩方式选项
{ var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline);
var encryptionContainer = Root.Q("EncryptionContainer"); _compressionField = Root.Q<EnumField>("Compression");
var encryptionClassTypes = EditorTools.GetAssignableTypes(typeof(IEncryptionServices)); _compressionField.Init(compressOption);
if (encryptionClassTypes.Count > 0) _compressionField.SetValueWithoutNotify(compressOption);
{ _compressionField.style.width = StyleWidth;
var encyptionClassName = AssetBundleBuilderSetting.GetPackageEncyptionClassName(PackageName, BuildPipeline); _compressionField.RegisterValueChangedCallback(evt =>
int defaultIndex = encryptionClassTypes.FindIndex(x => x.FullName.Equals(encyptionClassName)); {
_encryptionField = new PopupField<Type>(encryptionClassTypes, defaultIndex); AssetBundleBuilderSetting.SetPackageCompressOption(PackageName, BuildPipeline, (ECompressOption)_compressionField.value);
_encryptionField.label = "Encryption"; });
_encryptionField.style.width = StyleWidth;
_encryptionField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSetting.SetPackageEncyptionClassName(PackageName, BuildPipeline, _encryptionField.value.FullName);
});
encryptionContainer.Add(_encryptionField);
}
else
{
_encryptionField = new PopupField<Type>();
_encryptionField.label = "Encryption";
_encryptionField.style.width = StyleWidth;
encryptionContainer.Add(_encryptionField);
}
}
// 压缩方式选项 // 输出文件名称样式
var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline); var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline);
_compressionField = Root.Q<EnumField>("Compression"); _outputNameStyleField = Root.Q<EnumField>("FileNameStyle");
_compressionField.Init(compressOption); _outputNameStyleField.Init(fileNameStyle);
_compressionField.SetValueWithoutNotify(compressOption); _outputNameStyleField.SetValueWithoutNotify(fileNameStyle);
_compressionField.style.width = StyleWidth; _outputNameStyleField.style.width = StyleWidth;
_compressionField.RegisterValueChangedCallback(evt => _outputNameStyleField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSetting.SetPackageCompressOption(PackageName, BuildPipeline, (ECompressOption)_compressionField.value); AssetBundleBuilderSetting.SetPackageFileNameStyle(PackageName, BuildPipeline, (EFileNameStyle)_outputNameStyleField.value);
}); });
// 输出文件名称样式 // 首包文件拷贝选项
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline); var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline);
_outputNameStyleField = Root.Q<EnumField>("FileNameStyle"); _copyBuildinFileOptionField = Root.Q<EnumField>("CopyBuildinFileOption");
_outputNameStyleField.Init(fileNameStyle); _copyBuildinFileOptionField.Init(buildinFileCopyOption);
_outputNameStyleField.SetValueWithoutNotify(fileNameStyle); _copyBuildinFileOptionField.SetValueWithoutNotify(buildinFileCopyOption);
_outputNameStyleField.style.width = StyleWidth; _copyBuildinFileOptionField.style.width = StyleWidth;
_outputNameStyleField.RegisterValueChangedCallback(evt => _copyBuildinFileOptionField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSetting.SetPackageFileNameStyle(PackageName, BuildPipeline, (EFileNameStyle)_outputNameStyleField.value); AssetBundleBuilderSetting.SetPackageBuildinFileCopyOption(PackageName, BuildPipeline, (EBuildinFileCopyOption)_copyBuildinFileOptionField.value);
}); RefreshView();
});
// 首包文件拷贝选项 // 首包文件拷贝参数
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline); var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline);
_copyBuildinFileOptionField = Root.Q<EnumField>("CopyBuildinFileOption"); _copyBuildinFileTagsField = Root.Q<TextField>("CopyBuildinFileParam");
_copyBuildinFileOptionField.Init(buildinFileCopyOption); _copyBuildinFileTagsField.SetValueWithoutNotify(buildinFileCopyParams);
_copyBuildinFileOptionField.SetValueWithoutNotify(buildinFileCopyOption); _copyBuildinFileTagsField.RegisterValueChangedCallback(evt =>
_copyBuildinFileOptionField.style.width = StyleWidth; {
_copyBuildinFileOptionField.RegisterValueChangedCallback(evt => AssetBundleBuilderSetting.SetPackageBuildinFileCopyParams(PackageName, BuildPipeline, _copyBuildinFileTagsField.value);
{ });
AssetBundleBuilderSetting.SetPackageBuildinFileCopyOption(PackageName, BuildPipeline, (EBuildinFileCopyOption)_copyBuildinFileOptionField.value);
RefreshView();
});
// 首包文件拷贝参数 // 清理构建缓存
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline); bool clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline);
_copyBuildinFileTagsField = Root.Q<TextField>("CopyBuildinFileParam"); _clearBuildCacheToggle = Root.Q<Toggle>("ClearBuildCache");
_copyBuildinFileTagsField.SetValueWithoutNotify(buildinFileCopyParams); _clearBuildCacheToggle.SetValueWithoutNotify(clearBuildCache);
_copyBuildinFileTagsField.RegisterValueChangedCallback(evt => _clearBuildCacheToggle.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSetting.SetPackageBuildinFileCopyParams(PackageName, BuildPipeline, _copyBuildinFileTagsField.value); AssetBundleBuilderSetting.SetPackageClearBuildCache(PackageName, BuildPipeline, _clearBuildCacheToggle.value);
}); });
// 构建按钮 // 使用资源依赖数据库
var buildButton = Root.Q<Button>("Build"); bool useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline);
buildButton.clicked += BuildButton_clicked; _useAssetDependencyDBToggle = Root.Q<Toggle>("UseAssetDependency");
} _useAssetDependencyDBToggle.SetValueWithoutNotify(useAssetDependencyDB);
private void RefreshView() _useAssetDependencyDBToggle.RegisterValueChangedCallback(evt =>
{ {
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline); AssetBundleBuilderSetting.SetPackageUseAssetDependencyDB(PackageName, BuildPipeline, _useAssetDependencyDBToggle.value);
bool tagsFiledVisible = buildinFileCopyOption == EBuildinFileCopyOption.ClearAndCopyByTags || buildinFileCopyOption == EBuildinFileCopyOption.OnlyCopyByTags; });
_copyBuildinFileTagsField.visible = tagsFiledVisible;
}
private void BuildButton_clicked()
{
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline);
if (EditorUtility.DisplayDialog("提示", $"通过构建模式【{buildMode}】来构建!", "Yes", "No"))
{
EditorTools.ClearUnityConsole();
EditorApplication.delayCall += ExecuteBuild;
}
else
{
Debug.LogWarning("[Build] 打包已经取消");
}
}
/// <summary> // 对齐文本间距
/// 执行构建任务 UIElementsTools.SetElementLabelMinWidth(_buildOutputField, LabelMinWidth);
/// </summary> UIElementsTools.SetElementLabelMinWidth(_buildVersionField, LabelMinWidth);
protected abstract void ExecuteBuild(); UIElementsTools.SetElementLabelMinWidth(_compressionField, LabelMinWidth);
UIElementsTools.SetElementLabelMinWidth(_encryptionField, LabelMinWidth);
UIElementsTools.SetElementLabelMinWidth(_outputNameStyleField, LabelMinWidth);
UIElementsTools.SetElementLabelMinWidth(_copyBuildinFileOptionField, LabelMinWidth);
UIElementsTools.SetElementLabelMinWidth(_copyBuildinFileTagsField, LabelMinWidth);
UIElementsTools.SetElementLabelMinWidth(_clearBuildCacheToggle, LabelMinWidth);
UIElementsTools.SetElementLabelMinWidth(_useAssetDependencyDBToggle, LabelMinWidth);
/// <summary> // 构建按钮
/// 获取构建管线支持的构建模式集合 var buildButton = Root.Q<Button>("Build");
/// </summary> buildButton.clicked += BuildButton_clicked;
protected abstract List<Enum> GetSupportBuildModes(); }
private void RefreshView()
{
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline);
bool tagsFiledVisible = buildinFileCopyOption == EBuildinFileCopyOption.ClearAndCopyByTags || buildinFileCopyOption == EBuildinFileCopyOption.OnlyCopyByTags;
_copyBuildinFileTagsField.visible = tagsFiledVisible;
}
private void BuildButton_clicked()
{
if (EditorUtility.DisplayDialog("提示", $"开始构建资源包[{PackageName}]", "Yes", "No"))
{
EditorTools.ClearUnityConsole();
EditorApplication.delayCall += ExecuteBuild;
}
else
{
Debug.LogWarning("[Build] 打包已经取消");
}
}
/// <summary> /// <summary>
/// 获取构建版本 /// 执行构建任务
/// </summary> /// </summary>
protected string GetPackageVersion() protected abstract void ExecuteBuild();
{
return _buildVersionField.value;
}
/// <summary> /// <summary>
/// 创建加密类实例 /// 获取构建版本
/// </summary> /// </summary>
protected IEncryptionServices CreateEncryptionInstance() protected string GetPackageVersion()
{ {
var encyptionClassName = AssetBundleBuilderSetting.GetPackageEncyptionClassName(PackageName, BuildPipeline); return _buildVersionField.value;
var encryptionClassTypes = EditorTools.GetAssignableTypes(typeof(IEncryptionServices)); }
var classType = encryptionClassTypes.Find(x => x.FullName.Equals(encyptionClassName));
if (classType != null)
return (IEncryptionServices)Activator.CreateInstance(classType);
else
return null;
}
private string GetDefaultPackageVersion() /// <summary>
{ /// 创建加密类实例
int totalMinutes = DateTime.Now.Hour * 60 + DateTime.Now.Minute; /// </summary>
return DateTime.Now.ToString("yyyy-MM-dd") + "-" + totalMinutes; protected IEncryptionServices CreateEncryptionInstance()
} {
} var encyptionClassName = AssetBundleBuilderSetting.GetPackageEncyptionClassName(PackageName, BuildPipeline);
var encryptionClassTypes = EditorTools.GetAssignableTypes(typeof(IEncryptionServices));
var classType = encryptionClassTypes.Find(x => x.FullName.Equals(encyptionClassName));
if (classType != null)
return (IEncryptionServices)Activator.CreateInstance(classType);
else
return null;
}
private string GetDefaultPackageVersion()
{
int totalMinutes = DateTime.Now.Hour * 60 + DateTime.Now.Minute;
return DateTime.Now.ToString("yyyy-MM-dd") + "-" + totalMinutes;
}
}
} }
#endif #endif

View File

@@ -2,7 +2,8 @@
<ui:VisualElement name="BuildContainer"> <ui:VisualElement name="BuildContainer">
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" /> <ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
<ui:TextField picking-mode="Ignore" label="Build Version" name="BuildVersion" /> <ui:TextField picking-mode="Ignore" label="Build Version" name="BuildVersion" />
<ui:VisualElement name="BuildModeContainer" style="height: 24px;" /> <ui:Toggle label="Clear Build Cache" name="ClearBuildCache" />
<ui:Toggle label="Use Asset Depend DB" name="UseAssetDependency" />
<ui:VisualElement name="EncryptionContainer" style="height: 24px;" /> <ui:VisualElement name="EncryptionContainer" style="height: 24px;" />
<uie:EnumField label="Compression" value="Center" name="Compression" /> <uie:EnumField label="Compression" value="Center" name="Compression" />
<uie:EnumField label="File Name Style" value="Center" name="FileNameStyle" /> <uie:EnumField label="File Name Style" value="Center" name="FileNameStyle" />

View File

@@ -1,4 +1,4 @@
#if UNITY_2019_4_OR_NEWER #if UNITY_2019_4_OR_NEWER
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -10,54 +10,48 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class BuiltinBuildPipelineViewer : BuildPipelineViewerBase internal class BuiltinBuildPipelineViewer : BuildPipelineViewerBase
{ {
public BuiltinBuildPipelineViewer(string packageName, BuildTarget buildTarget, VisualElement parent) public BuiltinBuildPipelineViewer(string packageName, BuildTarget buildTarget, VisualElement parent)
: base(packageName, EBuildPipeline.BuiltinBuildPipeline, buildTarget, parent) : base(packageName, EBuildPipeline.BuiltinBuildPipeline, buildTarget, parent)
{ {
} }
/// <summary> /// <summary>
/// ִ<>й<EFBFBD><D0B9><EFBFBD> /// 执行构建
/// </summary> /// </summary>
protected override void ExecuteBuild() protected override void ExecuteBuild()
{ {
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline); var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline);
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline); var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline);
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline); var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline);
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline); var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline);
var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline); var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline);
var useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline);
BuiltinBuildParameters buildParameters = new BuiltinBuildParameters(); BuiltinBuildParameters buildParameters = new BuiltinBuildParameters();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = BuildPipeline.ToString(); buildParameters.BuildPipeline = BuildPipeline.ToString();
buildParameters.BuildTarget = BuildTarget; buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
buildParameters.BuildMode = buildMode; buildParameters.BuildTarget = BuildTarget;
buildParameters.PackageName = PackageName; buildParameters.PackageName = PackageName;
buildParameters.PackageVersion = GetPackageVersion(); buildParameters.PackageVersion = GetPackageVersion();
buildParameters.VerifyBuildingResult = true; buildParameters.EnableSharePackRule = true;
buildParameters.FileNameStyle = fileNameStyle; buildParameters.VerifyBuildingResult = true;
buildParameters.BuildinFileCopyOption = buildinFileCopyOption; buildParameters.FileNameStyle = fileNameStyle;
buildParameters.BuildinFileCopyParams = buildinFileCopyParams; buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
buildParameters.EncryptionServices = CreateEncryptionInstance(); buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
buildParameters.CompressOption = compressOption; buildParameters.CompressOption = compressOption;
buildParameters.ClearBuildCacheFiles = clearBuildCache;
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
buildParameters.EncryptionServices = CreateEncryptionInstance();
BuiltinBuildPipeline pipeline = new BuiltinBuildPipeline(); BuiltinBuildPipeline pipeline = new BuiltinBuildPipeline();
var buildResult = pipeline.Run(buildParameters, true); var buildResult = pipeline.Run(buildParameters, true);
if (buildResult.Success) if (buildResult.Success)
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory); EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
} }
}
protected override List<Enum> GetSupportBuildModes()
{
List<Enum> buildModeList = new List<Enum>();
buildModeList.Add(EBuildMode.ForceRebuild);
buildModeList.Add(EBuildMode.IncrementalBuild);
buildModeList.Add(EBuildMode.DryRunBuild);
buildModeList.Add(EBuildMode.SimulateBuild);
return buildModeList;
}
}
} }
#endif #endif

View File

@@ -0,0 +1,70 @@
#if UNITY_2019_4_OR_NEWER
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
internal class EditorSimulateBuildPipelineViewer : BuildPipelineViewerBase
{
public EditorSimulateBuildPipelineViewer(string packageName, BuildTarget buildTarget, VisualElement parent)
: base(packageName, EBuildPipeline.RawFileBuildPipeline, buildTarget, parent)
{
var compressionField = Root.Q<EnumField>("Compression");
UIElementsTools.SetElementVisible(compressionField, false);
var encryptionContainer = Root.Q<VisualElement>("EncryptionContainer");
UIElementsTools.SetElementVisible(encryptionContainer, false);
var fileNameStyleField = Root.Q<EnumField>("FileNameStyle");
UIElementsTools.SetElementVisible(fileNameStyleField, false);
var copyBuildinFileOptionField = Root.Q<EnumField>("CopyBuildinFileOption");
UIElementsTools.SetElementVisible(copyBuildinFileOptionField, false);
var copyBuildinFileParamField = Root.Q<TextField>("CopyBuildinFileParam");
UIElementsTools.SetElementVisible(copyBuildinFileParamField, false);
var clearBuildCacheToggle = Root.Q<Toggle>("ClearBuildCache");
UIElementsTools.SetElementVisible(clearBuildCacheToggle, false);
var useAssetDependencyToggle = Root.Q<Toggle>("UseAssetDependency");
UIElementsTools.SetElementVisible(useAssetDependencyToggle, false);
}
/// <summary>
/// 执行构建
/// </summary>
protected override void ExecuteBuild()
{
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline);
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline);
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline);
EditorSimulateBuildParameters buildParameters = new EditorSimulateBuildParameters();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = BuildPipeline.ToString();
buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle;
buildParameters.BuildTarget = BuildTarget;
buildParameters.PackageName = PackageName;
buildParameters.PackageVersion = GetPackageVersion();
buildParameters.VerifyBuildingResult = true;
buildParameters.FileNameStyle = fileNameStyle;
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
buildParameters.EncryptionServices = CreateEncryptionInstance();
EditorSimulateBuildPipeline pipeline = new EditorSimulateBuildPipeline();
var buildResult = pipeline.Run(buildParameters, true);
if (buildResult.Success)
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 01e426f05b237b340881910d779e4c2e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,4 @@
#if UNITY_2019_4_OR_NEWER #if UNITY_2019_4_OR_NEWER
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -10,52 +10,47 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class RawfileBuildpipelineViewer : BuildPipelineViewerBase internal class RawfileBuildpipelineViewer : BuildPipelineViewerBase
{ {
public RawfileBuildpipelineViewer(string packageName, BuildTarget buildTarget, VisualElement parent) public RawfileBuildpipelineViewer(string packageName, BuildTarget buildTarget, VisualElement parent)
: base(packageName, EBuildPipeline.RawFileBuildPipeline, buildTarget, parent) : base(packageName, EBuildPipeline.RawFileBuildPipeline, buildTarget, parent)
{ {
var compressionField = Root.Q<EnumField>("Compression"); var compressionField = Root.Q<EnumField>("Compression");
UIElementsTools.SetElementVisible(compressionField, false); UIElementsTools.SetElementVisible(compressionField, false);
} }
/// <summary> /// <summary>
/// ִ<>й<EFBFBD><D0B9><EFBFBD> /// 执行构建
/// </summary> /// </summary>
protected override void ExecuteBuild() protected override void ExecuteBuild()
{ {
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline); var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline);
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline); var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline);
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline); var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline);
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline); var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline);
var useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline);
RawFileBuildParameters buildParameters = new RawFileBuildParameters(); RawFileBuildParameters buildParameters = new RawFileBuildParameters();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = BuildPipeline.ToString(); buildParameters.BuildPipeline = BuildPipeline.ToString();
buildParameters.BuildTarget = BuildTarget; buildParameters.BuildBundleType = (int)EBuildBundleType.RawBundle;
buildParameters.BuildMode = buildMode; buildParameters.BuildTarget = BuildTarget;
buildParameters.PackageName = PackageName; buildParameters.PackageName = PackageName;
buildParameters.PackageVersion = GetPackageVersion(); buildParameters.PackageVersion = GetPackageVersion();
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
buildParameters.FileNameStyle = fileNameStyle; buildParameters.FileNameStyle = fileNameStyle;
buildParameters.BuildinFileCopyOption = buildinFileCopyOption; buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
buildParameters.BuildinFileCopyParams = buildinFileCopyParams; buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
buildParameters.EncryptionServices = CreateEncryptionInstance(); buildParameters.ClearBuildCacheFiles = clearBuildCache;
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
buildParameters.EncryptionServices = CreateEncryptionInstance();
RawFileBuildPipeline pipeline = new RawFileBuildPipeline(); RawFileBuildPipeline pipeline = new RawFileBuildPipeline();
var buildResult = pipeline.Run(buildParameters, true); var buildResult = pipeline.Run(buildParameters, true);
if (buildResult.Success) if (buildResult.Success)
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory); EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
} }
}
protected override List<Enum> GetSupportBuildModes()
{
List<Enum> buildModeList = new List<Enum>();
buildModeList.Add(EBuildMode.ForceRebuild);
buildModeList.Add(EBuildMode.SimulateBuild);
return buildModeList;
}
}
} }
#endif #endif

View File

@@ -10,52 +10,48 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class ScriptableBuildPipelineViewer : BuildPipelineViewerBase internal class ScriptableBuildPipelineViewer : BuildPipelineViewerBase
{ {
public ScriptableBuildPipelineViewer(string packageName, BuildTarget buildTarget, VisualElement parent) public ScriptableBuildPipelineViewer(string packageName, BuildTarget buildTarget, VisualElement parent)
: base(packageName, EBuildPipeline.ScriptableBuildPipeline, buildTarget, parent) : base(packageName, EBuildPipeline.ScriptableBuildPipeline, buildTarget, parent)
{ {
} }
/// <summary> /// <summary>
/// 执行构建 /// 执行构建
/// </summary> /// </summary>
protected override void ExecuteBuild() protected override void ExecuteBuild()
{ {
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline); var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline);
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline); var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline);
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline); var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline);
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline); var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline);
var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline); var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline);
var useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline);
ScriptableBuildParameters buildParameters = new ScriptableBuildParameters(); ScriptableBuildParameters buildParameters = new ScriptableBuildParameters();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = BuildPipeline.ToString(); buildParameters.BuildPipeline = BuildPipeline.ToString();
buildParameters.BuildTarget = BuildTarget; buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
buildParameters.BuildMode = buildMode; buildParameters.BuildTarget = BuildTarget;
buildParameters.PackageName = PackageName; buildParameters.PackageName = PackageName;
buildParameters.PackageVersion = GetPackageVersion(); buildParameters.PackageVersion = GetPackageVersion();
buildParameters.VerifyBuildingResult = true; buildParameters.EnableSharePackRule = true;
buildParameters.FileNameStyle = fileNameStyle; buildParameters.VerifyBuildingResult = true;
buildParameters.BuildinFileCopyOption = buildinFileCopyOption; buildParameters.FileNameStyle = fileNameStyle;
buildParameters.BuildinFileCopyParams = buildinFileCopyParams; buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
buildParameters.EncryptionServices = CreateEncryptionInstance(); buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
buildParameters.CompressOption = compressOption; buildParameters.CompressOption = compressOption;
buildParameters.ClearBuildCacheFiles = clearBuildCache;
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
buildParameters.EncryptionServices = CreateEncryptionInstance();
ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline(); ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline();
var buildResult = pipeline.Run(buildParameters, true); var buildResult = pipeline.Run(buildParameters, true);
if (buildResult.Success) if (buildResult.Success)
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory); EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
} }
}
protected override List<Enum> GetSupportBuildModes()
{
List<Enum> buildModeList = new List<Enum>();
buildModeList.Add(EBuildMode.IncrementalBuild);
buildModeList.Add(EBuildMode.SimulateBuild);
return buildModeList;
}
}
} }
#endif #endif

View File

@@ -6,316 +6,283 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
[Serializable] [Serializable]
public class AssetBundleCollector public class AssetBundleCollector
{ {
/// <summary> /// <summary>
/// 收集路径 /// 收集路径
/// 注意:支持文件夹或单个资源文件 /// 注意:支持文件夹或单个资源文件
/// </summary> /// </summary>
public string CollectPath = string.Empty; public string CollectPath = string.Empty;
/// <summary> /// <summary>
/// 收集器的GUID /// 收集器的GUID
/// </summary> /// </summary>
public string CollectorGUID = string.Empty; public string CollectorGUID = string.Empty;
/// <summary> /// <summary>
/// 收集器类型 /// 收集器类型
/// </summary> /// </summary>
public ECollectorType CollectorType = ECollectorType.MainAssetCollector; public ECollectorType CollectorType = ECollectorType.MainAssetCollector;
/// <summary> /// <summary>
/// 寻址规则类名 /// 寻址规则类名
/// </summary> /// </summary>
public string AddressRuleName = nameof(AddressByFileName); public string AddressRuleName = nameof(AddressByFileName);
/// <summary> /// <summary>
/// 打包规则类名 /// 打包规则类名
/// </summary> /// </summary>
public string PackRuleName = nameof(PackDirectory); public string PackRuleName = nameof(PackDirectory);
/// <summary> /// <summary>
/// 过滤规则类名 /// 过滤规则类名
/// </summary> /// </summary>
public string FilterRuleName = nameof(CollectAll); public string FilterRuleName = nameof(CollectAll);
/// <summary> /// <summary>
/// 资源分类标签 /// 资源分类标签
/// </summary> /// </summary>
public string AssetTags = string.Empty; public string AssetTags = string.Empty;
/// <summary> /// <summary>
/// 用户自定义数据 /// 用户自定义数据
/// </summary> /// </summary>
public string UserData = string.Empty; public string UserData = string.Empty;
/// <summary> /// <summary>
/// 收集器是否有效 /// 收集器是否有效
/// </summary> /// </summary>
public bool IsValid() public bool IsValid()
{ {
if (AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(CollectPath) == null) if (AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(CollectPath) == null)
return false; return false;
if (CollectorType == ECollectorType.None) if (CollectorType == ECollectorType.None)
return false; return false;
if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false) if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
return false; return false;
if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false) if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
return false; return false;
if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false) if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
return false; return false;
return true; return true;
} }
/// <summary> /// <summary>
/// 检测配置错误 /// 检测配置错误
/// </summary> /// </summary>
public void CheckConfigError() public void CheckConfigError()
{ {
string assetGUID = AssetDatabase.AssetPathToGUID(CollectPath); string assetGUID = AssetDatabase.AssetPathToGUID(CollectPath);
if (string.IsNullOrEmpty(assetGUID)) if (string.IsNullOrEmpty(assetGUID))
throw new Exception($"Invalid collect path : {CollectPath}"); throw new Exception($"Invalid collect path : {CollectPath}");
if (CollectorType == ECollectorType.None) if (CollectorType == ECollectorType.None)
throw new Exception($"{nameof(ECollectorType)}.{ECollectorType.None} is invalid in collector : {CollectPath}"); throw new Exception($"{nameof(ECollectorType)}.{ECollectorType.None} is invalid in collector : {CollectPath}");
if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false) if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
throw new Exception($"Invalid {nameof(IPackRule)} class type : {PackRuleName} in collector : {CollectPath}"); throw new Exception($"Invalid {nameof(IPackRule)} class type : {PackRuleName} in collector : {CollectPath}");
if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false) if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
throw new Exception($"Invalid {nameof(IFilterRule)} class type : {FilterRuleName} in collector : {CollectPath}"); throw new Exception($"Invalid {nameof(IFilterRule)} class type : {FilterRuleName} in collector : {CollectPath}");
if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false) if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
throw new Exception($"Invalid {nameof(IAddressRule)} class type : {AddressRuleName} in collector : {CollectPath}"); throw new Exception($"Invalid {nameof(IAddressRule)} class type : {AddressRuleName} in collector : {CollectPath}");
} }
/// <summary> /// <summary>
/// 修复配置错误 /// 修复配置错误
/// </summary> /// </summary>
public bool FixConfigError() public bool FixConfigError()
{ {
bool isFixed = false; bool isFixed = false;
if (string.IsNullOrEmpty(CollectorGUID) == false) if (string.IsNullOrEmpty(CollectorGUID) == false)
{ {
string convertAssetPath = AssetDatabase.GUIDToAssetPath(CollectorGUID); string convertAssetPath = AssetDatabase.GUIDToAssetPath(CollectorGUID);
if (string.IsNullOrEmpty(convertAssetPath)) if (string.IsNullOrEmpty(convertAssetPath))
{ {
Debug.LogWarning($"Collector GUID {CollectorGUID} is invalid and has been auto removed !"); Debug.LogWarning($"Collector GUID {CollectorGUID} is invalid and has been auto removed !");
CollectorGUID = string.Empty; CollectorGUID = string.Empty;
isFixed = true; isFixed = true;
} }
else else
{ {
if (CollectPath != convertAssetPath) if (CollectPath != convertAssetPath)
{ {
CollectPath = convertAssetPath; CollectPath = convertAssetPath;
isFixed = true; isFixed = true;
Debug.LogWarning($"Fix collect path : {CollectPath} -> {convertAssetPath}"); Debug.LogWarning($"Fix collect path : {CollectPath} -> {convertAssetPath}");
} }
} }
} }
/* /*
string convertGUID = AssetDatabase.AssetPathToGUID(CollectPath); string convertGUID = AssetDatabase.AssetPathToGUID(CollectPath);
if(string.IsNullOrEmpty(convertGUID) == false) if(string.IsNullOrEmpty(convertGUID) == false)
{ {
CollectorGUID = convertGUID; CollectorGUID = convertGUID;
} }
*/ */
return isFixed; return isFixed;
} }
/// <summary> /// <summary>
/// 获取打包收集的资源文件 /// 获取打包收集的资源文件
/// </summary> /// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command, AssetBundleCollectorGroup group) public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command, AssetBundleCollectorGroup group)
{ {
// 注意:模拟构建模式下只收集主资源 // 注意:模拟构建模式下只收集主资源
if (command.BuildMode == EBuildMode.SimulateBuild) if (command.SimulateBuild)
{ {
if (CollectorType != ECollectorType.MainAssetCollector) if (CollectorType != ECollectorType.MainAssetCollector)
return new List<CollectAssetInfo>(); return new List<CollectAssetInfo>();
} }
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000); Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
// 收集打包资源 // 收集打包资源路径
if (AssetDatabase.IsValidFolder(CollectPath)) List<string> findAssets = new List<string>();
{ if (AssetDatabase.IsValidFolder(CollectPath))
string collectDirectory = CollectPath; {
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory); string collectDirectory = CollectPath;
foreach (string assetPath in findAssets) string[] findResult = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
{ findAssets.AddRange(findResult);
if (IsValidateAsset(command, assetPath) && IsCollectAsset(group, assetPath)) }
{ else
if (result.ContainsKey(assetPath) == false) {
{ string assetPath = CollectPath;
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath); findAssets.Add(assetPath);
result.Add(assetPath, collectAssetInfo); }
}
else
{
throw new Exception($"The collecting asset file is existed : {assetPath} in collector : {CollectPath}");
}
}
}
}
else
{
string assetPath = CollectPath;
if (IsValidateAsset(command, assetPath) && IsCollectAsset(group, assetPath))
{
var collectAssetInfo = CreateCollectAssetInfo(command, group, assetPath);
result.Add(assetPath, collectAssetInfo);
}
else
{
throw new Exception($"The collecting single asset file is invalid : {assetPath} in collector : {CollectPath}");
}
}
// 检测可寻址地址是否重复 // 收集打包资源信息
if (command.EnableAddressable) foreach (string assetPath in findAssets)
{ {
var addressTemper = new Dictionary<string, string>(); var assetInfo = new AssetInfo(assetPath);
foreach (var collectInfoPair in result) if (command.IgnoreRule.IsIgnore(assetInfo) == false && IsCollectAsset(group, assetInfo))
{ {
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector) if (result.ContainsKey(assetPath) == false)
{ {
string address = collectInfoPair.Value.Address; var collectAssetInfo = CreateCollectAssetInfo(command, group, assetInfo);
string assetPath = collectInfoPair.Value.AssetPath; result.Add(assetPath, collectAssetInfo);
if (string.IsNullOrEmpty(address)) }
continue; else
{
throw new Exception($"The collecting asset file is existed : {assetPath} in collector : {CollectPath}");
}
}
}
if (address.StartsWith("Assets/") || address.StartsWith("assets/")) // 检测可寻址地址是否重复
throw new Exception($"The address can not set asset path in collector : {CollectPath} \nAssetPath: {assetPath}"); if (command.EnableAddressable)
{
var addressTemper = new Dictionary<string, string>();
foreach (var collectInfoPair in result)
{
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectInfoPair.Value.Address;
string assetPath = collectInfoPair.Value.AssetInfo.AssetPath;
if (string.IsNullOrEmpty(address))
continue;
if (addressTemper.TryGetValue(address, out var existed) == false) if (address.StartsWith("Assets/") || address.StartsWith("assets/"))
addressTemper.Add(address, assetPath); throw new Exception($"The address can not set asset path in collector : {CollectPath} \nAssetPath: {assetPath}");
else
throw new Exception($"The address is existed : {address} in collector : {CollectPath} \nAssetPath:\n {existed}\n {assetPath}");
}
}
}
// 返回列表 if (addressTemper.TryGetValue(address, out var existed) == false)
return result.Values.ToList(); addressTemper.Add(address, assetPath);
} else
throw new Exception($"The address is existed : {address} in collector : {CollectPath} \nAssetPath:\n {existed}\n {assetPath}");
}
}
}
private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, string assetPath) // 返回列表
{ return result.Values.ToList();
string address = GetAddress(command, group, assetPath); }
string bundleName = GetBundleName(command, group, assetPath);
List<string> assetTags = GetAssetTags(group);
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags);
// 注意:模拟构建模式下不需要收集依赖资源
if (command.BuildMode == EBuildMode.SimulateBuild)
collectAssetInfo.DependAssets = new List<string>();
else
collectAssetInfo.DependAssets = GetAllDependencies(command, assetPath);
return collectAssetInfo; /// <summary>
} /// 创建资源收集类
private bool IsValidateAsset(CollectCommand command, string assetPath) /// </summary>
{ private CollectAssetInfo CreateCollectAssetInfo(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false) {
{ string address = GetAddress(command, group, assetInfo);
UnityEngine.Debug.LogError($"Invalid asset path : {assetPath}"); string bundleName = GetBundleName(command, group, assetInfo);
return false; List<string> assetTags = GetAssetTags(group);
} CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetInfo, assetTags);
collectAssetInfo.DependAssets = GetAllDependencies(command, assetInfo.AssetPath);
return collectAssetInfo;
}
// 忽略文件夹 private bool IsCollectAsset(AssetBundleCollectorGroup group, AssetInfo assetInfo)
if (AssetDatabase.IsValidFolder(assetPath)) {
return false; // 根据规则设置过滤资源文件
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
}
private string GetAddress(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
{
if (command.EnableAddressable == false)
return string.Empty;
// 忽略编辑器下的类型资源 if (CollectorType != ECollectorType.MainAssetCollector)
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); return string.Empty;
if (assetType == typeof(LightingDataAsset))
return false;
// 忽略Unity引擎无法识别的文件 IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName);
if (command.IgnoreDefaultType) string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
{ return adressValue;
if (assetType == typeof(UnityEditor.DefaultAsset)) }
{ private string GetBundleName(CollectCommand command, AssetBundleCollectorGroup group, AssetInfo assetInfo)
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetPath}"); {
return false; if (command.AutoCollectShaders)
} {
} if (assetInfo.IsShaderAsset())
{
// 获取着色器打包规则结果
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
return shaderPackRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
}
}
string fileExtension = System.IO.Path.GetExtension(assetPath); // 获取其它资源打包规则结果
if (DefaultFilterRule.IsIgnoreFile(fileExtension)) IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
return false; PackRuleResult defaultPackRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetInfo.AssetPath, CollectPath, group.GroupName, UserData));
return defaultPackRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
}
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
{
List<string> tags = EditorTools.StringToStringList(group.AssetTags, ';');
List<string> temper = EditorTools.StringToStringList(AssetTags, ';');
tags.AddRange(temper);
return tags;
}
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
{
// 注意:模拟构建模式下不需要收集依赖资源
if (command.SimulateBuild)
return new List<AssetInfo>();
return true; string[] depends = command.AssetDependency.GetDependencies(mainAssetPath, true);
} List<AssetInfo> result = new List<AssetInfo>(depends.Length);
private bool IsCollectAsset(AssetBundleCollectorGroup group, string assetPath) foreach (string assetPath in depends)
{ {
// 根据规则设置过滤资源文件 // 注意:排除主资源对象
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName); if (assetPath == mainAssetPath)
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath, CollectPath, group.GroupName, UserData)); continue;
}
private string GetAddress(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
{
if (command.EnableAddressable == false)
return string.Empty;
if (CollectorType != ECollectorType.MainAssetCollector) AssetInfo assetInfo = new AssetInfo(assetPath);
return string.Empty; if (command.IgnoreRule.IsIgnore(assetInfo) == false)
result.Add(assetInfo);
IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName); }
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName, UserData)); return result;
return adressValue; }
} }
private string GetBundleName(CollectCommand command, AssetBundleCollectorGroup group, string assetPath)
{
if (command.AutoCollectShaders)
{
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection))
{
// 获取着色器打包规则结果
PackRuleResult shaderPackRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
return shaderPackRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
}
}
// 获取其它资源打包规则结果
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
PackRuleResult defaultPackRuleResult = packRuleInstance.GetPackRuleResult(new PackRuleData(assetPath, CollectPath, group.GroupName, UserData));
return defaultPackRuleResult.GetBundleName(command.PackageName, command.UniqueBundleName);
}
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
{
List<string> tags = EditorTools.StringToStringList(group.AssetTags, ';');
List<string> temper = EditorTools.StringToStringList(AssetTags, ';');
tags.AddRange(temper);
return tags;
}
private List<string> GetAllDependencies(CollectCommand command, string mainAssetPath)
{
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
List<string> result = new List<string>(depends.Length);
foreach (string assetPath in depends)
{
// 注意:排除主资源对象
if (assetPath == mainAssetPath)
continue;
if (IsValidateAsset(command, assetPath))
result.Add(assetPath);
}
return result;
}
}
} }

View File

@@ -8,257 +8,274 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleCollectorConfig public class AssetBundleCollectorConfig
{ {
public const string ConfigVersion = "v2.0.0"; public const string ConfigVersion = "v2.1";
public const string XmlVersion = "Version"; public const string XmlVersion = "Version";
public const string XmlCommon = "Common"; public const string XmlCommon = "Common";
public const string XmlShowPackageView = "ShowPackageView"; public const string XmlShowPackageView = "ShowPackageView";
public const string XmlShowEditorAlias = "ShowEditorAlias"; public const string XmlShowEditorAlias = "ShowEditorAlias";
public const string XmlUniqueBundleName = "UniqueBundleName"; public const string XmlUniqueBundleName = "UniqueBundleName";
public const string XmlPackage = "Package"; public const string XmlPackage = "Package";
public const string XmlPackageName = "PackageName"; public const string XmlPackageName = "PackageName";
public const string XmlPackageDesc = "PackageDesc"; public const string XmlPackageDesc = "PackageDesc";
public const string XmlEnableAddressable = "AutoAddressable"; public const string XmlEnableAddressable = "AutoAddressable";
public const string XmlLocationToLower = "LocationToLower"; public const string XmlLocationToLower = "LocationToLower";
public const string XmlIncludeAssetGUID = "IncludeAssetGUID"; public const string XmlIncludeAssetGUID = "IncludeAssetGUID";
public const string XmlIgnoreDefaultType = "IgnoreDefaultType"; public const string XmlIgnoreRuleName = "IgnoreRuleName";
public const string XmlGroup = "Group"; public const string XmlGroup = "Group";
public const string XmlGroupActiveRule = "GroupActiveRule"; public const string XmlGroupActiveRule = "GroupActiveRule";
public const string XmlGroupName = "GroupName"; public const string XmlGroupName = "GroupName";
public const string XmlGroupDesc = "GroupDesc"; public const string XmlGroupDesc = "GroupDesc";
public const string XmlCollector = "Collector"; public const string XmlCollector = "Collector";
public const string XmlCollectPath = "CollectPath"; public const string XmlCollectPath = "CollectPath";
public const string XmlCollectorGUID = "CollectGUID"; public const string XmlCollectorGUID = "CollectGUID";
public const string XmlCollectorType = "CollectType"; public const string XmlCollectorType = "CollectType";
public const string XmlAddressRule = "AddressRule"; public const string XmlAddressRule = "AddressRule";
public const string XmlPackRule = "PackRule"; public const string XmlPackRule = "PackRule";
public const string XmlFilterRule = "FilterRule"; public const string XmlFilterRule = "FilterRule";
public const string XmlUserData = "UserData"; public const string XmlUserData = "UserData";
public const string XmlAssetTags = "AssetTags"; public const string XmlAssetTags = "AssetTags";
/// <summary> /// <summary>
/// 导入XML配置表 /// 导入XML配置表
/// </summary> /// </summary>
public static void ImportXmlConfig(string filePath) public static void ImportXmlConfig(string filePath)
{ {
if (File.Exists(filePath) == false) if (File.Exists(filePath) == false)
throw new FileNotFoundException(filePath); throw new FileNotFoundException(filePath);
if (Path.GetExtension(filePath) != ".xml") if (Path.GetExtension(filePath) != ".xml")
throw new Exception($"Only support xml : {filePath}"); throw new Exception($"Only support xml : {filePath}");
// 加载配置文件 // 加载配置文件
XmlDocument xmlDoc = new XmlDocument(); XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath); xmlDoc.Load(filePath);
XmlElement root = xmlDoc.DocumentElement; XmlElement root = xmlDoc.DocumentElement;
// 读取配置版本 // 读取配置版本
string configVersion = root.GetAttribute(XmlVersion); string configVersion = root.GetAttribute(XmlVersion);
if (configVersion != ConfigVersion) if (configVersion != ConfigVersion)
{ {
if (UpdateXmlConfig(xmlDoc) == false) if (UpdateXmlConfig(xmlDoc) == false)
throw new Exception($"The config version update failed : {configVersion} -> {ConfigVersion}"); throw new Exception($"The config version update failed : {configVersion} -> {ConfigVersion}");
else else
Debug.Log($"The config version update succeed : {configVersion} -> {ConfigVersion}"); Debug.Log($"The config version update succeed : {configVersion} -> {ConfigVersion}");
} }
// 读取公共配置 // 读取公共配置
bool uniqueBundleName = false; bool uniqueBundleName = false;
bool showPackageView = false; bool showPackageView = false;
bool showEditorAlias = false; bool showEditorAlias = false;
var commonNodeList = root.GetElementsByTagName(XmlCommon); var commonNodeList = root.GetElementsByTagName(XmlCommon);
if (commonNodeList.Count > 0) if (commonNodeList.Count > 0)
{ {
XmlElement commonElement = commonNodeList[0] as XmlElement; XmlElement commonElement = commonNodeList[0] as XmlElement;
if (commonElement.HasAttribute(XmlShowPackageView)) if (commonElement.HasAttribute(XmlShowPackageView))
showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false; showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false;
if (commonElement.HasAttribute(XmlShowEditorAlias)) if (commonElement.HasAttribute(XmlShowEditorAlias))
showEditorAlias = commonElement.GetAttribute(XmlShowEditorAlias) == "True" ? true : false; showEditorAlias = commonElement.GetAttribute(XmlShowEditorAlias) == "True" ? true : false;
if (commonElement.HasAttribute(XmlUniqueBundleName)) if (commonElement.HasAttribute(XmlUniqueBundleName))
uniqueBundleName = commonElement.GetAttribute(XmlUniqueBundleName) == "True" ? true : false; uniqueBundleName = commonElement.GetAttribute(XmlUniqueBundleName) == "True" ? true : false;
} }
// 读取包裹配置 // 读取包裹配置
List<AssetBundleCollectorPackage> packages = new List<AssetBundleCollectorPackage>(); List<AssetBundleCollectorPackage> packages = new List<AssetBundleCollectorPackage>();
var packageNodeList = root.GetElementsByTagName(XmlPackage); var packageNodeList = root.GetElementsByTagName(XmlPackage);
foreach (var packageNode in packageNodeList) foreach (var packageNode in packageNodeList)
{ {
XmlElement packageElement = packageNode as XmlElement; XmlElement packageElement = packageNode as XmlElement;
if (packageElement.HasAttribute(XmlPackageName) == false) if (packageElement.HasAttribute(XmlPackageName) == false)
throw new Exception($"Not found attribute {XmlPackageName} in {XmlPackage}"); throw new Exception($"Not found attribute {XmlPackageName} in {XmlPackage}");
if (packageElement.HasAttribute(XmlPackageDesc) == false) if (packageElement.HasAttribute(XmlPackageDesc) == false)
throw new Exception($"Not found attribute {XmlPackageDesc} in {XmlPackage}"); throw new Exception($"Not found attribute {XmlPackageDesc} in {XmlPackage}");
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage(); AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
package.PackageName = packageElement.GetAttribute(XmlPackageName); package.PackageName = packageElement.GetAttribute(XmlPackageName);
package.PackageDesc = packageElement.GetAttribute(XmlPackageDesc); package.PackageDesc = packageElement.GetAttribute(XmlPackageDesc);
package.EnableAddressable = packageElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false; package.EnableAddressable = packageElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
package.LocationToLower = packageElement.GetAttribute(XmlLocationToLower) == "True" ? true : false; package.LocationToLower = packageElement.GetAttribute(XmlLocationToLower) == "True" ? true : false;
package.IncludeAssetGUID = packageElement.GetAttribute(XmlIncludeAssetGUID) == "True" ? true : false; package.IncludeAssetGUID = packageElement.GetAttribute(XmlIncludeAssetGUID) == "True" ? true : false;
package.IgnoreDefaultType = packageElement.GetAttribute(XmlIgnoreDefaultType) == "True" ? true : false; package.IgnoreRuleName = packageElement.GetAttribute(XmlIgnoreRuleName);
packages.Add(package); packages.Add(package);
// 读取分组配置 // 读取分组配置
var groupNodeList = packageElement.GetElementsByTagName(XmlGroup); var groupNodeList = packageElement.GetElementsByTagName(XmlGroup);
foreach (var groupNode in groupNodeList) foreach (var groupNode in groupNodeList)
{ {
XmlElement groupElement = groupNode as XmlElement; XmlElement groupElement = groupNode as XmlElement;
if (groupElement.HasAttribute(XmlGroupActiveRule) == false) if (groupElement.HasAttribute(XmlGroupActiveRule) == false)
throw new Exception($"Not found attribute {XmlGroupActiveRule} in {XmlGroup}"); throw new Exception($"Not found attribute {XmlGroupActiveRule} in {XmlGroup}");
if (groupElement.HasAttribute(XmlGroupName) == false) if (groupElement.HasAttribute(XmlGroupName) == false)
throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}"); throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}");
if (groupElement.HasAttribute(XmlGroupDesc) == false) if (groupElement.HasAttribute(XmlGroupDesc) == false)
throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}"); throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}");
if (groupElement.HasAttribute(XmlAssetTags) == false) if (groupElement.HasAttribute(XmlAssetTags) == false)
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}"); throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}");
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup(); AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
group.ActiveRuleName = groupElement.GetAttribute(XmlGroupActiveRule); group.ActiveRuleName = groupElement.GetAttribute(XmlGroupActiveRule);
group.GroupName = groupElement.GetAttribute(XmlGroupName); group.GroupName = groupElement.GetAttribute(XmlGroupName);
group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc); group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc);
group.AssetTags = groupElement.GetAttribute(XmlAssetTags); group.AssetTags = groupElement.GetAttribute(XmlAssetTags);
package.Groups.Add(group); package.Groups.Add(group);
// 读取收集器配置 // 读取收集器配置
var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector); var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
foreach (var collectorNode in collectorNodeList) foreach (var collectorNode in collectorNodeList)
{ {
XmlElement collectorElement = collectorNode as XmlElement; XmlElement collectorElement = collectorNode as XmlElement;
if (collectorElement.HasAttribute(XmlCollectPath) == false) if (collectorElement.HasAttribute(XmlCollectPath) == false)
throw new Exception($"Not found attribute {XmlCollectPath} in {XmlCollector}"); throw new Exception($"Not found attribute {XmlCollectPath} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlCollectorGUID) == false) if (collectorElement.HasAttribute(XmlCollectorGUID) == false)
throw new Exception($"Not found attribute {XmlCollectorGUID} in {XmlCollector}"); throw new Exception($"Not found attribute {XmlCollectorGUID} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlCollectorType) == false) if (collectorElement.HasAttribute(XmlCollectorType) == false)
throw new Exception($"Not found attribute {XmlCollectorType} in {XmlCollector}"); throw new Exception($"Not found attribute {XmlCollectorType} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlAddressRule) == false) if (collectorElement.HasAttribute(XmlAddressRule) == false)
throw new Exception($"Not found attribute {XmlAddressRule} in {XmlCollector}"); throw new Exception($"Not found attribute {XmlAddressRule} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlPackRule) == false) if (collectorElement.HasAttribute(XmlPackRule) == false)
throw new Exception($"Not found attribute {XmlPackRule} in {XmlCollector}"); throw new Exception($"Not found attribute {XmlPackRule} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlFilterRule) == false) if (collectorElement.HasAttribute(XmlFilterRule) == false)
throw new Exception($"Not found attribute {XmlFilterRule} in {XmlCollector}"); throw new Exception($"Not found attribute {XmlFilterRule} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlUserData) == false) if (collectorElement.HasAttribute(XmlUserData) == false)
throw new Exception($"Not found attribute {XmlUserData} in {XmlCollector}"); throw new Exception($"Not found attribute {XmlUserData} in {XmlCollector}");
if (collectorElement.HasAttribute(XmlAssetTags) == false) if (collectorElement.HasAttribute(XmlAssetTags) == false)
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}"); throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}");
AssetBundleCollector collector = new AssetBundleCollector(); AssetBundleCollector collector = new AssetBundleCollector();
collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath); collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath);
collector.CollectorGUID = collectorElement.GetAttribute(XmlCollectorGUID); collector.CollectorGUID = collectorElement.GetAttribute(XmlCollectorGUID);
collector.CollectorType = EditorTools.NameToEnum<ECollectorType>(collectorElement.GetAttribute(XmlCollectorType)); collector.CollectorType = EditorTools.NameToEnum<ECollectorType>(collectorElement.GetAttribute(XmlCollectorType));
collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule); collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule); collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule); collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
collector.UserData = collectorElement.GetAttribute(XmlUserData); collector.UserData = collectorElement.GetAttribute(XmlUserData);
collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags); collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags);
group.Collectors.Add(collector); group.Collectors.Add(collector);
} }
} }
} }
// 检测配置错误 // 检测配置错误
foreach (var package in packages) foreach (var package in packages)
{ {
package.CheckConfigError(); package.CheckConfigError();
} }
// 保存配置数据 // 保存配置数据
AssetBundleCollectorSettingData.ClearAll(); AssetBundleCollectorSettingData.ClearAll();
AssetBundleCollectorSettingData.Setting.ShowPackageView = showPackageView; AssetBundleCollectorSettingData.Setting.ShowPackageView = showPackageView;
AssetBundleCollectorSettingData.Setting.ShowEditorAlias = showEditorAlias; AssetBundleCollectorSettingData.Setting.ShowEditorAlias = showEditorAlias;
AssetBundleCollectorSettingData.Setting.UniqueBundleName = uniqueBundleName; AssetBundleCollectorSettingData.Setting.UniqueBundleName = uniqueBundleName;
AssetBundleCollectorSettingData.Setting.Packages.AddRange(packages); AssetBundleCollectorSettingData.Setting.Packages.AddRange(packages);
AssetBundleCollectorSettingData.SaveFile(); AssetBundleCollectorSettingData.SaveFile();
Debug.Log($"Asset bundle collector config import complete"); Debug.Log($"Asset bundle collector config import complete");
} }
/// <summary> /// <summary>
/// 导出XML配置表 /// 导出XML配置表
/// </summary> /// </summary>
public static void ExportXmlConfig(string savePath) public static void ExportXmlConfig(string savePath)
{ {
if (File.Exists(savePath)) if (File.Exists(savePath))
File.Delete(savePath); File.Delete(savePath);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sb.AppendLine("<root>"); sb.AppendLine("<root>");
sb.AppendLine("</root>"); sb.AppendLine("</root>");
XmlDocument xmlDoc = new XmlDocument(); XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(sb.ToString()); xmlDoc.LoadXml(sb.ToString());
XmlElement root = xmlDoc.DocumentElement; XmlElement root = xmlDoc.DocumentElement;
// 设置配置版本 // 设置配置版本
root.SetAttribute(XmlVersion, ConfigVersion); root.SetAttribute(XmlVersion, ConfigVersion);
// 设置公共配置 // 设置公共配置
var commonElement = xmlDoc.CreateElement(XmlCommon); var commonElement = xmlDoc.CreateElement(XmlCommon);
commonElement.SetAttribute(XmlShowPackageView, AssetBundleCollectorSettingData.Setting.ShowPackageView.ToString()); commonElement.SetAttribute(XmlShowPackageView, AssetBundleCollectorSettingData.Setting.ShowPackageView.ToString());
commonElement.SetAttribute(XmlShowEditorAlias, AssetBundleCollectorSettingData.Setting.ShowEditorAlias.ToString()); commonElement.SetAttribute(XmlShowEditorAlias, AssetBundleCollectorSettingData.Setting.ShowEditorAlias.ToString());
commonElement.SetAttribute(XmlUniqueBundleName, AssetBundleCollectorSettingData.Setting.UniqueBundleName.ToString()); commonElement.SetAttribute(XmlUniqueBundleName, AssetBundleCollectorSettingData.Setting.UniqueBundleName.ToString());
root.AppendChild(commonElement); root.AppendChild(commonElement);
// 设置Package配置 // 设置Package配置
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages) foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
{ {
var packageElement = xmlDoc.CreateElement(XmlPackage); var packageElement = xmlDoc.CreateElement(XmlPackage);
packageElement.SetAttribute(XmlPackageName, package.PackageName); packageElement.SetAttribute(XmlPackageName, package.PackageName);
packageElement.SetAttribute(XmlPackageDesc, package.PackageDesc); packageElement.SetAttribute(XmlPackageDesc, package.PackageDesc);
packageElement.SetAttribute(XmlEnableAddressable, package.EnableAddressable.ToString()); packageElement.SetAttribute(XmlEnableAddressable, package.EnableAddressable.ToString());
packageElement.SetAttribute(XmlLocationToLower, package.LocationToLower.ToString()); packageElement.SetAttribute(XmlLocationToLower, package.LocationToLower.ToString());
packageElement.SetAttribute(XmlIncludeAssetGUID, package.IncludeAssetGUID.ToString()); packageElement.SetAttribute(XmlIncludeAssetGUID, package.IncludeAssetGUID.ToString());
packageElement.SetAttribute(XmlIgnoreDefaultType, package.IgnoreDefaultType.ToString()); packageElement.SetAttribute(XmlIgnoreRuleName, package.IgnoreRuleName);
root.AppendChild(packageElement); root.AppendChild(packageElement);
// 设置分组配置 // 设置分组配置
foreach (var group in package.Groups) foreach (var group in package.Groups)
{ {
var groupElement = xmlDoc.CreateElement(XmlGroup); var groupElement = xmlDoc.CreateElement(XmlGroup);
groupElement.SetAttribute(XmlGroupActiveRule, group.ActiveRuleName); groupElement.SetAttribute(XmlGroupActiveRule, group.ActiveRuleName);
groupElement.SetAttribute(XmlGroupName, group.GroupName); groupElement.SetAttribute(XmlGroupName, group.GroupName);
groupElement.SetAttribute(XmlGroupDesc, group.GroupDesc); groupElement.SetAttribute(XmlGroupDesc, group.GroupDesc);
groupElement.SetAttribute(XmlAssetTags, group.AssetTags); groupElement.SetAttribute(XmlAssetTags, group.AssetTags);
packageElement.AppendChild(groupElement); packageElement.AppendChild(groupElement);
// 设置收集器配置 // 设置收集器配置
foreach (var collector in group.Collectors) foreach (var collector in group.Collectors)
{ {
var collectorElement = xmlDoc.CreateElement(XmlCollector); var collectorElement = xmlDoc.CreateElement(XmlCollector);
collectorElement.SetAttribute(XmlCollectPath, collector.CollectPath); collectorElement.SetAttribute(XmlCollectPath, collector.CollectPath);
collectorElement.SetAttribute(XmlCollectorGUID, collector.CollectorGUID); collectorElement.SetAttribute(XmlCollectorGUID, collector.CollectorGUID);
collectorElement.SetAttribute(XmlCollectorType, collector.CollectorType.ToString()); collectorElement.SetAttribute(XmlCollectorType, collector.CollectorType.ToString());
collectorElement.SetAttribute(XmlAddressRule, collector.AddressRuleName); collectorElement.SetAttribute(XmlAddressRule, collector.AddressRuleName);
collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName); collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName);
collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName); collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName);
collectorElement.SetAttribute(XmlUserData, collector.UserData); collectorElement.SetAttribute(XmlUserData, collector.UserData);
collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags); collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags);
groupElement.AppendChild(collectorElement); groupElement.AppendChild(collectorElement);
} }
} }
} }
// 生成配置文件 // 生成配置文件
xmlDoc.Save(savePath); xmlDoc.Save(savePath);
Debug.Log($"Asset bundle collector config export complete"); Debug.Log($"Asset bundle collector config export complete");
} }
/// <summary> /// <summary>
/// 升级XML配置表 /// 升级XML配置表
/// </summary> /// </summary>
private static bool UpdateXmlConfig(XmlDocument xmlDoc) private static bool UpdateXmlConfig(XmlDocument xmlDoc)
{ {
XmlElement root = xmlDoc.DocumentElement; XmlElement root = xmlDoc.DocumentElement;
string configVersion = root.GetAttribute(XmlVersion); string configVersion = root.GetAttribute(XmlVersion);
if (configVersion == ConfigVersion) if (configVersion == ConfigVersion)
return true; return true;
return false; // v2.0.0 -> v2.1
} if (configVersion == "v2.0.0")
} {
// 读取包裹配置
var packageNodeList = root.GetElementsByTagName(XmlPackage);
foreach (var packageNode in packageNodeList)
{
XmlElement packageElement = packageNode as XmlElement;
if (packageElement.HasAttribute(XmlIgnoreRuleName) == false)
packageElement.SetAttribute(XmlIgnoreRuleName, nameof(NormalIgnoreRule));
}
// 更新版本
root.SetAttribute(XmlVersion, "v2.1");
return UpdateXmlConfig(xmlDoc);
}
return false;
}
}
} }

View File

@@ -7,115 +7,120 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
[Serializable] [Serializable]
public class AssetBundleCollectorGroup public class AssetBundleCollectorGroup
{ {
/// <summary> /// <summary>
/// 分组名称 /// 分组名称
/// </summary> /// </summary>
public string GroupName = string.Empty; public string GroupName = string.Empty;
/// <summary> /// <summary>
/// 分组描述 /// 分组描述
/// </summary> /// </summary>
public string GroupDesc = string.Empty; public string GroupDesc = string.Empty;
/// <summary> /// <summary>
/// 资源分类标签 /// 资源分类标签
/// </summary> /// </summary>
public string AssetTags = string.Empty; public string AssetTags = string.Empty;
/// <summary> /// <summary>
/// 分组激活规则 /// 分组激活规则
/// </summary> /// </summary>
public string ActiveRuleName = nameof(EnableGroup); public string ActiveRuleName = nameof(EnableGroup);
/// <summary> /// <summary>
/// 分组的收集器列表 /// 分组的收集器列表
/// </summary> /// </summary>
public List<AssetBundleCollector> Collectors = new List<AssetBundleCollector>(); public List<AssetBundleCollector> Collectors = new List<AssetBundleCollector>();
/// <summary> /// <summary>
/// 检测配置错误 /// 检测配置错误
/// </summary> /// </summary>
public void CheckConfigError() public void CheckConfigError()
{ {
if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false) if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false)
throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}"); throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}");
foreach (var collector in Collectors) // 检测分组是否激活
{ IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
collector.CheckConfigError(); if (activeRule.IsActiveGroup(new GroupData(GroupName)) == false)
} return;
}
/// <summary> foreach (var collector in Collectors)
/// 修复配置错误 {
/// </summary> collector.CheckConfigError();
public bool FixConfigError() }
{ }
bool isFixed = false;
foreach (var collector in Collectors)
{
if (collector.FixConfigError())
{
isFixed = true;
}
}
return isFixed;
}
/// <summary> /// <summary>
/// 获取打包收集的资源文件 /// 修复配置错误
/// </summary> /// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command) public bool FixConfigError()
{ {
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000); bool isFixed = false;
foreach (var collector in Collectors)
{
if (collector.FixConfigError())
{
isFixed = true;
}
}
return isFixed;
}
// 检测分组是否激活 /// <summary>
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName); /// 获取打包收集的资源文件
if (activeRule.IsActiveGroup() == false) /// </summary>
{ public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
return new List<CollectAssetInfo>(); {
} Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
// 收集打包资源 // 检测分组是否激活
foreach (var collector in Collectors) IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
{ if (activeRule.IsActiveGroup(new GroupData(GroupName)) == false)
var temper = collector.GetAllCollectAssets(command, this); {
foreach (var assetInfo in temper) return new List<CollectAssetInfo>();
{ }
if (result.ContainsKey(assetInfo.AssetPath) == false)
result.Add(assetInfo.AssetPath, assetInfo);
else
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group : {GroupName}");
}
}
// 检测可寻址地址是否重复 // 收集打包资源
if (command.EnableAddressable) foreach (var collector in Collectors)
{ {
var addressTemper = new Dictionary<string, string>(); var temper = collector.GetAllCollectAssets(command, this);
foreach (var collectInfoPair in result) foreach (var collectAsset in temper)
{ {
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector) if (result.ContainsKey(collectAsset.AssetInfo.AssetPath) == false)
{ result.Add(collectAsset.AssetInfo.AssetPath, collectAsset);
string address = collectInfoPair.Value.Address; else
string assetPath = collectInfoPair.Value.AssetPath; throw new Exception($"The collecting asset file is existed : {collectAsset.AssetInfo.AssetPath} in group : {GroupName}");
if (string.IsNullOrEmpty(address)) }
continue; }
if (addressTemper.TryGetValue(address, out var existed) == false) // 检测可寻址地址是否重复
addressTemper.Add(address, assetPath); if (command.EnableAddressable)
else {
throw new Exception($"The address is existed : {address} in group : {GroupName} \nAssetPath:\n {existed}\n {assetPath}"); var addressTemper = new Dictionary<string, string>();
} foreach (var collectAssetPair in result)
} {
} if (collectAssetPair.Value.CollectorType == ECollectorType.MainAssetCollector)
{
string address = collectAssetPair.Value.Address;
string assetPath = collectAssetPair.Value.AssetInfo.AssetPath;
if (string.IsNullOrEmpty(address))
continue;
// 返回列表 if (addressTemper.TryGetValue(address, out var existed) == false)
return result.Values.ToList(); addressTemper.Add(address, assetPath);
} else
} throw new Exception($"The address is existed : {address} in group : {GroupName} \nAssetPath:\n {existed}\n {assetPath}");
}
}
}
// 返回列表
return result.Values.ToList();
}
}
} }

View File

@@ -7,148 +7,167 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
[Serializable] [Serializable]
public class AssetBundleCollectorPackage public class AssetBundleCollectorPackage
{ {
/// <summary> /// <summary>
/// 包裹名称 /// 包裹名称
/// </summary> /// </summary>
public string PackageName = string.Empty; public string PackageName = string.Empty;
/// <summary> /// <summary>
/// 包裹描述 /// 包裹描述
/// </summary> /// </summary>
public string PackageDesc = string.Empty; public string PackageDesc = string.Empty;
/// <summary> /// <summary>
/// 启用可寻址资源定位 /// 启用可寻址资源定位
/// </summary> /// </summary>
public bool EnableAddressable = false; public bool EnableAddressable = false;
/// <summary> /// <summary>
/// 资源定位地址大小写不敏感 /// 资源定位地址大小写不敏感
/// </summary> /// </summary>
public bool LocationToLower = false; public bool LocationToLower = false;
/// <summary> /// <summary>
/// 包含资源GUID数据 /// 包含资源GUID数据
/// </summary> /// </summary>
public bool IncludeAssetGUID = false; public bool IncludeAssetGUID = false;
/// <summary> /// <summary>
/// 忽略Unity引擎无法识别的文件 /// 自动收集所有着色器(所有着色器存储在一个资源包内)
/// </summary> /// </summary>
public bool IgnoreDefaultType = true; public bool AutoCollectShaders = true;
/// <summary> /// <summary>
/// 自动收集所有着色器(所有着色器存储在一个资源包内) /// 资源忽略规则名
/// </summary> /// </summary>
public bool AutoCollectShaders = true; public string IgnoreRuleName = nameof(NormalIgnoreRule);
/// <summary> /// <summary>
/// 分组列表 /// 分组列表
/// </summary> /// </summary>
public List<AssetBundleCollectorGroup> Groups = new List<AssetBundleCollectorGroup>(); public List<AssetBundleCollectorGroup> Groups = new List<AssetBundleCollectorGroup>();
/// <summary> /// <summary>
/// 检测配置错误 /// 检测配置错误
/// </summary> /// </summary>
public void CheckConfigError() public void CheckConfigError()
{ {
foreach (var group in Groups) if (string.IsNullOrEmpty(IgnoreRuleName))
{ {
group.CheckConfigError(); throw new Exception($"{nameof(IgnoreRuleName)} is null or empty !");
} }
} else
{
if (AssetBundleCollectorSettingData.HasIgnoreRuleName(IgnoreRuleName) == false)
throw new Exception($"Invalid {nameof(IIgnoreRule)} class type : {IgnoreRuleName} in package : {PackageName}");
}
/// <summary> foreach (var group in Groups)
/// 修复配置错误 {
/// </summary> group.CheckConfigError();
public bool FixConfigError() }
{ }
bool isFixed = false;
foreach (var group in Groups)
{
if (group.FixConfigError())
{
isFixed = true;
}
}
return isFixed;
}
/// <summary> /// <summary>
/// 获取打包收集的资源文件 /// 修复配置错误
/// </summary> /// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command) public bool FixConfigError()
{ {
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000); bool isFixed = false;
// 收集打包资源 if (string.IsNullOrEmpty(IgnoreRuleName))
foreach (var group in Groups) {
{ Debug.LogWarning($"Set the {nameof(IgnoreRuleName)} to {nameof(NormalIgnoreRule)}");
var temper = group.GetAllCollectAssets(command); IgnoreRuleName = nameof(NormalIgnoreRule);
foreach (var assetInfo in temper) isFixed = true;
{ }
if (result.ContainsKey(assetInfo.AssetPath) == false)
result.Add(assetInfo.AssetPath, assetInfo);
else
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath}");
}
}
// 检测可寻址地址是否重复 foreach (var group in Groups)
if (command.EnableAddressable) {
{ if (group.FixConfigError())
var addressTemper = new Dictionary<string, string>(); {
foreach (var collectInfoPair in result) isFixed = true;
{ }
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector) }
{
string address = collectInfoPair.Value.Address;
string assetPath = collectInfoPair.Value.AssetPath;
if (string.IsNullOrEmpty(address))
continue;
if (addressTemper.TryGetValue(address, out var existed) == false) return isFixed;
addressTemper.Add(address, assetPath); }
else
throw new Exception($"The address is existed : {address} \nAssetPath:\n {existed}\n {assetPath}");
}
}
}
// 返回列表 /// <summary>
return result.Values.ToList(); /// 获取打包收集的资源文件
} /// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
{
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
/// <summary> // 收集打包资源
/// 获取所有的资源标签 foreach (var group in Groups)
/// </summary> {
public List<string> GetAllTags() var temper = group.GetAllCollectAssets(command);
{ foreach (var collectAsset in temper)
HashSet<string> result = new HashSet<string>(); {
foreach (var group in Groups) if (result.ContainsKey(collectAsset.AssetInfo.AssetPath) == false)
{ result.Add(collectAsset.AssetInfo.AssetPath, collectAsset);
List<string> groupTags = EditorTools.StringToStringList(group.AssetTags, ';'); else
foreach (var tag in groupTags) throw new Exception($"The collecting asset file is existed : {collectAsset.AssetInfo.AssetPath}");
{ }
if (result.Contains(tag) == false) }
result.Add(tag);
}
foreach (var collector in group.Collectors) // 检测可寻址地址是否重复
{ if (command.EnableAddressable)
List<string> collectorTags = EditorTools.StringToStringList(collector.AssetTags, ';'); {
foreach (var tag in collectorTags) var addressTemper = new Dictionary<string, string>();
{ foreach (var collectInfoPair in result)
if (result.Contains(tag) == false) {
result.Add(tag); if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
} {
} string address = collectInfoPair.Value.Address;
} string assetPath = collectInfoPair.Value.AssetInfo.AssetPath;
return result.ToList(); if (string.IsNullOrEmpty(address))
} continue;
}
if (addressTemper.TryGetValue(address, out var existed) == false)
addressTemper.Add(address, assetPath);
else
throw new Exception($"The address is existed : {address} \nAssetPath:\n {existed}\n {assetPath}");
}
}
}
// 返回列表
return result.Values.ToList();
}
/// <summary>
/// 获取所有的资源标签
/// </summary>
public List<string> GetAllTags()
{
HashSet<string> result = new HashSet<string>();
foreach (var group in Groups)
{
List<string> groupTags = EditorTools.StringToStringList(group.AssetTags, ';');
foreach (var tag in groupTags)
{
if (result.Contains(tag) == false)
result.Add(tag);
}
foreach (var collector in group.Collectors)
{
List<string> collectorTags = EditorTools.StringToStringList(collector.AssetTags, ';');
foreach (var tag in collectorTags)
{
if (result.Contains(tag) == false)
result.Add(tag);
}
}
}
return result.ToList();
}
}
} }

View File

@@ -6,125 +6,124 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
[CreateAssetMenu(fileName = "AssetBundleCollectorSetting", menuName = "YooAsset/Create AssetBundle Collector Settings")] [CreateAssetMenu(fileName = "AssetBundleCollectorSetting", menuName = "YooAsset/Create AssetBundle Collector Settings")]
public class AssetBundleCollectorSetting : ScriptableObject public class AssetBundleCollectorSetting : ScriptableObject
{ {
/// <summary> /// <summary>
/// 显示包裹列表视图 /// 显示包裹列表视图
/// </summary> /// </summary>
public bool ShowPackageView = false; public bool ShowPackageView = false;
/// <summary> /// <summary>
/// 是否显示编辑器别名 /// 是否显示编辑器别名
/// </summary> /// </summary>
public bool ShowEditorAlias = false; public bool ShowEditorAlias = false;
/// <summary> /// <summary>
/// 资源包名唯一化 /// 资源包名唯一化
/// </summary> /// </summary>
public bool UniqueBundleName = false; public bool UniqueBundleName = false;
/// <summary>
/// 包裹列表
/// </summary>
public List<AssetBundleCollectorPackage> Packages = new List<AssetBundleCollectorPackage>();
/// <summary> /// <summary>
/// 包裹列表 /// 清空所有数据
/// </summary> /// </summary>
public List<AssetBundleCollectorPackage> Packages = new List<AssetBundleCollectorPackage>(); public void ClearAll()
{
ShowPackageView = false;
UniqueBundleName = false;
ShowEditorAlias = false;
Packages.Clear();
}
/// <summary>
/// 检测包裹配置错误
/// </summary>
public void CheckPackageConfigError(string packageName)
{
var package = GetPackage(packageName);
package.CheckConfigError();
}
/// <summary> /// <summary>
/// 清空所有数据 /// 检测所有配置错误
/// </summary> /// </summary>
public void ClearAll() public void CheckAllPackageConfigError()
{ {
ShowPackageView = false; foreach (var package in Packages)
UniqueBundleName = false; {
ShowEditorAlias = false; package.CheckConfigError();
Packages.Clear(); }
} }
/// <summary> /// <summary>
/// 检测包裹配置错误 /// 修复所有配置错误
/// </summary> /// </summary>
public void CheckPackageConfigError(string packageName) public bool FixAllPackageConfigError()
{ {
var package = GetPackage(packageName); bool isFixed = false;
package.CheckConfigError(); foreach (var package in Packages)
} {
if (package.FixConfigError())
{
isFixed = true;
}
}
return isFixed;
}
/// <summary> /// <summary>
/// 检测所有配置错误 /// 获取所有的资源标签
/// </summary> /// </summary>
public void CheckAllPackageConfigError() public List<string> GetPackageAllTags(string packageName)
{ {
foreach (var package in Packages) var package = GetPackage(packageName);
{ return package.GetAllTags();
package.CheckConfigError(); }
}
}
/// <summary> /// <summary>
/// 修复所有配置错误 /// 获取包裹收集的资源文件
/// </summary> /// </summary>
public bool FixAllPackageConfigError() public CollectResult GetPackageAssets(bool simulateBuild, bool useAssetDependencyDB, string packageName)
{ {
bool isFixed = false; if (string.IsNullOrEmpty(packageName))
foreach (var package in Packages) throw new Exception("Build package name is null or empty !");
{
if (package.FixConfigError())
{
isFixed = true;
}
}
return isFixed;
}
/// <summary> // 检测配置合法性
/// 获取所有的资源标签 var package = GetPackage(packageName);
/// </summary> package.CheckConfigError();
public List<string> GetPackageAllTags(string packageName)
{
var package = GetPackage(packageName);
return package.GetAllTags();
}
/// <summary> // 创建资源收集命令
/// 获取包裹收集的资源文件 IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(package.IgnoreRuleName);
/// </summary> CollectCommand command = new CollectCommand(simulateBuild, useAssetDependencyDB, packageName,
public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName) package.EnableAddressable,
{ package.LocationToLower,
if (string.IsNullOrEmpty(packageName)) package.IncludeAssetGUID,
throw new Exception("Build package name is null or empty !"); package.AutoCollectShaders,
UniqueBundleName, ignoreRule);
// 检测配置合法性 // 获取收集的资源集合
var package = GetPackage(packageName); CollectResult collectResult = new CollectResult(command);
package.CheckConfigError(); collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
return collectResult;
}
// 创建资源收集命令 /// <summary>
CollectCommand command = new CollectCommand(buildMode, packageName, /// 获取包裹类
package.EnableAddressable, /// </summary>
package.LocationToLower, public AssetBundleCollectorPackage GetPackage(string packageName)
package.IncludeAssetGUID, {
package.IgnoreDefaultType, foreach (var package in Packages)
package.AutoCollectShaders, {
UniqueBundleName); if (package.PackageName == packageName)
return package;
// 获取收集的资源集合 }
CollectResult collectResult = new CollectResult(command); throw new Exception($"Not found package : {packageName}");
collectResult.SetCollectAssets(package.GetAllCollectAssets(command)); }
return collectResult; }
}
/// <summary>
/// 获取包裹类
/// </summary>
public AssetBundleCollectorPackage GetPackage(string packageName)
{
foreach (var package in Packages)
{
if (package.PackageName == packageName)
return package;
}
throw new Exception($"Not found package : {packageName}");
}
}
} }

View File

@@ -7,424 +7,484 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleCollectorSettingData public class AssetBundleCollectorSettingData
{ {
private static readonly Dictionary<string, System.Type> _cacheActiveRuleTypes = new Dictionary<string, Type>(); private static readonly Dictionary<string, System.Type> _cacheActiveRuleTypes = new Dictionary<string, Type>();
private static readonly Dictionary<string, IActiveRule> _cacheActiveRuleInstance = new Dictionary<string, IActiveRule>(); private static readonly Dictionary<string, IActiveRule> _cacheActiveRuleInstance = new Dictionary<string, IActiveRule>();
private static readonly Dictionary<string, System.Type> _cacheAddressRuleTypes = new Dictionary<string, System.Type>(); private static readonly Dictionary<string, System.Type> _cacheAddressRuleTypes = new Dictionary<string, System.Type>();
private static readonly Dictionary<string, IAddressRule> _cacheAddressRuleInstance = new Dictionary<string, IAddressRule>(); private static readonly Dictionary<string, IAddressRule> _cacheAddressRuleInstance = new Dictionary<string, IAddressRule>();
private static readonly Dictionary<string, System.Type> _cachePackRuleTypes = new Dictionary<string, System.Type>(); private static readonly Dictionary<string, System.Type> _cachePackRuleTypes = new Dictionary<string, System.Type>();
private static readonly Dictionary<string, IPackRule> _cachePackRuleInstance = new Dictionary<string, IPackRule>(); private static readonly Dictionary<string, IPackRule> _cachePackRuleInstance = new Dictionary<string, IPackRule>();
private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>(); private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>();
private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>(); private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>();
/// <summary> private static readonly Dictionary<string, System.Type> _cacheIgnoreRuleTypes = new Dictionary<string, System.Type>();
/// 配置数据是否被修改 private static readonly Dictionary<string, IIgnoreRule> _cacheIgnoreRuleInstance = new Dictionary<string, IIgnoreRule>();
/// </summary>
public static bool IsDirty { private set; get; } = false; /// <summary>
/// 配置数据是否被修改
/// </summary>
public static bool IsDirty { private set; get; } = false;
static AssetBundleCollectorSettingData() static AssetBundleCollectorSettingData()
{ {
// IPackRule // IPackRule
{ {
// 清空缓存集合 // 清空缓存集合
_cachePackRuleTypes.Clear(); _cachePackRuleTypes.Clear();
_cachePackRuleInstance.Clear(); _cachePackRuleInstance.Clear();
// 获取所有类型 // 获取所有类型
List<Type> types = new List<Type>(100) List<Type> types = new List<Type>(100)
{ {
typeof(PackSeparately), typeof(PackSeparately),
typeof(PackDirectory), typeof(PackDirectory),
typeof(PackTopDirectory), typeof(PackTopDirectory),
typeof(PackCollector), typeof(PackCollector),
typeof(PackGroup), typeof(PackGroup),
typeof(PackRawFile), typeof(PackRawFile),
typeof(PackShaderVariants) typeof(PackShaderVariants)
}; };
var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule)); var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule));
types.AddRange(customTypes); types.AddRange(customTypes);
for (int i = 0; i < types.Count; i++) for (int i = 0; i < types.Count; i++)
{ {
Type type = types[i]; Type type = types[i];
if (_cachePackRuleTypes.ContainsKey(type.Name) == false) if (_cachePackRuleTypes.ContainsKey(type.Name) == false)
_cachePackRuleTypes.Add(type.Name, type); _cachePackRuleTypes.Add(type.Name, type);
} }
} }
// IFilterRule // IFilterRule
{ {
// 清空缓存集合 // 清空缓存集合
_cacheFilterRuleTypes.Clear(); _cacheFilterRuleTypes.Clear();
_cacheFilterRuleInstance.Clear(); _cacheFilterRuleInstance.Clear();
// 获取所有类型 // 获取所有类型
List<Type> types = new List<Type>(100) List<Type> types = new List<Type>(100)
{ {
typeof(CollectAll), typeof(CollectAll),
typeof(CollectScene), typeof(CollectScene),
typeof(CollectPrefab), typeof(CollectPrefab),
typeof(CollectSprite) typeof(CollectSprite)
}; };
var customTypes = EditorTools.GetAssignableTypes(typeof(IFilterRule)); var customTypes = EditorTools.GetAssignableTypes(typeof(IFilterRule));
types.AddRange(customTypes); types.AddRange(customTypes);
for (int i = 0; i < types.Count; i++) for (int i = 0; i < types.Count; i++)
{ {
Type type = types[i]; Type type = types[i];
if (_cacheFilterRuleTypes.ContainsKey(type.Name) == false) if (_cacheFilterRuleTypes.ContainsKey(type.Name) == false)
_cacheFilterRuleTypes.Add(type.Name, type); _cacheFilterRuleTypes.Add(type.Name, type);
} }
} }
// IAddressRule // IAddressRule
{ {
// 清空缓存集合 // 清空缓存集合
_cacheAddressRuleTypes.Clear(); _cacheAddressRuleTypes.Clear();
_cacheAddressRuleInstance.Clear(); _cacheAddressRuleInstance.Clear();
// 获取所有类型 // 获取所有类型
List<Type> types = new List<Type>(100) List<Type> types = new List<Type>(100)
{ {
typeof(AddressByFileName), typeof(AddressByFileName),
typeof(AddressByFolderAndFileName), typeof(AddressByFolderAndFileName),
typeof(AddressByGroupAndFileName), typeof(AddressByGroupAndFileName),
typeof(AddressDisable) typeof(AddressDisable)
}; };
var customTypes = EditorTools.GetAssignableTypes(typeof(IAddressRule)); var customTypes = EditorTools.GetAssignableTypes(typeof(IAddressRule));
types.AddRange(customTypes); types.AddRange(customTypes);
for (int i = 0; i < types.Count; i++) for (int i = 0; i < types.Count; i++)
{ {
Type type = types[i]; Type type = types[i];
if (_cacheAddressRuleTypes.ContainsKey(type.Name) == false) if (_cacheAddressRuleTypes.ContainsKey(type.Name) == false)
_cacheAddressRuleTypes.Add(type.Name, type); _cacheAddressRuleTypes.Add(type.Name, type);
} }
} }
// IActiveRule // IActiveRule
{ {
// 清空缓存集合 // 清空缓存集合
_cacheActiveRuleTypes.Clear(); _cacheActiveRuleTypes.Clear();
_cacheActiveRuleInstance.Clear(); _cacheActiveRuleInstance.Clear();
// 获取所有类型 // 获取所有类型
List<Type> types = new List<Type>(100) List<Type> types = new List<Type>(100)
{ {
typeof(EnableGroup), typeof(EnableGroup),
typeof(DisableGroup), typeof(DisableGroup),
}; };
var customTypes = EditorTools.GetAssignableTypes(typeof(IActiveRule)); var customTypes = EditorTools.GetAssignableTypes(typeof(IActiveRule));
types.AddRange(customTypes); types.AddRange(customTypes);
for (int i = 0; i < types.Count; i++) for (int i = 0; i < types.Count; i++)
{ {
Type type = types[i]; Type type = types[i];
if (_cacheActiveRuleTypes.ContainsKey(type.Name) == false) if (_cacheActiveRuleTypes.ContainsKey(type.Name) == false)
_cacheActiveRuleTypes.Add(type.Name, type); _cacheActiveRuleTypes.Add(type.Name, type);
} }
} }
}
private static AssetBundleCollectorSetting _setting = null; // IIgnoreRule
public static AssetBundleCollectorSetting Setting {
{ // 清空缓存集合
get _cacheIgnoreRuleTypes.Clear();
{ _cacheIgnoreRuleInstance.Clear();
if (_setting == null)
_setting = SettingLoader.LoadSettingData<AssetBundleCollectorSetting>();
return _setting;
}
}
/// <summary> // 获取所有类型
/// 存储配置文件 List<Type> types = new List<Type>(100)
/// </summary> {
public static void SaveFile() typeof(NormalIgnoreRule),
{ typeof(RawFileIgnoreRule),
if (Setting != null) };
{
IsDirty = false;
EditorUtility.SetDirty(Setting);
AssetDatabase.SaveAssets();
Debug.Log($"{nameof(AssetBundleCollectorSetting)}.asset is saved!");
}
}
/// <summary> var customTypes = EditorTools.GetAssignableTypes(typeof(IIgnoreRule));
/// 修复配置文件 types.AddRange(customTypes);
/// </summary> for (int i = 0; i < types.Count; i++)
public static void FixFile() {
{ Type type = types[i];
bool isFixed = Setting.FixAllPackageConfigError(); if (_cacheIgnoreRuleTypes.ContainsKey(type.Name) == false)
if (isFixed) _cacheIgnoreRuleTypes.Add(type.Name, type);
{ }
IsDirty = true; }
} }
}
/// <summary> private static AssetBundleCollectorSetting _setting = null;
/// 清空所有数据 public static AssetBundleCollectorSetting Setting
/// </summary> {
public static void ClearAll() get
{ {
Setting.ClearAll(); if (_setting == null)
SaveFile(); _setting = SettingLoader.LoadSettingData<AssetBundleCollectorSetting>();
} return _setting;
}
}
public static List<RuleDisplayName> GetActiveRuleNames() /// <summary>
{ /// 存储配置文件
List<RuleDisplayName> names = new List<RuleDisplayName>(); /// </summary>
foreach (var pair in _cacheActiveRuleTypes) public static void SaveFile()
{ {
RuleDisplayName ruleName = new RuleDisplayName(); if (Setting != null)
ruleName.ClassName = pair.Key; {
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value); IsDirty = false;
names.Add(ruleName); EditorUtility.SetDirty(Setting);
} AssetDatabase.SaveAssets();
return names; Debug.Log($"{nameof(AssetBundleCollectorSetting)}.asset is saved!");
} }
public static List<RuleDisplayName> GetAddressRuleNames() }
{
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheAddressRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
public static List<RuleDisplayName> GetPackRuleNames()
{
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cachePackRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
public static List<RuleDisplayName> GetFilterRuleNames()
{
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheFilterRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
private static string GetRuleDisplayName(string name, Type type)
{
var attribute = DisplayNameAttributeHelper.GetAttribute<DisplayNameAttribute>(type);
if (attribute != null && string.IsNullOrEmpty(attribute.DisplayName) == false)
return attribute.DisplayName;
else
return name;
}
public static bool HasActiveRuleName(string ruleName) /// <summary>
{ /// 修复配置文件
return _cacheActiveRuleTypes.Keys.Contains(ruleName); /// </summary>
} public static void FixFile()
public static bool HasAddressRuleName(string ruleName) {
{ bool isFixed = Setting.FixAllPackageConfigError();
return _cacheAddressRuleTypes.Keys.Contains(ruleName); if (isFixed)
} {
public static bool HasPackRuleName(string ruleName) IsDirty = true;
{ Debug.Log("Fix package config error done !");
return _cachePackRuleTypes.Keys.Contains(ruleName); }
} }
public static bool HasFilterRuleName(string ruleName)
{
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
}
public static IActiveRule GetActiveRuleInstance(string ruleName) /// <summary>
{ /// 清空所有数据
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance)) /// </summary>
return instance; public static void ClearAll()
{
Setting.ClearAll();
SaveFile();
}
// 如果不存在创建类的实例 public static List<RuleDisplayName> GetActiveRuleNames()
if (_cacheActiveRuleTypes.TryGetValue(ruleName, out Type type)) {
{ List<RuleDisplayName> names = new List<RuleDisplayName>();
instance = (IActiveRule)Activator.CreateInstance(type); foreach (var pair in _cacheActiveRuleTypes)
_cacheActiveRuleInstance.Add(ruleName, instance); {
return instance; RuleDisplayName ruleName = new RuleDisplayName();
} ruleName.ClassName = pair.Key;
else ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
{ names.Add(ruleName);
throw new Exception($"{nameof(IActiveRule)} is invalid{ruleName}"); }
} return names;
} }
public static IAddressRule GetAddressRuleInstance(string ruleName) public static List<RuleDisplayName> GetAddressRuleNames()
{ {
if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance)) List<RuleDisplayName> names = new List<RuleDisplayName>();
return instance; foreach (var pair in _cacheAddressRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
public static List<RuleDisplayName> GetPackRuleNames()
{
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cachePackRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
public static List<RuleDisplayName> GetFilterRuleNames()
{
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheFilterRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
public static List<RuleDisplayName> GetIgnoreRuleNames()
{
List<RuleDisplayName> names = new List<RuleDisplayName>();
foreach (var pair in _cacheIgnoreRuleTypes)
{
RuleDisplayName ruleName = new RuleDisplayName();
ruleName.ClassName = pair.Key;
ruleName.DisplayName = GetRuleDisplayName(pair.Key, pair.Value);
names.Add(ruleName);
}
return names;
}
private static string GetRuleDisplayName(string name, Type type)
{
var attribute = DisplayNameAttributeHelper.GetAttribute<DisplayNameAttribute>(type);
if (attribute != null && string.IsNullOrEmpty(attribute.DisplayName) == false)
return attribute.DisplayName;
else
return name;
}
// 如果不存在创建类的实例 public static bool HasActiveRuleName(string ruleName)
if (_cacheAddressRuleTypes.TryGetValue(ruleName, out Type type)) {
{ return _cacheActiveRuleTypes.ContainsKey(ruleName);
instance = (IAddressRule)Activator.CreateInstance(type); }
_cacheAddressRuleInstance.Add(ruleName, instance); public static bool HasAddressRuleName(string ruleName)
return instance; {
} return _cacheAddressRuleTypes.ContainsKey(ruleName);
else }
{ public static bool HasPackRuleName(string ruleName)
throw new Exception($"{nameof(IAddressRule)} is invalid{ruleName}"); {
} return _cachePackRuleTypes.ContainsKey(ruleName);
} }
public static IPackRule GetPackRuleInstance(string ruleName) public static bool HasFilterRuleName(string ruleName)
{ {
if (_cachePackRuleInstance.TryGetValue(ruleName, out IPackRule instance)) return _cacheFilterRuleTypes.ContainsKey(ruleName);
return instance; }
public static bool HasIgnoreRuleName(string ruleName)
{
return _cacheIgnoreRuleTypes.ContainsKey(ruleName);
}
// 如果不存在创建类的实例 public static IActiveRule GetActiveRuleInstance(string ruleName)
if (_cachePackRuleTypes.TryGetValue(ruleName, out Type type)) {
{ if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
instance = (IPackRule)Activator.CreateInstance(type); return instance;
_cachePackRuleInstance.Add(ruleName, instance);
return instance;
}
else
{
throw new Exception($"{nameof(IPackRule)} is invalid{ruleName}");
}
}
public static IFilterRule GetFilterRuleInstance(string ruleName)
{
if (_cacheFilterRuleInstance.TryGetValue(ruleName, out IFilterRule instance))
return instance;
// 如果不存在创建类的实例 // 如果不存在创建类的实例
if (_cacheFilterRuleTypes.TryGetValue(ruleName, out Type type)) if (_cacheActiveRuleTypes.TryGetValue(ruleName, out Type type))
{ {
instance = (IFilterRule)Activator.CreateInstance(type); instance = (IActiveRule)Activator.CreateInstance(type);
_cacheFilterRuleInstance.Add(ruleName, instance); _cacheActiveRuleInstance.Add(ruleName, instance);
return instance; return instance;
} }
else else
{ {
throw new Exception($"{nameof(IFilterRule)} is invalid{ruleName}"); throw new Exception($"{nameof(IActiveRule)} is invalid{ruleName}");
} }
} }
public static IAddressRule GetAddressRuleInstance(string ruleName)
{
if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance))
return instance;
// 公共参数编辑相关 // 如果不存在创建类的实例
public static void ModifyShowPackageView(bool showPackageView) if (_cacheAddressRuleTypes.TryGetValue(ruleName, out Type type))
{ {
Setting.ShowPackageView = showPackageView; instance = (IAddressRule)Activator.CreateInstance(type);
IsDirty = true; _cacheAddressRuleInstance.Add(ruleName, instance);
} return instance;
public static void ModifyShowEditorAlias(bool showAlias) }
{ else
Setting.ShowEditorAlias = showAlias; {
IsDirty = true; throw new Exception($"{nameof(IAddressRule)} is invalid{ruleName}");
} }
public static void ModifyUniqueBundleName(bool uniqueBundleName) }
{ public static IPackRule GetPackRuleInstance(string ruleName)
Setting.UniqueBundleName = uniqueBundleName; {
IsDirty = true; if (_cachePackRuleInstance.TryGetValue(ruleName, out IPackRule instance))
} return instance;
// 资源包裹编辑相关 // 如果不存在创建类的实例
public static AssetBundleCollectorPackage CreatePackage(string packageName) if (_cachePackRuleTypes.TryGetValue(ruleName, out Type type))
{ {
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage(); instance = (IPackRule)Activator.CreateInstance(type);
package.PackageName = packageName; _cachePackRuleInstance.Add(ruleName, instance);
Setting.Packages.Add(package); return instance;
IsDirty = true; }
return package; else
} {
public static void RemovePackage(AssetBundleCollectorPackage package) throw new Exception($"{nameof(IPackRule)} is invalid{ruleName}");
{ }
if (Setting.Packages.Remove(package)) }
{ public static IFilterRule GetFilterRuleInstance(string ruleName)
IsDirty = true; {
} if (_cacheFilterRuleInstance.TryGetValue(ruleName, out IFilterRule instance))
else return instance;
{
Debug.LogWarning($"Failed remove package : {package.PackageName}");
}
}
public static void ModifyPackage(AssetBundleCollectorPackage package)
{
if (package != null)
{
IsDirty = true;
}
}
// 资源分组编辑相关 // 如果不存在创建类的实例
public static AssetBundleCollectorGroup CreateGroup(AssetBundleCollectorPackage package, string groupName) if (_cacheFilterRuleTypes.TryGetValue(ruleName, out Type type))
{ {
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup(); instance = (IFilterRule)Activator.CreateInstance(type);
group.GroupName = groupName; _cacheFilterRuleInstance.Add(ruleName, instance);
package.Groups.Add(group); return instance;
IsDirty = true; }
return group; else
} {
public static void RemoveGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group) throw new Exception($"{nameof(IFilterRule)} is invalid{ruleName}");
{ }
if (package.Groups.Remove(group)) }
{ public static IIgnoreRule GetIgnoreRuleInstance(string ruleName)
IsDirty = true; {
} if (_cacheIgnoreRuleInstance.TryGetValue(ruleName, out IIgnoreRule instance))
else return instance;
{
Debug.LogWarning($"Failed remove group : {group.GroupName}");
}
}
public static void ModifyGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group)
{
if (package != null && group != null)
{
IsDirty = true;
}
}
// 资源收集器编辑相关 // 如果不存在创建类的实例
public static void CreateCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector) if (_cacheIgnoreRuleTypes.TryGetValue(ruleName, out Type type))
{ {
group.Collectors.Add(collector); instance = (IIgnoreRule)Activator.CreateInstance(type);
IsDirty = true; _cacheIgnoreRuleInstance.Add(ruleName, instance);
} return instance;
public static void RemoveCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector) }
{ else
if (group.Collectors.Remove(collector)) {
{ throw new Exception($"{nameof(IIgnoreRule)} is invalid{ruleName}");
IsDirty = true; }
} }
else
{
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
}
}
public static void ModifyCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
{
if (group != null && collector != null)
{
IsDirty = true;
}
}
/// <summary> // 公共参数编辑相关
/// 获取所有的资源标签 public static void ModifyShowPackageView(bool showPackageView)
/// </summary> {
public static string GetPackageAllTags(string packageName) Setting.ShowPackageView = showPackageView;
{ IsDirty = true;
var allTags = Setting.GetPackageAllTags(packageName); }
return string.Join(";", allTags); public static void ModifyShowEditorAlias(bool showAlias)
} {
} Setting.ShowEditorAlias = showAlias;
IsDirty = true;
}
public static void ModifyUniqueBundleName(bool uniqueBundleName)
{
Setting.UniqueBundleName = uniqueBundleName;
IsDirty = true;
}
// 资源包裹编辑相关
public static AssetBundleCollectorPackage CreatePackage(string packageName)
{
AssetBundleCollectorPackage package = new AssetBundleCollectorPackage();
package.PackageName = packageName;
Setting.Packages.Add(package);
IsDirty = true;
return package;
}
public static void RemovePackage(AssetBundleCollectorPackage package)
{
if (Setting.Packages.Remove(package))
{
IsDirty = true;
}
else
{
Debug.LogWarning($"Failed remove package : {package.PackageName}");
}
}
public static void ModifyPackage(AssetBundleCollectorPackage package)
{
if (package != null)
{
IsDirty = true;
}
}
// 资源分组编辑相关
public static AssetBundleCollectorGroup CreateGroup(AssetBundleCollectorPackage package, string groupName)
{
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
group.GroupName = groupName;
package.Groups.Add(group);
IsDirty = true;
return group;
}
public static void RemoveGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group)
{
if (package.Groups.Remove(group))
{
IsDirty = true;
}
else
{
Debug.LogWarning($"Failed remove group : {group.GroupName}");
}
}
public static void ModifyGroup(AssetBundleCollectorPackage package, AssetBundleCollectorGroup group)
{
if (package != null && group != null)
{
IsDirty = true;
}
}
// 资源收集器编辑相关
public static void CreateCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
{
group.Collectors.Add(collector);
IsDirty = true;
}
public static void RemoveCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
{
if (group.Collectors.Remove(collector))
{
IsDirty = true;
}
else
{
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
}
}
public static void ModifyCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
{
if (group != null && collector != null)
{
IsDirty = true;
}
}
/// <summary>
/// 获取所有的资源标签
/// </summary>
public static string GetPackageAllTags(string packageName)
{
var allTags = Setting.GetPackageAllTags(packageName);
return string.Join(";", allTags);
}
}
} }

View File

@@ -21,7 +21,6 @@
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" /> <ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Location To Lower" name="LocationToLower" style="width: 196px; -unity-text-align: middle-left;" /> <ui:Toggle label="Location To Lower" name="LocationToLower" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Include Asset GUID" name="IncludeAssetGUID" style="width: 196px; -unity-text-align: middle-left;" /> <ui:Toggle label="Include Asset GUID" name="IncludeAssetGUID" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Ignore Default Type" name="IgnoreDefaultType" style="width: 196px; -unity-text-align: middle-left;" />
<ui:Toggle label="Auto Collect Shaders" name="AutoCollectShaders" value="true" style="width: 196px; -unity-text-align: middle-left;" /> <ui:Toggle label="Auto Collect Shaders" name="AutoCollectShaders" value="true" style="width: 196px; -unity-text-align: middle-left;" />
</ui:VisualElement> </ui:VisualElement>
</ui:VisualElement> </ui:VisualElement>

View File

@@ -0,0 +1,271 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
public class AssetDependencyCache
{
/// <summary>
/// 资源依赖缓存数据库
/// </summary>
private class CacheDatabase
{
private class CacheInfo
{
/// <summary>
/// 此哈希函数会聚合了以下内容:源资源路径、源资源、元文件、目标平台以及导入器版本。
/// 如果此哈希值发送变化,则说明导入资源可能已更改,因此应重新搜集依赖关系。
/// </summary>
public string DependHash;
/// <summary>
/// 直接依赖资源的GUID列表
/// </summary>
public List<string> DependGUIDs = new List<string>();
}
private string _databaseFilePath;
private readonly Dictionary<string, CacheInfo> _database = new Dictionary<string, CacheInfo>(100000);
/// <summary>
/// 创建数据库
/// </summary>
public void CreateDatabase(string databaseFilePath, bool useCacheDatabase)
{
_databaseFilePath = databaseFilePath;
_database.Clear();
try
{
if (useCacheDatabase && File.Exists(databaseFilePath))
{
// 解析缓存文件
using var stream = File.OpenRead(databaseFilePath);
using var reader = new BinaryReader(stream);
var count = reader.ReadInt32();
for (int i = 0; i < count; i++)
{
var assetPath = reader.ReadString();
var cacheInfo = new CacheInfo
{
DependHash = reader.ReadString(),
DependGUIDs = ReadStringList(reader),
};
_database.Add(assetPath, cacheInfo);
}
// 移除无效资源
List<string> removeList = new List<string>(10000);
foreach (var cacheInfoPair in _database)
{
var assetPath = cacheInfoPair.Key;
var assetGUID = AssetDatabase.AssetPathToGUID(assetPath);
if (string.IsNullOrEmpty(assetGUID))
{
removeList.Add(assetPath);
}
}
foreach (var assetPath in removeList)
{
_database.Remove(assetPath);
}
}
}
catch (Exception ex)
{
ClearCache(true);
Debug.LogError($"Failed to load cache database : {ex.Message}");
}
// 查找新增或变动资源
var allAssetPaths = AssetDatabase.GetAllAssetPaths();
foreach (var assetPath in allAssetPaths)
{
if (_database.TryGetValue(assetPath, out CacheInfo cacheInfo))
{
var dependHash = AssetDatabase.GetAssetDependencyHash(assetPath);
if (dependHash.ToString() != cacheInfo.DependHash)
{
_database[assetPath] = CreateCacheInfo(assetPath);
}
}
else
{
var newCacheInfo = CreateCacheInfo(assetPath);
_database.Add(assetPath, newCacheInfo);
}
}
}
/// <summary>
/// 保存缓存文件
/// </summary>
public void SaveCacheFile()
{
if (File.Exists(_databaseFilePath))
File.Delete(_databaseFilePath);
try
{
using var stream = File.Create(_databaseFilePath);
using var writer = new BinaryWriter(stream);
writer.Write(_database.Count);
foreach (var assetPair in _database)
{
string assetPath = assetPair.Key;
var assetInfo = assetPair.Value;
writer.Write(assetPath);
writer.Write(assetInfo.DependHash);
WriteStringList(writer, assetInfo.DependGUIDs);
}
writer.Flush();
}
catch (Exception ex)
{
Debug.LogError($"Failed to save cache database : {ex.Message}");
}
}
/// <summary>
/// 清理缓存数据
/// </summary>
public void ClearCache(bool clearDatabaseFile)
{
if (clearDatabaseFile)
{
if (File.Exists(_databaseFilePath))
File.Delete(_databaseFilePath);
}
_database.Clear();
}
/// <summary>
/// 获取资源的依赖列表
/// </summary>
public string[] GetDependencies(string assetPath, bool recursive)
{
// 注意AssetDatabase.GetDependencies()方法返回结果里会踢出丢失文件!
// 注意AssetDatabase.GetDependencies()方法返回结果里会包含主资源路径!
// 注意:机制上不允许存在未收录的资源
if (_database.ContainsKey(assetPath) == false)
{
throw new Exception($"Fatal : can not found cache info : {assetPath}");
}
var result = new HashSet<string> { assetPath };
CollectDependencies(assetPath, result, recursive);
// 注意AssetDatabase.GetDependencies保持一致将主资源添加到依赖列表最前面
return result.ToArray();
}
private void CollectDependencies(string assetPath, HashSet<string> result, bool recursive)
{
if (_database.TryGetValue(assetPath, out var cacheInfo) == false)
{
throw new Exception($"Fatal : can not found cache info : {assetPath}");
}
foreach (var dependGUID in cacheInfo.DependGUIDs)
{
string dependAssetPath = AssetDatabase.GUIDToAssetPath(dependGUID);
if (string.IsNullOrEmpty(dependAssetPath))
continue;
// 如果是文件夹资源
if (AssetDatabase.IsValidFolder(dependAssetPath))
continue;
// 如果已经收集过
if (result.Contains(dependAssetPath))
continue;
result.Add(dependAssetPath);
// 递归收集依赖
if (recursive)
CollectDependencies(dependAssetPath, result, recursive);
}
}
private List<string> ReadStringList(BinaryReader reader)
{
var count = reader.ReadInt32();
var values = new List<string>(count);
for (int i = 0; i < count; i++)
{
values.Add(reader.ReadString());
}
return values;
}
private void WriteStringList(BinaryWriter writer, List<string> values)
{
writer.Write(values.Count);
foreach (var value in values)
{
writer.Write(value);
}
}
private CacheInfo CreateCacheInfo(string assetPath)
{
var dependHash = AssetDatabase.GetAssetDependencyHash(assetPath);
var dependAssetPaths = AssetDatabase.GetDependencies(assetPath, false);
var dependGUIDs = new List<string>();
foreach (var dependAssetPath in dependAssetPaths)
{
string guid = AssetDatabase.AssetPathToGUID(dependAssetPath);
if (string.IsNullOrEmpty(guid) == false)
{
dependGUIDs.Add(guid);
}
}
var cacheInfo = new CacheInfo();
cacheInfo.DependHash = dependHash.ToString();
cacheInfo.DependGUIDs = dependGUIDs;
return cacheInfo;
}
}
private readonly CacheDatabase _database;
/// <summary>
/// 初始化资源依赖缓存系统
/// </summary>
public AssetDependencyCache(bool useCacheDatabase)
{
if (useCacheDatabase)
Debug.Log("Use asset dependency database !");
string databaseFilePath = "Library/AssetDependencyDB";
_database = new CacheDatabase();
_database.CreateDatabase(databaseFilePath, useCacheDatabase);
if (useCacheDatabase)
{
_database.SaveCacheFile();
}
}
/// <summary>
/// 获取资源的依赖列表
/// </summary>
/// <param name="assetPath">资源路径</param>
/// <param name="recursive">递归查找所有依赖</param>
/// <returns>返回依赖的资源路径集合</returns>
public string[] GetDependencies(string assetPath, bool recursive = true)
{
// 通过本地缓存获取依赖关系
return _database.GetDependencies(assetPath, recursive);
// 通过Unity引擎获取依赖关系
//return AssetDatabase.GetDependencies(assetPath, recursive);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ddc7e04182c802b468e038777e4dd442
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -3,46 +3,46 @@ using System.Collections.Generic;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class CollectAssetInfo public class CollectAssetInfo
{ {
/// <summary> /// <summary>
/// 收集器类型 /// 收集器类型
/// </summary> /// </summary>
public ECollectorType CollectorType { private set; get; } public ECollectorType CollectorType { private set; get; }
/// <summary> /// <summary>
/// 资源包名称 /// 资源包名称
/// </summary> /// </summary>
public string BundleName { private set; get; } public string BundleName { private set; get; }
/// <summary> /// <summary>
/// 可寻址地址 /// 可寻址地址
/// </summary> /// </summary>
public string Address { private set; get; } public string Address { private set; get; }
/// <summary> /// <summary>
/// 资源路径 /// 资源信息
/// </summary> /// </summary>
public string AssetPath { private set; get; } public AssetInfo AssetInfo { private set; get; }
/// <summary> /// <summary>
/// 资源分类标签 /// 资源分类标签
/// </summary> /// </summary>
public List<string> AssetTags { private set; get; } public List<string> AssetTags { private set; get; }
/// <summary> /// <summary>
/// 依赖的资源列表 /// 依赖的资源列表
/// </summary> /// </summary>
public List<string> DependAssets = new List<string>(); public List<AssetInfo> DependAssets = new List<AssetInfo>();
public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath, List<string> assetTags) public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, AssetInfo assetInfo, List<string> assetTags)
{ {
CollectorType = collectorType; CollectorType = collectorType;
BundleName = bundleName; BundleName = bundleName;
Address = address; Address = address;
AssetPath = assetPath; AssetInfo = assetInfo;
AssetTags = assetTags; AssetTags = assetTags;
} }
} }
} }

Some files were not shown because too many files have changed in this diff Show More