Compare commits

...

176 Commits
1.0.7 ... 1.2.2

Author SHA1 Message Date
hevinci
141086929f Update CHANGELOG.md 2022-07-31 23:27:01 +08:00
hevinci
4f417e123b Update package.json 2022-07-31 23:26:59 +08:00
hevinci
2204f4d129 Update PatchManifest
资源补丁清单增加文件版本信息
2022-07-31 23:09:54 +08:00
hevinci
f80a3229cc Update AssetBundleBuilder 2022-07-31 22:53:30 +08:00
hevinci
d94d196c83 Update AssetBundleBuilder 2022-07-31 22:51:40 +08:00
hevinci
9c67461dbc Update AssetBundleBuilder
增加资源构建结果返回信息
2022-07-31 22:41:24 +08:00
hevinci
75910b7558 Update YooAssets.cs
增加获取资源信息新方法
2022-07-31 22:26:33 +08:00
hevinci
88b9afe189 Update ShaderVariantCollector 2022-07-28 16:12:39 +08:00
hevinci
6fa17e617a Update document 2022-07-27 12:19:34 +08:00
hevinci
2c9360721a Update document 2022-07-27 11:07:33 +08:00
hevinci
6851495da5 Update document 2022-07-27 11:05:12 +08:00
hevinci
1b25835d1a Update ShaderVariantCollector 2022-07-27 11:04:54 +08:00
hevinci
e36918b6ec Merge branch 'main' of https://github.com/tuyoogame/YooAsset 2022-07-27 10:25:49 +08:00
hevinci
65468d5b15 Update document 2022-07-27 10:25:46 +08:00
何冠峰
78f81ea335 Merge pull request #28 from wqaetly/ForPr
feat:SVC搜集工作支持在CI上进行
2022-07-27 10:11:41 +08:00
NKG丶MadLife
21f350a84e chore:调整缩进 2022-07-27 00:19:23 +08:00
NKG丶MadLife
17fab5ad61 feat:SVC搜集工作支持在CI上进行 2022-07-27 00:17:23 +08:00
hevinci
7f41ba9a3c Update document 2022-07-25 18:36:41 +08:00
hevinci
1dc434832a Update AssetSystem
修复了加载多个相同的子场景而无法全部卸载的问题。
2022-07-25 18:31:35 +08:00
hevinci
045e74c82f Update samples 2022-07-25 18:21:27 +08:00
hevinci
c96fa23d61 Update patch manifest 2022-07-25 16:12:34 +08:00
hevinci
7881f39b97 Delete BasicSample.meta 2022-07-25 15:56:04 +08:00
hevinci
cf1a32ed1f Update Samples 2022-07-25 15:55:51 +08:00
hevinci
d0b7ae020c Update patch manifest 2022-07-25 15:46:20 +08:00
hevinci
e5c7bbdf52 Update AssetBundleBuilder 2022-07-25 15:40:26 +08:00
hevinci
42d52720f3 Update AssetBundleBuilder
增加输出文件名称样式的选择功能。
2022-07-23 17:39:04 +08:00
hevinci
6d392139df Update CHANGELOG.md 2022-07-23 15:55:45 +08:00
hevinci
852c741310 Update package.json 2022-07-23 15:55:35 +08:00
hevinci
41761f0a97 Update AssetBundleBuilder
SBP构建参数增加了缓存服务器的地址和端口
2022-07-22 12:56:22 +08:00
hevinci
2d5854ed58 Update AssetBundleBuilder
移除对增量更新初次无法构建的限制
2022-07-22 12:55:20 +08:00
hevinci
1370ffb3bb Update UpdateManifestOperation.cs
不期望删除断点续传的资源文件
2022-07-21 18:00:57 +08:00
hevinci
6efc88423e Update document 2022-07-20 19:00:29 +08:00
hevinci
6e2314eab5 Update document 2022-07-20 15:06:14 +08:00
hevinci
d64b31f6ce Fixed #26
修复多个场景打进一个AB包时,卸载子场景时抛出异常。
2022-07-20 15:05:28 +08:00
hevinci
d5a4b3365f Update YooAssets.cs 2022-07-20 10:57:56 +08:00
hevinci
86142ed4db Fixed #25
修复了资源文件不存在返回的handle无法完成的问题。
2022-07-20 10:57:40 +08:00
hevinci
2cb9278db0 Update AssetBundleCollector
资源收集增加无效文件的过滤。
2022-07-19 19:20:51 +08:00
hevinci
92fad7f29b Update AssetBundleBuilder
修改内置构建管线的构建结果验证逻辑。
2022-07-19 19:20:05 +08:00
hevinci
c782e8154b Update document 2022-07-19 16:30:18 +08:00
何冠峰
77c387bfe9 Update README.md 2022-07-19 14:42:25 +08:00
hevinci
aea9099e34 Update AssetBundleReporter
增加主资源总数的统计。
2022-07-18 16:26:47 +08:00
hevinci
6446b3ed40 Update samples 2022-07-18 15:50:34 +08:00
hevinci
8967e6f8c4 Update package.json 2022-07-18 15:17:22 +08:00
hevinci
d6010a81e1 Update document 2022-07-18 15:02:25 +08:00
hevinci
95e6921a4e Update samples 2022-07-18 14:59:15 +08:00
hevinci
df5f0b9c13 Update packages 2022-07-18 14:57:39 +08:00
hevinci
665a6afd74 Move UniTask estension to samples 2022-07-18 14:57:07 +08:00
hevinci
f53c4300e8 Update .gitignore 2022-07-18 14:56:18 +08:00
hevinci
1fdeeb781f Update Samples 2022-07-18 14:56:12 +08:00
hevinci
e340af90ed Update CHANGELOG.md 2022-07-18 12:17:21 +08:00
hevinci
7fa7cc4af1 Update package.json 2022-07-18 12:17:02 +08:00
hevinci
ca3c011f34 Update AssetBundleBuilder
增加配置保存按钮。
2022-07-18 12:05:40 +08:00
hevinci
669339d5b4 Update AssetBundleCollector
增加配置保存按钮。
2022-07-18 12:04:46 +08:00
hevinci
c6567650fe Update Update document 2022-07-18 11:25:09 +08:00
hevinci
3ae70412fa Update AssetBundleBuilder 2022-07-18 11:24:47 +08:00
hevinci
d575850f9f Update package.json 2022-07-15 19:47:33 +08:00
hevinci
d1439da54e Update AssetBundleBuilder
支持可编程构建管线
2022-07-15 19:34:59 +08:00
何冠峰
89022d3df4 Merge pull request #24 from LiuOcean/main
Update UniTask.YooAsset README
2022-07-13 17:03:39 +08:00
L
3c38fe6155 Update UniTask.YooAsset README 2022-07-13 15:29:23 +08:00
hevinci
e68ece6925 Update AssetBundleBuilder 2022-07-13 11:59:15 +08:00
hevinci
ea9b8874cc Update decryption services
解密服务接口增加解密文件信息。
2022-07-13 10:48:49 +08:00
hevinci
475efd90fc Update FAQ.md 2022-07-13 10:33:21 +08:00
hevinci
682605d5c2 Update document 2022-07-12 16:06:44 +08:00
hevinci
256844ddf5 Update AssetBundleCollector
打包资源忽略Gizmos资源文件。
2022-07-12 15:38:26 +08:00
何冠峰
96f95bbd99 Merge pull request #21 from axn777/branch_share_ignore
如果依赖的是运行时以外的,不打入 share AssetBundle包
2022-07-12 15:00:56 +08:00
何冠峰
4f7bb945e0 Merge pull request #22 from wqaetly/ForPr
fix:修复ShaderVariantCollection刷新不及时问题
2022-07-12 14:54:26 +08:00
NKG丶MadLife
0d69d779f6 fix:修复ShaderVariantCollection刷新不及时问题 2022-07-10 22:12:09 +08:00
axn777
5df26908fb 如果依赖的是运行时以外的,不打入 share AssetBundle包 2022-07-08 01:41:20 +08:00
hevinci
fb5e289de0 Update patch system
优化代码逻辑结构
2022-07-07 19:10:44 +08:00
hevinci
b238759f61 Update CHANGELOG.md 2022-07-07 10:13:39 +08:00
hevinci
2bb0d18891 Update package.json 2022-07-07 10:13:20 +08:00
hevinci
7d5b6504f4 Update YooAssets.cs
检测原生文件加载方法,预防传入无效文件。
2022-07-05 20:07:32 +08:00
何冠峰
63f90e1537 Merge pull request #19 from LiuOcean/main
Fix Unity 2020 IL2Cpp UniTask Bug
2022-07-02 15:28:12 +08:00
何冠峰
65b43feb38 Merge pull request #18 from Y-way/typo
拼写错误
2022-07-02 15:27:59 +08:00
L
4f00a19344 Fix Unity 2020 IL2Cpp UniTask Bug 2022-07-02 12:33:59 +08:00
hevinci
3bfca7d340 Update AssetBundleBuilder 2022-06-30 14:29:27 +08:00
Y-way
8538d0de28 拼写错误 2022-06-30 14:09:07 +08:00
hevinci
5425e17d6f Update AssetOperationHandle.cs 2022-06-30 12:12:44 +08:00
何冠峰
bb3065d08d Merge pull request #17 from Y-way/OptimizeAssetOperationHandle
AssetOperationHandle类新增便捷方法,便于链式编程
2022-06-30 12:03:57 +08:00
hevinci
1adc3d7ed6 Update document 2022-06-30 12:02:06 +08:00
hevinci
556b23b488 Update OperationHandleBase.cs 2022-06-29 12:41:06 +08:00
hevinci
5b0c189d75 Update InitializationOperation.cs 2022-06-29 11:59:39 +08:00
hevinci
161fdff09a Update document 2022-06-29 10:02:57 +08:00
hevinci
81b3dd57b1 Update document 2022-06-28 20:23:03 +08:00
hevinci
1ab0f447d2 Update document 2022-06-28 20:20:36 +08:00
hevinci
9ac07e94d1 Update UpdateManifestOperation
增加在弱联网环境下的更新支持
2022-06-28 20:13:32 +08:00
Y-way
fee6e8f4dd 增加失败提示 2022-06-28 19:45:37 +08:00
Y-way
1e39b1af6d AssetOperationHandle类新增便捷方法,便于链式编程
TextAsset asset;
                YooAssets.LoadAssetAsync<TextAsset>(name).WaitForAsyncOperationComplete().GetAssetObjet<TextAsset>(out asset).Release();
                YooAssets.LoadAssetAsync<TextAsset>(name).Completed += handler => {
                    handler.GetAssetObjet(out asset).Release();
                };
2022-06-28 19:17:47 +08:00
hevinci
727d841d47 Update document 2022-06-28 17:18:43 +08:00
hevinci
5e0d4d6ee1 Update document 2022-06-27 14:03:14 +08:00
hevinci
32ce99949b Update AssetBundleDebugger
完善调试器窗口,增加帧数控制。
2022-06-25 17:56:49 +08:00
hevinci
fbb9bff3c7 Remove AutoReleaseGameObjectHandle param.
移除自动释放资源对象句柄的功能。
2022-06-25 12:09:20 +08:00
hevinci
6471b237ce Update Patch System
离线模式移除资内置资源解压功能。
2022-06-25 11:42:50 +08:00
hevinci
d452c610c1 Update document 2022-06-25 11:41:13 +08:00
hevinci
009fa88402 Update document 2022-06-25 10:59:51 +08:00
hevinci
6d26276352 Update AssetBundleDebuggerWindow.cs
修复了AssetView和BundleView切换失败的问题。
2022-06-24 17:03:27 +08:00
hevinci
bdca693413 Update CHANGELOG.md 2022-06-23 21:48:09 +08:00
hevinci
a2d30ca99a Update package.json 2022-06-23 21:44:32 +08:00
hevinci
5c02bc2bee Update AssetBundleCollector
增加分组禁用功能。
2022-06-23 20:41:32 +08:00
何冠峰
00ffd55fef Merge pull request #15 from JourneyHans/main
编辑器模式下打包执行成功后自动显示Bundle文件夹
2022-06-23 16:08:11 +08:00
hevinci
32148821a1 Add AutoReleaseGameObjectHandle initialize parameters
支持自动释放游戏对象句柄的功能。
2022-06-23 16:02:53 +08:00
hevinci
60f6483a86 Update AssetBundleCollector window
修复StaticAssetCollector无法预览Main Assets列表的问题。
2022-06-23 14:07:12 +08:00
hevinci
9b80300f19 Update DefaultFilterRule.cs 2022-06-23 13:58:47 +08:00
hevinci
8f02bfa3a6 Update DefaultFilterRule.cs
修复了精灵过滤器无效的问题。
2022-06-23 13:46:31 +08:00
huanghanzhi
93607ad62a 编辑器模式下打包执行成功后自动显示Bundle文件夹 2022-06-22 15:50:56 +08:00
hevinci
3cbf891674 Add GetAssetPath method.
增加YooAssets.GetAssetPath方法
2022-06-21 17:21:37 +08:00
hevinci
00688a65af Add VerifyLevel filed.
增加了下载文件校验等级初始化参数。
2022-06-21 16:04:59 +08:00
hevinci
c0099cb90c Update RawFileOperation.cs
优化原生文件加载逻辑
2022-06-21 14:08:02 +08:00
hevinci
43248408fc Update DownloaderOperation.cs
Add OnStartDownloadFileCallback filed.
Change OnDownloadFileFailedCallback to OnDownloadErrorCallback.
2022-06-21 10:40:16 +08:00
hevinci
d535500b9e Update AssetBundleDebugger 2022-06-20 19:56:19 +08:00
hevinci
9cea3e1ba9 Update YooAssets.cs
Add IsInitialized filed
2022-06-20 15:38:55 +08:00
何冠峰
746fa44ab8 Merge pull request #13 from susices/main
修复资源包收集工具页面 切换EnableAddressable时 未及时刷新收集器UI的问题
2022-06-20 10:21:20 +08:00
hevinci
b23d56f49c Update document 2022-06-20 10:19:17 +08:00
hevinci
3693f1ea98 Update AssetInfo.cs
Add Address filed.
2022-06-20 10:18:51 +08:00
susices
14127e8097 Merge branch 'tuyoogame:main' into main 2022-06-18 18:27:28 +08:00
wenchao
ad0d47bd68 修复资源包收集工具页面 切换EnableAddressable时 未及时刷新收集器UI的问题 2022-06-18 18:26:24 +08:00
hevinci
b59fb0d811 Optimize share bundle pack logic
优化了共享资源的打包逻辑。
2022-06-17 12:05:14 +08:00
hevinci
0b1990f040 Yooasset add destroy methods
增加销毁机制
2022-06-15 18:14:04 +08:00
hevinci
8deb239450 Update remote debugger
Support remote mobie device debugging
2022-06-15 16:52:54 +08:00
hevinci
33387e8d26 Update AssetBundleBuilder 2022-06-10 10:50:27 +08:00
hevinci
9d4656a1f2 Update EditorHelper.cs 2022-06-09 16:09:35 +08:00
hevinci
9c49d8d54a Update manifest operation add FoundNewManifest filed.
补丁清单更新操作,增加了查询发现了新的清单的字段。
2022-05-27 15:17:10 +08:00
hevinci
4ee6b3cdc2 Update CHANGELOG.md 2022-05-22 15:14:27 +08:00
hevinci
d5636a71b1 Update package.json 2022-05-22 15:08:45 +08:00
hevinci
b1ca47fc14 Update EditorHelper.cs 2022-05-22 15:03:40 +08:00
hevinci
ddb35620cb Update document 2022-05-22 00:40:15 +08:00
hevinci
a906a84721 Optimized the loading method of the setting file
优化了配置文件的加载方式和途径。
2022-05-22 00:39:22 +08:00
hevinci
d43d30f72f The collector window supports undo operations
资源收集界面支持撤销操作
2022-05-21 23:41:58 +08:00
hevinci
e9841a65c6 Added pause method and resume method to patch downloader
补丁下载器增加暂停方法和恢复方法
2022-05-21 22:36:06 +08:00
hevinci
2dd3ba847e Bundle build system adds builtin files copy options
资源构建增加内置文件拷贝的选项
2022-05-21 22:24:05 +08:00
hevinci
0dcbe0574c Fixed load sprite issues in editor simulate mode
修复加载精灵图片失败的问题在编辑器模拟模式下。
2022-05-16 20:16:10 +08:00
hevinci
d01dce438c Fixed window opening issues
修复了资源收集配置存在多个的时候,导致后续无法打开窗口的问题。
2022-05-16 15:48:23 +08:00
hevinci
76929cc015 Update CHANGELOG.md 2022-05-14 12:47:16 +08:00
hevinci
cde0f4bcd8 Update package.json 2022-05-14 12:47:12 +08:00
hevinci
8dc0560537 Optimized the loading method of the setting file
优化了配置文件的加载方式和途径。
2022-05-13 23:53:19 +08:00
hevinci
a054740de6 Optimize assetbundle build parameters
优化了资源包的构建参数:始终开启DisableLoadAssetByFileName
2022-05-13 21:58:23 +08:00
hevinci
029b850d6b Update asset system
新增获取所有子资源对象的方法。
2022-05-13 14:57:49 +08:00
hevinci
8260653eae Merge branch 'main' of https://github.com/tuyoogame/YooAsset 2022-05-13 14:29:36 +08:00
hevinci
bd7b9b5c44 Update README.md 2022-05-13 14:29:28 +08:00
hevinci
8f33a391f8 Update document 2022-05-13 14:29:22 +08:00
何冠峰
2f9d3a9f11 Merge pull request #11 from jiangguilong2000/main
feat(AssetSystem): 获取图集下所有的精灵对象集合
2022-05-13 14:23:23 +08:00
Allen Jiang
316294f449 feat(AssetSystem): 获取图集下所有的精灵对象集合 2022-05-13 14:08:36 +08:00
hevinci
09fac3bd64 Add warning when asset path is invalid. 2022-05-12 23:13:21 +08:00
hevinci
2da81212b4 Update document 2022-05-12 12:37:48 +08:00
hevinci
4cad587609 Optimized asset system and patch system framework
优化了资源定位不正确导致的错误报告方式。
YooAssets.ProcessOperation()重命名为YooAssets.StartOperation()
YooAssets.GetBundleInfo()已经移除方法。
YooAssets.IsNeedDownloadFromRemote()新增加方法。
2022-05-11 16:48:17 +08:00
hevinci
67eeae31c7 Update patch manifest
更新资源清单:资源对象增加分类标签。
2022-05-11 16:23:31 +08:00
hevinci
ae465a47a9 Simulate build use default build version.
模拟构建模式使用一个默认的资源版本号。
2022-05-11 16:13:51 +08:00
hevinci
23b59f6ad6 Update document 2022-05-09 22:14:49 +08:00
hevinci
09e3483e0a Update README.md 2022-05-09 22:13:20 +08:00
hevinci
b3f4e9ae6e Update document 2022-05-09 22:13:14 +08:00
hevinci
79efe6237d Update asset system 2022-05-09 21:18:15 +08:00
hevinci
bf0f479234 Update download system 2022-05-09 18:44:49 +08:00
hevinci
ece1dab28b Update README.md 2022-05-08 22:21:17 +08:00
hevinci
b913b5c20c Update document 2022-05-08 22:21:13 +08:00
hevinci
366cf3c792 Update CHANGELOG.md 2022-05-08 22:18:33 +08:00
hevinci
21ccd4d29f Update package.json 2022-05-08 22:17:57 +08:00
hevinci
b8ba4219cd Update YooAssets.cs 2022-05-08 22:09:44 +08:00
hevinci
43da6847ba Merge branch 'main' of https://github.com/tuyoogame/YooAsset 2022-05-08 21:51:35 +08:00
hevinci
c22c87e16b Update asset bundle reporter window
更新构建报告窗口:增加预览AssetBundle文件内容的功能。
2022-05-08 21:51:27 +08:00
何冠峰
4551dabb39 Merge pull request #9 from LiuOcean/main
Add AsyncOperationBaseExtensions UniTask Support
2022-05-08 19:32:27 +08:00
L
774ad0e5ef Add AsyncOperationBaseExtensions UniTask Support 2022-05-08 11:04:55 +08:00
hevinci
bd87e982ef Add progress of async operation
异步操作类增加进度查询。
2022-05-07 20:30:16 +08:00
hevinci
ecd4973948 Update editor simulate mode parameters
更新编辑器下模拟模式的初始化参数类
2022-05-07 19:20:52 +08:00
hevinci
6dd1eee6c3 Remove LoadAllAssets method.
移除YooAssets.LoadAllAssets方法。
2022-05-07 18:45:15 +08:00
hevinci
42703def02 Add process operation method.
增加开启异步操作的方法。
2022-05-07 18:23:00 +08:00
hevinci
afc08d4e46 Add load all asset method.
增加新的资源加载方法:加载资源对象所属资源包里的所有资源。
2022-05-06 23:15:03 +08:00
hevinci
65875b66c2 Optimized the speed of simulate build 2022-05-06 20:09:36 +08:00
hevinci
091758022f Update document 2022-05-06 10:00:09 +08:00
hevinci
c395a7a750 Supports location to lower
支持资源定位地址小写。
2022-05-05 23:11:26 +08:00
hevinci
2ab045658b Compatible with Unity2018
兼容Unity2018版本
2022-05-05 22:03:35 +08:00
hevinci
c196cd84d3 Optimized the speed of simulate build.
优化了编辑器下模拟构建的速度。
2022-05-05 21:12:44 +08:00
hevinci
c3c18cd555 Added initialization fault error detection
增加初始化容错检测。
2022-05-05 11:44:03 +08:00
hevinci
cb48c672bd Added version info to the collector xml config
资源收集配表增加版本信息。
2022-05-05 11:25:34 +08:00
hevinci
713073203c Fixed asset bundle collector config error
修复了资源收集器导出配置文件时没有导出公共设置。
2022-05-04 21:38:16 +08:00
hevinci
eafdb8cd31 Update AssetBundleCollector
AssetBundleGrouper变更为AssetBundleCollector
2022-05-04 21:24:51 +08:00
hevinci
d592fb96a6 Optimize collector window jank problem
优化了资源收集窗体卡顿问题。
2022-05-04 19:47:01 +08:00
446 changed files with 26956 additions and 2335 deletions

5
.gitignore vendored
View File

@@ -58,4 +58,7 @@ sysinfo.txt
# Crashlytics generated file # Crashlytics generated file
crashlytics-build.properties crashlytics-build.properties
*.vsconfig *.vsconfig
Sandbox/
Bundles/

View File

@@ -2,6 +2,289 @@
All notable changes to this package will be documented in this file. All notable changes to this package will be documented in this file.
## [1.2.2] - 2022-07-31
### Fixed
- 修复了加载多个相同的子场景而无法全部卸载的问题。
### Changed
- ShaderVariantCollecor支持在CI上调用运行。
- 资源补丁清单增加文件版本校验功能。
- AssetBundleBuilder现在构建结果可以查询构建失败信息。
- AssetBundleBuilder现在资源包文件名称样式提供选择功能。
````c#
class BuildParameters
{
/// <summary>
/// 补丁文件名称的样式
/// </summary>
public EOutputNameStyle OutputNameStyle;
}
````
### Added
- 增加获取资源信息新方法。
````c#
/// <summary>
/// 获取资源信息
/// </summary>
/// <param name="location">资源的定位地址</param>
public static AssetInfo GetAssetInfo(string location);
````
## [1.2.1] - 2022-07-23
### Fixed
- (#25)修复了资源文件不存在返回的handle无法完成的问题。
- (#26)修复多个场景打进一个AB包时卸载子场景时抛出异常。
### Changed
- 构建报告里增加主资源总数的统计。
- 资源构建系统里修改了内置构建管线的构建结果验证逻辑,移除了对中文路径的检测。
- 资源构建系统里移除了对增量更新初次无法构建的限制。
- 优化了缓存验证逻辑,不期望删除断点续传的资源文件。
- 资源构建系统里SBP构建参数增加了缓存服务器的地址和端口。
## [1.2.0] - 2022-07-18
### Fixed
- 修复了ShaderVariantCollection刷新不及时问题。
### Changed
- 资源收集忽略了Gizmos资源文件。
- 解密服务接口增加解密文件信息参数。
- 资源收集窗体增加配置保存按钮。
- 资源构建窗体增加配置保存按钮。
### Added
- 资源构建模块增加了可编程构建管线(SBP)的支持,开发者可以在内置构建管线和可编程构建管线之间自由选择,零修改成本。
## [1.1.1] - 2022-07-07
### Fixed
- 修复了AssetBundleDebugger窗口View下拉页签切换无效的问题。
- 修复了在Unity2020.3版本下UniTask在真机上的一个IL2CPP相关的错误。
### Changed
- 优化了AssetBundleDebugger窗口增加了帧数显示以及回放功能。
- 优化了AssetBundleBuilder的代码结构。
- 增强了YooAssets.GetRawFileAsync()方法的容错。
### Added
- 新增了OperationHandleBase.GetAssetInfo()方法。
````c#
/// <summary>
/// 获取资源信息
/// </summary>
public AssetInfo GetAssetInfo();
````
- 新增了AssetOperationHandle.GetAssetObjet<TAsset>()方法。
````c#
/// <summary>
/// 获取资源对象
/// </summary>
/// <typeparam name="TAsset">资源类型</typeparam>
public TAsset GetAssetObjet<TAsset>()
````
- 新增了弱联网情况下加载补丁清单方法。
````c#
/// <summary>
/// 弱联网情况下加载补丁清单
/// 注意:当指定版本内容验证失败后会返回失败。
/// </summary>
/// <param name="resourceVersion">指定的资源版本</param>
public static UpdateManifestOperation WeaklyUpdateManifestAsync(int resourceVersion)
````
### Removed
- 离线运行模式OfflinePlayMode下移除了资内置资源解压相关逻辑。
- 移除了初始化参数AutoReleaseGameObjectHandle及相关代码逻辑。
## [1.1.0] - 2022-06-23
### Fixed
- 修复了AssetBundleCollector窗口在切换EnableAddressable时未及时刷新界面的问题。
- 修复了AssetBundleCollector窗口资源过滤器CollectSprite无效的问题。
- 修复了AssetBundleCollector窗口无法正常预览StaticAssetCollector的资源列表的问题。
- 修复了在离线模式下原生文件每次都从包内加载的问题。
### Changed
- 变更了共享资源打包机制。
- AssetBundleCollector窗口增加了分组禁用功能。
- AssetBundleDebugger窗口增加了真机远程调试功能。
- AssetBundleBuilder窗口在构建成功后自动显示构建文件夹。
- DownloaderOperation.OnDownloadFileFailedCallback委托变更为OnDownloadErrorCallback委托。
### Added
- 新增UpdateManifestOperation.FoundNewManifest字段。
- 新增DownloaderOperation.OnStartDownloadFileCallback委托。
- 新增AssetInfo.Address字段。
- 新增YooAssets.IsInitialized字段。
- 新增YooAssets初始化参数。
````c#
/// <summary>
/// 下载文件校验等级
/// </summary>
public EVerifyLevel VerifyLevel = EVerifyLevel.High;
````
- 新增YooAssets获取资源完成路径的方法。
````c#
/// <summary>
/// 获取资源路径
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <returns>如果location地址无效则返回空字符串</returns>
public static string GetAssetPath(string location);
````
- 新增YooAssets初始化参数。
```c#
/// <summary>
/// 自动释放游戏对象所属资源句柄
/// 说明:通过资源句柄实例化的游戏对象在销毁之后,会自动释放所属资源句柄。
/// </summary>
public bool AutoReleaseGameObjectHandle = false;
```
## [1.0.10] - 2022-05-22
### Fixed
- 修复了资源收集配置存在多个的时候,导致后续无法打开窗口的问题。
- 修复了在编辑器模拟模式下加载精灵图片失败的问题。
- 修复了在Unity2019版本无法识别配置文件的问题。
### Changed
- 资源构建增加内置资源文件(首包资源文件)拷贝的选项。
- 补丁下载器增加暂停方法和恢复方法。
- 在资源收集界面对Collector的增加和删除支持撤销和恢复操作。
## [1.0.9] - 2022-05-14
### Fixed
- 修复了YooAssets.GetAssetInfos(string Tag)方法返回了无关的资源信息的问题。
### Changed
- 编辑器下的模拟运行模式,不再依赖配置里的构建版本。
- 更新资源清单结构,资源对象类增加分类标签。
- 优化了资源工具相关配置文件的加载方式和途径,这些配置文件可以放置在任何目录下。
- 优化了Location无效后的错误报告方式。
- 优化了资源包的构建参数现在始终开启DisableLoadAssetByFileName帮助减小运行时的内存。
- YooAssets.ProcessOperation()重命名为YooAssets.StartOperation()
### Added
- 新增YooAssets.IsNeedDownloadFromRemote()方法。
````c#
public static bool IsNeedDownloadFromRemote(string location);
````
- 新增获取所有子资源对象的方法。
````c#
class SubAssetsOperationHandle
{
public TObject[] GetSubAssetObjects<TObject>();
}
````
### Removed
- YooAssets.GetBundleInfo()方法已经移除。
## [1.0.8] - 2022-05-08
### Fixed
- 修复了资源收集器导出配置文件时没有导出公共设置。
- 修复了不兼容Unity2018版本的错误。
### Changed
- AssetBundleGrouper窗口变更为AssetBundleCollector窗口。
- **优化了编辑器下模拟运行的初始化速度**。
- **优化了资源收集窗口打开时卡顿的问题**。
- 资源收集XML配表支持版本兼容。
- 资源报告查看窗口支持预览AssetBundle文件内容的功能。
- 完善了对UniTask的支持。
- YooAssets所有接口支持初始化容错检测。
### Added
- 异步操作类增加进度查询字段。
```c#
class AsyncOperationBase
{
/// <summary>
/// 处理进度
/// </summary>
public float Progress { get; protected set; }
}
```
- 增加开启异步操作的方法。
```c#
/// <summary>
/// 开启一个异步操作
/// </summary>
/// <param name="operation">异步操作对象</param>
public static void ProcessOperaiton(GameAsyncOperation operation)
```
- 新增编辑器下模拟模式的初始化参数。
````c#
/// <summary>
/// 用于模拟运行的资源清单路径
/// 注意:如果路径为空,会自动重新构建补丁清单。
/// </summary>
public string SimulatePatchManifestPath;
````
- 新增通用的初始化参数。
```c#
/// <summary>
/// 资源定位地址大小写不敏感
/// </summary>
public bool LocationToLower = false;
```
## [1.0.7] - 2022-05-04 ## [1.0.7] - 2022-05-04
### Fixed ### Fixed

View File

@@ -8,141 +8,87 @@ namespace YooAsset.Editor
{ {
public class AssetBundleBuilder public class AssetBundleBuilder
{ {
public class BuildParametersContext : IContextObject
{
private readonly System.Diagnostics.Stopwatch _buildWatch = new System.Diagnostics.Stopwatch();
/// <summary>
/// 构建参数
/// </summary>
public BuildParameters Parameters { private set; get; }
/// <summary>
/// 构建管线的输出目录
/// </summary>
public string PipelineOutputDirectory { private set; get; }
public BuildParametersContext(BuildParameters parameters)
{
Parameters = parameters;
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
if (parameters.BuildMode == EBuildMode.DryRunBuild)
PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}";
else if(parameters.BuildMode == EBuildMode.FastRunBuild)
PipelineOutputDirectory += $"_{EBuildMode.FastRunBuild}";
}
/// <summary>
/// 获取本次构建的补丁目录
/// </summary>
public string GetPackageDirectory()
{
return $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.BuildVersion}";
}
/// <summary>
/// 获取构建选项
/// </summary>
public BuildAssetBundleOptions GetPipelineBuildOptions()
{
// For the new build system, unity always need BuildAssetBundleOptions.CollectDependencies and BuildAssetBundleOptions.DeterministicAssetBundle
// 除非设置ForceRebuildAssetBundle标记否则会进行增量打包
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
if (Parameters.BuildMode == EBuildMode.FastRunBuild)
{
throw new Exception("Should never get here !");
}
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
{
opt |= BuildAssetBundleOptions.DryRunBuild;
return opt;
}
if (Parameters.CompressOption == ECompressOption.Uncompressed)
opt |= BuildAssetBundleOptions.UncompressedAssetBundle;
else if (Parameters.CompressOption == ECompressOption.LZ4)
opt |= BuildAssetBundleOptions.ChunkBasedCompression;
if (Parameters.BuildMode == EBuildMode.ForceRebuild)
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
if (Parameters.AppendHash)
opt |= BuildAssetBundleOptions.AppendHashToAssetBundleName; //Append the hash to the assetBundle name
if (Parameters.DisableWriteTypeTree)
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
if (Parameters.IgnoreTypeTreeChanges)
opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check.
if (Parameters.DisableLoadAssetByFileName)
{
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
}
return opt;
}
/// <summary>
/// 获取构建的耗时(单位:秒)
/// </summary>
public int GetBuildingSeconds()
{
int seconds = (int)(_buildWatch.ElapsedMilliseconds / 1000);
return seconds;
}
public void BeginWatch()
{
_buildWatch.Start();
}
public void StopWatch()
{
_buildWatch.Stop();
}
}
private readonly BuildContext _buildContext = new BuildContext(); private readonly BuildContext _buildContext = new BuildContext();
/// <summary> /// <summary>
/// 开始构建 /// 开始构建
/// </summary> /// </summary>
public bool Run(BuildParameters buildParameters) public BuildResult Run(BuildParameters buildParameters)
{ {
// 清空旧数据 // 清空旧数据
_buildContext.ClearAllContext(); _buildContext.ClearAllContext();
// 检测构建参数是否为空
if (buildParameters == null)
{
throw new Exception($"{nameof(buildParameters)} is null !");
}
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
if (buildParameters.SBPParameters == null)
throw new Exception($"{nameof(BuildParameters.SBPParameters)} is null !");
}
// 构建参数 // 构建参数
var buildParametersContext = new BuildParametersContext(buildParameters); var buildParametersContext = new BuildParametersContext(buildParameters);
_buildContext.SetContextObject(buildParametersContext); _buildContext.SetContextObject(buildParametersContext);
// 执行构建流程 // 是否显示LOG
List<IBuildTask> pipeline = new List<IBuildTask> if (buildParameters.BuildMode == EBuildMode.SimulateBuild)
{
new TaskPrepare(), //前期准备工作
new TaskGetBuildMap(), //获取构建列表
new TaskBuilding(), //开始执行构建
new TaskVerifyBuildResult(), //验证构建结果
new TaskEncryption(), //加密资源文件
new TaskCreatePatchManifest(), //创建清单文件
new TaskCreateReport(), //创建报告文件
new TaskCreatePatchPackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件
};
if (buildParameters.BuildMode == EBuildMode.FastRunBuild)
BuildRunner.EnableLog = false; BuildRunner.EnableLog = false;
else else
BuildRunner.EnableLog = true; BuildRunner.EnableLog = true;
bool succeed = BuildRunner.Run(pipeline, _buildContext); // 创建构建节点
if (succeed) List<IBuildTask> pipeline;
Debug.Log($"{buildParameters.BuildMode}模式构建成功!"); if (buildParameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline)
{
pipeline = new List<IBuildTask>
{
new TaskPrepare(), //前期准备工作
new TaskGetBuildMap(), //获取构建列表
new TaskBuilding(), //开始执行构建
new TaskVerifyBuildResult(), //验证构建结果
new TaskEncryption(), //加密资源文件
new TaskCreatePatchManifest(), //创建清单文件
new TaskCreateReport(), //创建报告文件
new TaskCreatePatchPackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件
};
}
else if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
pipeline = new List<IBuildTask>
{
new TaskPrepare(), //前期准备工作
new TaskGetBuildMap(), //获取构建列表
new TaskBuilding_SBP(), //开始执行构建
new TaskVerifyBuildResult_SBP(), //验证构建结果
new TaskEncryption(), //加密资源文件
new TaskCreatePatchManifest(), //创建清单文件
new TaskCreateReport(), //创建报告文件
new TaskCreatePatchPackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件
};
}
else else
Debug.LogWarning($"{buildParameters.BuildMode}模式构建失败!"); {
return succeed; throw new NotImplementedException();
}
// 执行构建流程
var buildResult = BuildRunner.Run(pipeline, _buildContext);
if (buildResult.Success)
{
Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !");
}
else
{
Debug.LogWarning($"{buildParameters.BuildMode} pipeline build failed !");
Debug.LogError($"Build task failed : {buildResult.FailedTask}");
Debug.LogError($"Build task error : {buildResult.FailedInfo}");
}
return buildResult;
} }
} }
} }

View File

@@ -30,7 +30,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public static string MakePipelineOutputDirectory(string outputRoot, BuildTarget buildTarget) public static string MakePipelineOutputDirectory(string outputRoot, BuildTarget buildTarget)
{ {
return $"{outputRoot}/{buildTarget}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; return $"{outputRoot}/{buildTarget}/{YooAssetSettings.OutputFolderName}";
} }
/// <summary> /// <summary>

View File

@@ -10,13 +10,18 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public int BuildVersion = 0; public int BuildVersion = 0;
/// <summary>
/// 构建管线
/// </summary>
public EBuildPipeline BuildPipeline = EBuildPipeline.BuiltinBuildPipeline;
/// <summary> /// <summary>
/// 构建模式 /// 构建模式
/// </summary> /// </summary>
public EBuildMode BuildMode = EBuildMode.ForceRebuild; public EBuildMode BuildMode = EBuildMode.ForceRebuild;
/// <summary> /// <summary>
/// 内置资源标签 /// 内置资源标签(首包资源标签)
/// </summary> /// </summary>
public string BuildTags = string.Empty; public string BuildTags = string.Empty;
@@ -25,14 +30,14 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public ECompressOption CompressOption = ECompressOption.LZ4; public ECompressOption CompressOption = ECompressOption.LZ4;
/// <summary>
/// 输出文件名称样式
/// </summary>
public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName;
/// <summary> /// <summary>
/// 加密类名称 /// 加密类名称
/// </summary> /// </summary>
public string EncyptionClassName = string.Empty; public string EncyptionClassName = string.Empty;
/// <summary>
/// 附加后缀格式
/// </summary>
public bool AppendExtension = false;
} }
} }

View File

@@ -19,27 +19,17 @@ namespace YooAsset.Editor
} }
} }
/// <summary>
/// 配置数据是否被修改
/// </summary>
public static bool IsDirty { set; get; } = false;
/// <summary> /// <summary>
/// 加载配置文件 /// 加载配置文件
/// </summary> /// </summary>
private static void LoadSettingData() private static void LoadSettingData()
{ {
// 加载配置文件 _setting = EditorHelper.LoadSettingData<AssetBundleBuilderSetting>();
string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleBuilderSetting)}.asset";
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleBuilderSetting>(settingFilePath);
if (_setting == null)
{
Debug.LogWarning($"Create new {nameof(AssetBundleBuilderSetting)}.asset : {settingFilePath}");
_setting = ScriptableObject.CreateInstance<AssetBundleBuilderSetting>();
EditorTools.CreateFileDirectory(settingFilePath);
AssetDatabase.CreateAsset(Setting, settingFilePath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
else
{
Debug.Log($"Load {nameof(AssetBundleBuilderSetting)}.asset ok");
}
} }
/// <summary> /// <summary>
@@ -49,6 +39,7 @@ namespace YooAsset.Editor
{ {
if (Setting != null) if (Setting != null)
{ {
IsDirty = false;
EditorUtility.SetDirty(Setting); EditorUtility.SetDirty(Setting);
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
Debug.Log($"{nameof(AssetBundleBuilderSetting)}.asset is saved!"); Debug.Log($"{nameof(AssetBundleBuilderSetting)}.asset is saved!");

View File

@@ -22,32 +22,37 @@ namespace YooAsset.Editor
private List<Type> _encryptionServicesClassTypes; private List<Type> _encryptionServicesClassTypes;
private List<string> _encryptionServicesClassNames; private List<string> _encryptionServicesClassNames;
private Button _saveButton;
private TextField _buildOutputField; private TextField _buildOutputField;
private IntegerField _buildVersionField; private IntegerField _buildVersionField;
private EnumField _buildPipelineField;
private EnumField _buildModeField; private EnumField _buildModeField;
private TextField _buildTagsField; private TextField _buildinTagsField;
private PopupField<string> _encryptionField; private PopupField<string> _encryptionField;
private EnumField _compressionField; private EnumField _compressionField;
private Toggle _appendExtensionToggle; private EnumField _outputNameStyleField;
public void CreateGUI() public void CreateGUI()
{ {
VisualElement root = this.rootVisualElement;
// 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleBuilder/{nameof(AssetBundleBuilderWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleBuilderWindow)}.uxml : {uxml}");
return;
}
visualAsset.CloneTree(root);
try try
{ {
VisualElement root = this.rootVisualElement;
// 加载布局文件
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleBuilderWindow>();
if (visualAsset == null)
return;
visualAsset.CloneTree(root);
// 配置保存按钮
_saveButton = root.Q<Button>("SaveButton");
_saveButton.clicked += SaveBtn_clicked;
// 构建平台
_buildTarget = EditorUserBuildSettings.activeBuildTarget; _buildTarget = EditorUserBuildSettings.activeBuildTarget;
// 加密服务类
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes(); _encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList(); _encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
@@ -63,26 +68,41 @@ namespace YooAsset.Editor
_buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion); _buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion);
_buildVersionField.RegisterValueChangedCallback(evt => _buildVersionField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value; AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
}); });
// 构建管线
_buildPipelineField = root.Q<EnumField>("BuildPipeline");
_buildPipelineField.Init(AssetBundleBuilderSettingData.Setting.BuildPipeline);
_buildPipelineField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildPipeline);
_buildPipelineField.style.width = 350;
_buildPipelineField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildPipeline = (EBuildPipeline)_buildPipelineField.value;
RefreshWindow();
});
// 构建模式 // 构建模式
_buildModeField = root.Q<EnumField>("BuildMode"); _buildModeField = root.Q<EnumField>("BuildMode");
_buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode); _buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode);
_buildModeField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildMode); _buildModeField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildMode);
_buildModeField.style.width = 300; _buildModeField.style.width = 350;
_buildModeField.RegisterValueChangedCallback(evt => _buildModeField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value; AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value;
RefreshWindow(); RefreshWindow();
}); });
// 内置资源标签 // 内置资源标签
_buildTagsField = root.Q<TextField>("BuildinTags"); _buildinTagsField = root.Q<TextField>("BuildinTags");
_buildTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags); _buildinTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
_buildTagsField.RegisterValueChangedCallback(evt => _buildinTagsField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.Setting.BuildTags = _buildTagsField.value; AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildTags = _buildinTagsField.value;
}); });
// 加密方法 // 加密方法
@@ -92,9 +112,10 @@ namespace YooAsset.Editor
int defaultIndex = GetEncryptionDefaultIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName); int defaultIndex = GetEncryptionDefaultIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName);
_encryptionField = new PopupField<string>(_encryptionServicesClassNames, defaultIndex); _encryptionField = new PopupField<string>(_encryptionServicesClassNames, defaultIndex);
_encryptionField.label = "Encryption"; _encryptionField.label = "Encryption";
_encryptionField.style.width = 300; _encryptionField.style.width = 350;
_encryptionField.RegisterValueChangedCallback(evt => _encryptionField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value; AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value;
}); });
encryptionContainer.Add(_encryptionField); encryptionContainer.Add(_encryptionField);
@@ -103,7 +124,7 @@ namespace YooAsset.Editor
{ {
_encryptionField = new PopupField<string>(); _encryptionField = new PopupField<string>();
_encryptionField.label = "Encryption"; _encryptionField.label = "Encryption";
_encryptionField.style.width = 300; _encryptionField.style.width = 350;
encryptionContainer.Add(_encryptionField); encryptionContainer.Add(_encryptionField);
} }
@@ -111,18 +132,22 @@ namespace YooAsset.Editor
_compressionField = root.Q<EnumField>("Compression"); _compressionField = root.Q<EnumField>("Compression");
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption); _compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption); _compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
_compressionField.style.width = 300; _compressionField.style.width = 350;
_compressionField.RegisterValueChangedCallback(evt => _compressionField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value; AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
}); });
// 附加后缀格 // 输出文件名称样
_appendExtensionToggle = root.Q<Toggle>("AppendExtension"); _outputNameStyleField = root.Q<EnumField>("OutputNameStyle");
_appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension); _outputNameStyleField.Init(AssetBundleBuilderSettingData.Setting.OutputNameStyle);
_appendExtensionToggle.RegisterValueChangedCallback(evt => _outputNameStyleField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.OutputNameStyle);
_outputNameStyleField.style.width = 350;
_outputNameStyleField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value; AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.OutputNameStyle = (EOutputNameStyle)_outputNameStyleField.value;
}); });
// 构建按钮 // 构建按钮
@@ -138,16 +163,38 @@ namespace YooAsset.Editor
} }
public void OnDestroy() public void OnDestroy()
{ {
AssetBundleBuilderSettingData.SaveFile(); if(AssetBundleBuilderSettingData.IsDirty)
AssetBundleBuilderSettingData.SaveFile();
}
public void Update()
{
if(_saveButton != null)
{
if(AssetBundleBuilderSettingData.IsDirty)
{
if (_saveButton.enabledSelf == false)
_saveButton.SetEnabled(true);
}
else
{
if(_saveButton.enabledSelf)
_saveButton.SetEnabled(false);
}
}
} }
private void RefreshWindow() private void RefreshWindow()
{ {
bool enableElement = AssetBundleBuilderSettingData.Setting.BuildMode == EBuildMode.ForceRebuild; var buildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
_buildTagsField.SetEnabled(enableElement); bool enableElement = buildMode == EBuildMode.ForceRebuild;
_buildinTagsField.SetEnabled(enableElement);
_encryptionField.SetEnabled(enableElement); _encryptionField.SetEnabled(enableElement);
_compressionField.SetEnabled(enableElement); _compressionField.SetEnabled(enableElement);
_appendExtensionToggle.SetEnabled(enableElement); _outputNameStyleField.SetEnabled(enableElement);
}
private void SaveBtn_clicked()
{
AssetBundleBuilderSettingData.SaveFile();
} }
private void BuildButton_clicked() private void BuildButton_clicked()
{ {
@@ -172,17 +219,29 @@ namespace YooAsset.Editor
BuildParameters buildParameters = new BuildParameters(); BuildParameters buildParameters = new BuildParameters();
buildParameters.OutputRoot = defaultOutputRoot; buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.BuildTarget = _buildTarget; buildParameters.BuildTarget = _buildTarget;
buildParameters.BuildMode = (EBuildMode)_buildModeField.value; buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline;
buildParameters.BuildVersion = _buildVersionField.value; buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
buildParameters.BuildinTags = _buildTagsField.value; buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion;
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags;
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
buildParameters.EnableAddressable = AssetBundleGrouperSettingData.Setting.EnableAddressable; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
buildParameters.AppendFileExtension = _appendExtensionToggle.value; buildParameters.CopyBuildinTagFiles = AssetBundleBuilderSettingData.Setting.BuildMode == EBuildMode.ForceRebuild;
buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = (ECompressOption)_compressionField.value; buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;
AssetBundleBuilder builder = new AssetBundleBuilder(); if (AssetBundleBuilderSettingData.Setting.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
builder.Run(buildParameters); {
buildParameters.SBPParameters = new BuildParameters.SBPBuildParameters();
buildParameters.SBPParameters.WriteLinkXML = true;
}
var builder = new AssetBundleBuilder();
var buildResult = builder.Run(buildParameters);
if (buildResult.Success)
{
EditorUtility.RevealInFinder($"{buildParameters.OutputRoot}/{buildParameters.BuildTarget}/{buildParameters.BuildVersion}");
}
} }
// 加密类相关 // 加密类相关
@@ -199,9 +258,7 @@ namespace YooAsset.Editor
} }
private List<Type> GetEncryptionServicesClassTypes() private List<Type> GetEncryptionServicesClassTypes()
{ {
TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom<IEncryptionServices>(); return EditorTools.GetAssignableTypes(typeof(IEncryptionServices));
List<Type> classTypes = collection.ToList();
return classTypes;
} }
private IEncryptionServices CreateEncryptionServicesInstance() private IEncryptionServices CreateEncryptionServicesInstance()
{ {

View File

@@ -1,12 +1,15 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True"> <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<uie:Toolbar name="Toolbar" style="display: flex;" /> <uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="background-color: rgb(56, 147, 58);" />
</uie:Toolbar>
<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" />
<uie:IntegerField label="Build Version" value="0" name="BuildVersion" /> <uie:IntegerField label="Build Version" value="0" name="BuildVersion" />
<uie:EnumField label="Build Pipeline" name="BuildPipeline" />
<uie:EnumField label="Build Mode" name="BuildMode" /> <uie:EnumField label="Build Mode" name="BuildMode" />
<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" />
<ui:Toggle label="Append Extension" name="AppendExtension" style="height: 15px;" /> <uie:EnumField label="Output Name Style" value="Center" name="OutputNameStyle" />
<ui:TextField picking-mode="Ignore" label="Buildin Tags" name="BuildinTags" /> <ui:TextField picking-mode="Ignore" label="Buildin Tags" name="BuildinTags" />
<ui:Button text="构建" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" /> <ui:Button text="构建" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
</ui:VisualElement> </ui:VisualElement>

View File

@@ -1,32 +1,30 @@
using System; using UnityEditor;
using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public static class AssetBundleRuntimeBuilder public static class AssetBundleSimulateBuilder
{ {
private static string _manifestFilePath = string.Empty; private static string _manifestFilePath = string.Empty;
/// <summary> /// <summary>
/// 快速模式构建 /// 模拟构建
/// </summary> /// </summary>
public static void FastBuild() public static void SimulateBuild()
{ {
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot(); string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
BuildParameters buildParameters = new BuildParameters(); BuildParameters buildParameters = new BuildParameters();
buildParameters.OutputRoot = defaultOutputRoot; buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.BuildMode = EBuildMode.FastRunBuild; buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion; buildParameters.BuildVersion = 999;
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
buildParameters.EnableAddressable = AssetBundleGrouperSettingData.Setting.EnableAddressable;
AssetBundleBuilder builder = new AssetBundleBuilder(); AssetBundleBuilder builder = new AssetBundleBuilder();
bool buildResult = builder.Run(buildParameters); var buildResult = builder.Run(buildParameters);
if (buildResult) if (buildResult.Success)
{ {
string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildTarget); string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildTarget);
_manifestFilePath = $"{pipelineOutputDirectory}_{EBuildMode.FastRunBuild}/{YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildVersion)}"; _manifestFilePath = $"{pipelineOutputDirectory}_{EBuildMode.SimulateBuild}/{YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildVersion)}";
} }
else else
{ {
@@ -35,9 +33,9 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取构建的补丁清单文件路径 /// 获取构建的补丁清单路径
/// </summary> /// </summary>
public static string GetPatchManifestFilePath() public static string GetPatchManifestPath()
{ {
return _manifestFilePath; return _manifestFilePath;
} }

View File

@@ -9,6 +9,7 @@ namespace YooAsset.Editor
{ {
private string _mainBundleName; private string _mainBundleName;
private string _shareBundleName; private string _shareBundleName;
private bool _isAddAssetTags = false;
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>(); private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
/// <summary> /// <summary>
@@ -37,10 +38,15 @@ namespace YooAsset.Editor
public bool IsShaderAsset { private set; get; } public bool IsShaderAsset { private set; get; }
/// <summary> /// <summary>
/// 资源分类标签列表 /// 资源分类标签
/// </summary> /// </summary>
public readonly List<string> AssetTags = new List<string>(); public readonly List<string> AssetTags = new List<string>();
/// <summary>
/// 资源包的分类标签
/// </summary>
public readonly List<string> BundleTags = new List<string>();
/// <summary> /// <summary>
/// 依赖的所有资源 /// 依赖的所有资源
/// 注意:包括零依赖资源和冗余资源(资源包名无效) /// 注意:包括零依赖资源和冗余资源(资源包名无效)
@@ -62,9 +68,9 @@ namespace YooAsset.Editor
else else
IsShaderAsset = false; IsShaderAsset = false;
} }
public BuildAssetInfo(ECollectorType collectorType, string assetPath) public BuildAssetInfo(string assetPath)
{ {
CollectorType = collectorType; CollectorType = ECollectorType.None;
Address = string.Empty; Address = string.Empty;
AssetPath = assetPath; AssetPath = assetPath;
IsRawAsset = false; IsRawAsset = false;
@@ -89,10 +95,15 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 添加资源分类标签 /// 添加资源分类标签
/// 说明:原始定义的资源分类标签
/// </summary> /// </summary>
public void AddAssetTags(List<string> tags) public void AddAssetTags(List<string> tags)
{ {
if (_isAddAssetTags)
throw new Exception("Should never get here !");
_isAddAssetTags = true;
foreach (var tag in tags) foreach (var tag in tags)
{ {
if (AssetTags.Contains(tag) == false) if (AssetTags.Contains(tag) == false)
@@ -102,6 +113,21 @@ namespace YooAsset.Editor
} }
} }
/// <summary>
/// 添加资源包的分类标签
/// 说明:传染算法统计到的分类标签
/// </summary>
public void AddBundleTags(List<string> tags)
{
foreach (var tag in tags)
{
if (BundleTags.Contains(tag) == false)
{
BundleTags.Add(tag);
}
}
}
/// <summary> /// <summary>
/// 资源包名是否存在 /// 资源包名是否存在
/// </summary> /// </summary>
@@ -147,11 +173,11 @@ namespace YooAsset.Editor
if (IsRawAsset) if (IsRawAsset)
throw new Exception("Should never get here !"); throw new Exception("Should never get here !");
if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders) if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders)
{ {
if (IsShaderAsset) if (IsShaderAsset)
{ {
string shareBundleName = $"{AssetBundleGrouperSettingData.Setting.ShadersBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}"; string shareBundleName = $"{AssetBundleCollectorSettingData.Setting.ShadersBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower(); _shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
return; return;
} }
@@ -159,11 +185,9 @@ namespace YooAsset.Editor
if (_referenceBundleNames.Count > 1) if (_referenceBundleNames.Count > 1)
{ {
var bundleNameList = _referenceBundleNames.ToList(); IPackRule packRule = PackDirectory.StaticPackRule;
bundleNameList.Sort(); var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
string combineName = string.Join("|", bundleNameList); var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
var combineNameHash = HashUtility.StringSHA1(combineName);
var shareBundleName = $"share_{combineNameHash}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower(); _shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
} }
} }

View File

@@ -68,14 +68,14 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取资源标签列表 /// 获取资源包的分类标签列表
/// </summary> /// </summary>
public string[] GetAssetTags() public string[] GetBundleTags()
{ {
List<string> result = new List<string>(BuildinAssets.Count); List<string> result = new List<string>(BuildinAssets.Count);
foreach (var assetInfo in BuildinAssets) foreach (var assetInfo in BuildinAssets)
{ {
foreach (var assetTag in assetInfo.AssetTags) foreach (var assetTag in assetInfo.BundleTags)
{ {
if (result.Contains(assetTag) == false) if (result.Contains(assetTag) == false)
result.Add(assetTag); result.Add(assetTag);

View File

@@ -55,13 +55,13 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取AssetBundle内包含的标记列表 /// 获取资源包的分类标签列表
/// </summary> /// </summary>
public string[] GetAssetTags(string bundleName) public string[] GetBundleTags(string bundleName)
{ {
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo)) if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
{ {
return bundleInfo.GetAssetTags(); return bundleInfo.GetBundleTags();
} }
throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}"); throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}");
} }

View File

@@ -10,16 +10,16 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 执行资源构建上下文 /// 执行资源构建上下文
/// </summary> /// </summary>
public static BuildMapContext CreateBuildMap() public static BuildMapContext CreateBuildMap(EBuildMode buildMode)
{ {
BuildMapContext context = new BuildMapContext(); BuildMapContext context = new BuildMapContext();
Dictionary<string, BuildAssetInfo> buildAssetDic = new Dictionary<string, BuildAssetInfo>(1000); Dictionary<string, BuildAssetInfo> buildAssetDic = new Dictionary<string, BuildAssetInfo>(1000);
// 1. 检测配置合法性 // 1. 检测配置合法性
AssetBundleGrouperSettingData.Setting.CheckConfigError(); AssetBundleCollectorSettingData.Setting.CheckConfigError();
// 2. 获取所有主动收集的资源 // 2. 获取所有收集器收集的资源
List<CollectAssetInfo> allCollectAssets = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets(); List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode);
// 3. 剔除未被引用的依赖资源 // 3. 剔除未被引用的依赖资源
List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>(); List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>();
@@ -36,13 +36,15 @@ namespace YooAsset.Editor
allCollectAssets.Remove(removeValue); allCollectAssets.Remove(removeValue);
} }
// 4. 录入主动收集的资源 // 4. 录入所有收集器收集的资源
foreach (var collectAssetInfo in allCollectAssets) foreach (var collectAssetInfo in allCollectAssets)
{ {
if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false) if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
{ {
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName, collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset); var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName,
collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset);
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo); buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo);
} }
else else
@@ -58,13 +60,13 @@ namespace YooAsset.Editor
{ {
if (buildAssetDic.ContainsKey(dependAssetPath)) if (buildAssetDic.ContainsKey(dependAssetPath))
{ {
buildAssetDic[dependAssetPath].AddAssetTags(collectAssetInfo.AssetTags); buildAssetDic[dependAssetPath].AddBundleTags(collectAssetInfo.AssetTags);
buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName); buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName);
} }
else else
{ {
var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath); var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags); buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName); buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName);
buildAssetDic.Add(dependAssetPath, buildAssetInfo); buildAssetDic.Add(dependAssetPath, buildAssetInfo);
} }
@@ -92,7 +94,7 @@ namespace YooAsset.Editor
pair.Value.CalculateFullBundleName(); pair.Value.CalculateFullBundleName();
} }
// 8. 移除参与构建的资源 // 8. 移除参与构建的资源
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>(); List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic) foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
{ {

View File

@@ -9,6 +9,33 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public class BuildParameters public class BuildParameters
{ {
/// <summary>
/// SBP构建参数
/// </summary>
public class SBPBuildParameters
{
/// <summary>
/// 生成代码防裁剪配置
/// </summary>
public bool WriteLinkXML = true;
/// <summary>
/// 缓存服务器地址
/// </summary>
public string CacheServerHost;
/// <summary>
/// 缓存服务器端口
/// </summary>
public int CacheServerPort;
}
/// <summary>
/// 可编程构建管线的参数
/// </summary>
public SBPBuildParameters SBPParameters;
/// <summary> /// <summary>
/// 输出的根目录 /// 输出的根目录
/// </summary> /// </summary>
@@ -19,6 +46,11 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public BuildTarget BuildTarget; public BuildTarget BuildTarget;
/// <summary>
/// 构建管线
/// </summary>
public EBuildPipeline BuildPipeline;
/// <summary> /// <summary>
/// 构建模式 /// 构建模式
/// </summary> /// </summary>
@@ -30,7 +62,7 @@ namespace YooAsset.Editor
public int BuildVersion; public int BuildVersion;
/// <summary> /// <summary>
/// 内置资源的标记列表 /// 内置资源标签集合(首包资源标签)
/// 注意:分号为分隔符 /// 注意:分号为分隔符
/// </summary> /// </summary>
public string BuildinTags; public string BuildinTags;
@@ -45,17 +77,11 @@ namespace YooAsset.Editor
/// 启用可寻址资源定位 /// 启用可寻址资源定位
/// </summary> /// </summary>
public bool EnableAddressable = false; public bool EnableAddressable = false;
/// <summary> /// <summary>
/// 启用自动分包机制 /// 拷贝内置资源文件到StreamingAssets目录首包资源文件
/// 说明:自动分包机制可以实现资源零冗余
/// </summary> /// </summary>
public bool EnableAutoCollect = true; public bool CopyBuildinTagFiles = false;
/// <summary>
/// 追加文件扩展名
/// </summary>
public bool AppendFileExtension = false;
/// <summary> /// <summary>
@@ -63,16 +89,16 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public IEncryptionServices EncryptionServices = null; public IEncryptionServices EncryptionServices = null;
/// <summary>
/// 补丁文件名称的样式
/// </summary>
public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName;
/// <summary> /// <summary>
/// 压缩选项 /// 压缩选项
/// </summary> /// </summary>
public ECompressOption CompressOption = ECompressOption.Uncompressed; public ECompressOption CompressOption = ECompressOption.Uncompressed;
/// <summary>
/// 文件名附加上哈希值
/// </summary>
public bool AppendHash = false;
/// <summary> /// <summary>
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率) /// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
/// </summary> /// </summary>
@@ -83,18 +109,15 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool IgnoreTypeTreeChanges = true; public bool IgnoreTypeTreeChanges = true;
/// <summary>
/// 禁用名称查找资源(可以降内存并提高加载效率)
/// </summary>
public bool DisableLoadAssetByFileName = false;
/// <summary> /// <summary>
/// 获取内置标记列表 /// 获取内置资源标签列表(首包资源标签)
/// </summary> /// </summary>
public List<string> GetBuildinTags() public List<string> GetBuildinTags()
{ {
return StringUtility.StringToStringList(BuildinTags, ';'); return StringUtility.StringToStringList(BuildinTags, ';');
} }
} }
} }

View File

@@ -0,0 +1,138 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
namespace YooAsset.Editor
{
public class BuildParametersContext : IContextObject
{
private readonly System.Diagnostics.Stopwatch _buildWatch = new System.Diagnostics.Stopwatch();
/// <summary>
/// 构建参数
/// </summary>
public BuildParameters Parameters { private set; get; }
/// <summary>
/// 构建管线的输出目录
/// </summary>
public string PipelineOutputDirectory { private set; get; }
public BuildParametersContext(BuildParameters parameters)
{
Parameters = parameters;
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
if (parameters.BuildMode == EBuildMode.DryRunBuild)
PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}";
else if (parameters.BuildMode == EBuildMode.SimulateBuild)
PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}";
}
/// <summary>
/// 获取本次构建的补丁目录
/// </summary>
public string GetPackageDirectory()
{
return $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.BuildVersion}";
}
/// <summary>
/// 获取内置构建管线的构建选项
/// </summary>
public BuildAssetBundleOptions GetPipelineBuildOptions()
{
// For the new build system, unity always need BuildAssetBundleOptions.CollectDependencies and BuildAssetBundleOptions.DeterministicAssetBundle
// 除非设置ForceRebuildAssetBundle标记否则会进行增量打包
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
throw new Exception("Should never get here !");
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
{
opt |= BuildAssetBundleOptions.DryRunBuild;
return opt;
}
if (Parameters.CompressOption == ECompressOption.Uncompressed)
opt |= BuildAssetBundleOptions.UncompressedAssetBundle;
else if (Parameters.CompressOption == ECompressOption.LZ4)
opt |= BuildAssetBundleOptions.ChunkBasedCompression;
if (Parameters.BuildMode == EBuildMode.ForceRebuild)
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
if (Parameters.DisableWriteTypeTree)
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
if (Parameters.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.
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
return opt;
}
/// <summary>
/// 获取可编程构建管线的构建参数
/// </summary>
public UnityEditor.Build.Pipeline.BundleBuildParameters GetSBPBuildParameters()
{
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
throw new Exception("Should never get here !");
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
throw new Exception($"SBP not support {nameof(EBuildMode.DryRunBuild)} build mode !");
var targetGroup = BuildPipeline.GetBuildTargetGroup(Parameters.BuildTarget);
var buildParams = new UnityEditor.Build.Pipeline.BundleBuildParameters(Parameters.BuildTarget, targetGroup, PipelineOutputDirectory);
if (Parameters.CompressOption == ECompressOption.Uncompressed)
buildParams.BundleCompression = UnityEngine.BuildCompression.Uncompressed;
else if (Parameters.CompressOption == ECompressOption.LZMA)
buildParams.BundleCompression = UnityEngine.BuildCompression.LZMA;
else if (Parameters.CompressOption == ECompressOption.LZ4)
buildParams.BundleCompression = UnityEngine.BuildCompression.LZ4;
else
throw new System.NotImplementedException(Parameters.CompressOption.ToString());
if (Parameters.DisableWriteTypeTree)
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree;
if(Parameters.BuildMode == EBuildMode.ForceRebuild)
{
buildParams.UseCache = false;
}
else
{
buildParams.UseCache = true;
buildParams.CacheServerHost = Parameters.SBPParameters.CacheServerHost;
buildParams.CacheServerPort = Parameters.SBPParameters.CacheServerPort;
}
buildParams.WriteLinkXML = Parameters.SBPParameters.WriteLinkXML;
return buildParams;
}
/// <summary>
/// 获取构建的耗时(单位:秒)
/// </summary>
public float GetBuildingSeconds()
{
float seconds = _buildWatch.ElapsedMilliseconds / 1000f;
return seconds;
}
public void BeginWatch()
{
_buildWatch.Start();
}
public void StopWatch()
{
_buildWatch.Stop();
}
}
}

View File

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

View File

@@ -22,6 +22,11 @@ namespace YooAsset.Editor
/// 说明Meta文件记录的GUID /// 说明Meta文件记录的GUID
/// </summary> /// </summary>
public string AssetGUID; public string AssetGUID;
/// <summary>
/// 资源的分类标签
/// </summary>
public string[] AssetTags;
/// <summary> /// <summary>
/// 所属资源包名称 /// 所属资源包名称

View File

@@ -8,11 +8,31 @@ namespace YooAsset.Editor
[Serializable] [Serializable]
public class ReportBundleInfo public class ReportBundleInfo
{ {
public class FlagsData
{
public bool IsEncrypted { private set; get; }
public bool IsBuildin { private set; get; }
public bool IsRawFile { private set; get; }
public FlagsData(bool isEncrypted, bool isBuildin, bool isRawFile)
{
IsEncrypted = isEncrypted;
IsBuildin = isBuildin;
IsRawFile = isRawFile;
}
}
private FlagsData _flagData;
/// <summary> /// <summary>
/// 资源包名称 /// 资源包名称
/// </summary> /// </summary>
public string BundleName; public string BundleName;
/// <summary>
/// 文件名称
/// </summary>
public string FileName;
/// <summary> /// <summary>
/// 哈希值 /// 哈希值
/// </summary> /// </summary>
@@ -38,6 +58,26 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public int Flags; public int Flags;
/// <summary>
/// 获取标志位的解析数据
/// </summary>
public FlagsData GetFlagData()
{
if (_flagData == null)
{
BitMask32 value = Flags;
bool isEncrypted = value.Test(0);
bool isBuildin = value.Test(1);
bool isRawFile = value.Test(2);
_flagData = new FlagsData(isEncrypted, isBuildin, isRawFile);
}
return _flagData;
}
/// <summary>
/// 获取资源分类标签的字符串
/// </summary>
public string GetTagsString() public string GetTagsString()
{ {
if (Tags != null) if (Tags != null)
@@ -45,5 +85,16 @@ namespace YooAsset.Editor
else else
return string.Empty; return string.Empty;
} }
/// <summary>
/// 是否为原生文件
/// </summary>
public bool IsRawFile()
{
if (System.IO.Path.GetExtension(BundleName) == $".{YooAssetSettingsData.Setting.RawFileVariant}")
return true;
else
return false;
}
} }
} }

View File

@@ -8,6 +8,11 @@ namespace YooAsset.Editor
[Serializable] [Serializable]
public class ReportSummary public class ReportSummary
{ {
/// <summary>
/// YooAsset版本
/// </summary>
public string YooVersion;
/// <summary> /// <summary>
/// 引擎版本 /// 引擎版本
/// </summary> /// </summary>
@@ -16,7 +21,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 构建时间 /// 构建时间
/// </summary> /// </summary>
public string BuildTime; public string BuildDate;
/// <summary> /// <summary>
/// 构建耗时(单位:秒) /// 构建耗时(单位:秒)
@@ -28,6 +33,11 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public BuildTarget BuildTarget; public BuildTarget BuildTarget;
/// <summary>
/// 构建管线
/// </summary>
public EBuildPipeline BuildPipeline;
/// <summary> /// <summary>
/// 构建模式 /// 构建模式
/// </summary> /// </summary>
@@ -49,14 +59,9 @@ namespace YooAsset.Editor
public bool EnableAddressable; public bool EnableAddressable;
/// <summary> /// <summary>
/// 启用自动分包机制 /// 拷贝内置资源文件
/// </summary> /// </summary>
public bool EnableAutoCollect; public bool CopyBuildinTagFiles;
/// <summary>
/// 追加文件扩展名
/// </summary>
public bool AppendFileExtension;
/// <summary> /// <summary>
/// 自动收集着色器 /// 自动收集着色器
@@ -74,14 +79,14 @@ namespace YooAsset.Editor
public string EncryptionServicesClassName; public string EncryptionServicesClassName;
// 构建参数 // 构建参数
public EOutputNameStyle OutputNameStyle;
public ECompressOption CompressOption; public ECompressOption CompressOption;
public bool AppendHash;
public bool DisableWriteTypeTree; public bool DisableWriteTypeTree;
public bool IgnoreTypeTreeChanges; public bool IgnoreTypeTreeChanges;
public bool DisableLoadAssetByFileName;
// 构建结果 // 构建结果
public int AssetFileTotalCount; public int AssetFileTotalCount;
public int MainAssetTotalCount;
public int AllBundleTotalCount; public int AllBundleTotalCount;
public long AllBundleTotalSize; public long AllBundleTotalSize;
public int BuildinBundleTotalCount; public int BuildinBundleTotalCount;

View File

@@ -0,0 +1,24 @@

namespace YooAsset.Editor
{
/// <summary>
/// 构建结果
/// </summary>
public class BuildResult
{
/// <summary>
/// 构建是否成功
/// </summary>
public bool Success;
/// <summary>
/// 构建失败的任务
/// </summary>
public string FailedTask;
/// <summary>
/// 构建失败的信息
/// </summary>
public string FailedInfo;
}
}

View File

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

View File

@@ -14,45 +14,54 @@ namespace YooAsset.Editor
/// 执行构建流程 /// 执行构建流程
/// </summary> /// </summary>
/// <returns>如果成功返回TRUE否则返回FALSE</returns> /// <returns>如果成功返回TRUE否则返回FALSE</returns>
public static bool 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");
bool succeed = true; BuildResult buildResult = new BuildResult();
buildResult.Success = true;
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
{ {
var taskAttribute = task.GetType().GetCustomAttribute<TaskAttribute>(); var taskAttribute = task.GetType().GetCustomAttribute<TaskAttribute>();
Log($"---------------------------------------->{taskAttribute.Desc}"); Log($"---------------------------------------->{taskAttribute.Desc}<---------------------------------------");
task.Run(context); task.Run(context);
} }
catch (Exception e) catch (Exception e)
{ {
Debug.LogError($"Build task {task.GetType().Name} failed !"); buildResult.FailedTask = task.GetType().Name;
Debug.LogError($"Build error : {e}"); buildResult.FailedInfo = e.ToString();
succeed = false; buildResult.Success = false;
break; break;
} }
} }
// 返回运行结果 // 返回运行结果
return succeed; return buildResult;
} }
/// <summary> /// <summary>
/// 普通日志输出 /// 日志输出
/// </summary> /// </summary>
public static void Log(string info) public static void Log(string info)
{ {
if (EnableLog) if (EnableLog)
{ {
UnityEngine.Debug.Log(info); UnityEngine.Debug.Log(info);
} }
}
/// <summary>
/// 日志输出
/// </summary>
public static void Info(string info)
{
UnityEngine.Debug.Log(info);
} }
} }
} }

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Linq; using System.Linq;
using System.IO;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor; using UnityEditor;
@@ -18,12 +17,12 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
// 快速构建模式下跳过引擎构建 // 模拟构建模式下跳过引擎构建
var buildMode = buildParametersContext.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.FastRunBuild) if (buildMode == EBuildMode.SimulateBuild)
return; return;
BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions(); BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions();
@@ -46,7 +45,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 拷贝原生文件 /// 拷贝原生文件
/// </summary> /// </summary>
private void CopyRawBundle(BuildMapContext buildMapContext, AssetBundleBuilder.BuildParametersContext buildParametersContext) private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext)
{ {
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {

View File

@@ -0,0 +1,82 @@
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.Build.Pipeline;
using UnityEditor.Build.Pipeline.Interfaces;
namespace YooAsset.Editor
{
[TaskAttribute("资源构建内容打包")]
public class TaskBuilding_SBP : IBuildTask
{
public class SBPBuildResultContext : IContextObject
{
public IBundleBuildResults Results;
}
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
// 模拟构建模式下跳过引擎构建
var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.SimulateBuild)
return;
// 构建内容
var buildContent = new BundleBuildContent(buildMapContext.GetPipelineBuilds());
// 开始构建
IBundleBuildResults buildResults;
var buildParameters = buildParametersContext.GetSBPBuildParameters();
var taskList = DefaultBuildTasks.Create(DefaultBuildTasks.Preset.AssetBundleBuiltInShaderExtraction);
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
if (exitCode < 0)
{
throw new Exception($"构建过程中发生错误 : {exitCode}");
}
BuildRunner.Log("Unity引擎打包成功");
SBPBuildResultContext buildResultContext = new SBPBuildResultContext();
buildResultContext.Results = buildResults;
context.SetContextObject(buildResultContext);
// 添加Unity内置资源包信息
if (buildResults.BundleInfos.Keys.Any(t => t == YooAssetSettings.UnityBuiltInShadersBundleName))
{
BuildBundleInfo builtInBundleInfo = new BuildBundleInfo(YooAssetSettings.UnityBuiltInShadersBundleName);
buildMapContext.BundleInfos.Add(builtInBundleInfo);
}
// 拷贝原生文件
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
{
CopyRawBundle(buildMapContext, buildParametersContext);
}
}
/// <summary>
/// 拷贝原生文件
/// </summary>
private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext)
{
foreach (var bundleInfo in buildMapContext.BundleInfos)
{
if (bundleInfo.IsRawFile)
{
string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
foreach (var buildAsset in bundleInfo.BuildinAssets)
{
if (buildAsset.IsRawAsset)
EditorTools.CopyFile(buildAsset.AssetPath, dest, true);
}
}
}
}
}
}

View File

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

View File

@@ -12,8 +12,8 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
// 注意:我们只有在强制重建的时候才会拷贝 // 注意:我们只有在强制重建的时候才会拷贝
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
if (buildParameters.Parameters.BuildMode == EBuildMode.ForceRebuild) if (buildParameters.Parameters.CopyBuildinTagFiles)
{ {
// 清空流目录 // 清空流目录
AssetBundleBuilderHelper.ClearStreamingAssetsFolder(); AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
@@ -35,7 +35,7 @@ namespace YooAsset.Editor
continue; continue;
string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}"; string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{patchBundle.Hash}"; string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{patchBundle.FileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }

View File

@@ -1,8 +1,11 @@
using System; using System;
using System.IO; using System.Linq;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor.Build.Pipeline;
using UnityEditor.Build.Pipeline.Interfaces;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
[TaskAttribute("创建补丁清单文件")] [TaskAttribute("创建补丁清单文件")]
@@ -10,28 +13,36 @@ namespace YooAsset.Editor
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>(); CreatePatchManifestFile(context);
var encryptionContext = context.GetContextObject<TaskEncryption.EncryptionContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
CreatePatchManifestFile(buildParameters, buildMapContext, encryptionContext);
} }
/// <summary> /// <summary>
/// 创建补丁清单文件到输出目录 /// 创建补丁清单文件到输出目录
/// </summary> /// </summary>
private void CreatePatchManifestFile(AssetBundleBuilder.BuildParametersContext buildParameters, private void CreatePatchManifestFile(BuildContext context)
BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
var encryptionContext = context.GetContextObject<TaskEncryption.EncryptionContext>();
int resourceVersion = buildParameters.Parameters.BuildVersion; int resourceVersion = buildParameters.Parameters.BuildVersion;
// 创建新补丁清单 // 创建新补丁清单
PatchManifest patchManifest = new PatchManifest(); PatchManifest patchManifest = new PatchManifest();
patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable; patchManifest.FileVersion = YooAssetSettings.PatchManifestFileVersion;
patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion; patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion;
patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable;
patchManifest.OutputNameStyle = (int)buildParameters.Parameters.OutputNameStyle;
patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags; patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags;
patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext); patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest); patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest);
// 更新Unity内置资源包的引用关系
if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.SBPBuildResultContext>();
UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results);
}
// 创建补丁清单文件 // 创建补丁清单文件
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}"); BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}");
@@ -53,14 +64,12 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 获取资源包列表 /// 获取资源包列表
/// </summary> /// </summary>
private List<PatchBundle> GetAllPatchBundle(AssetBundleBuilder.BuildParametersContext buildParameters, private List<PatchBundle> GetAllPatchBundle(BuildParametersContext buildParameters, BuildMapContext buildMapContext,
BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext) TaskEncryption.EncryptionContext encryptionContext)
{ {
List<PatchBundle> result = new List<PatchBundle>(1000); List<PatchBundle> result = new List<PatchBundle>(1000);
// 内置标记列表
List<string> buildinTags = buildParameters.Parameters.GetBuildinTags(); List<string> buildinTags = buildParameters.Parameters.GetBuildinTags();
var buildMode = buildParameters.Parameters.BuildMode; var buildMode = buildParameters.Parameters.BuildMode;
bool standardBuild = buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild; bool standardBuild = buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild;
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
@@ -70,17 +79,11 @@ namespace YooAsset.Editor
string hash = GetFileHash(filePath, standardBuild); string hash = GetFileHash(filePath, standardBuild);
string crc32 = GetFileCRC(filePath, standardBuild); string crc32 = GetFileCRC(filePath, standardBuild);
long size = GetFileSize(filePath, standardBuild); long size = GetFileSize(filePath, standardBuild);
string[] tags = buildMapContext.GetAssetTags(bundleName); string[] tags = buildMapContext.GetBundleTags(bundleName);
bool isEncrypted = encryptionContext.IsEncryptFile(bundleName); bool isEncrypted = encryptionContext.IsEncryptFile(bundleName);
bool isBuildin = IsBuildinBundle(tags, buildinTags); bool isBuildin = IsBuildinBundle(tags, buildinTags);
bool isRawFile = bundleInfo.IsRawFile; bool isRawFile = bundleInfo.IsRawFile;
// 附加文件扩展名
if (buildParameters.Parameters.AppendFileExtension)
{
hash += bundleInfo.GetAppendExtension();
}
PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc32, size, tags); PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc32, size, tags);
patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile); patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile);
result.Add(patchBundle); result.Add(patchBundle);
@@ -90,7 +93,7 @@ namespace YooAsset.Editor
} }
private bool IsBuildinBundle(string[] bundleTags, List<string> buildinTags) private bool IsBuildinBundle(string[] bundleTags, List<string> buildinTags)
{ {
// 注意:没有任何标记的Bundle文件默认为内置文件 // 注意:没有任何分类标签的Bundle文件默认为内置文件
if (bundleTags.Length == 0) if (bundleTags.Length == 0)
return true; return true;
@@ -126,8 +129,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 获取资源列表 /// 获取资源列表
/// </summary> /// </summary>
private List<PatchAsset> GetAllPatchAsset(AssetBundleBuilder.BuildParametersContext buildParameters, private List<PatchAsset> GetAllPatchAsset(BuildParametersContext buildParameters, BuildMapContext buildMapContext, PatchManifest patchManifest)
BuildMapContext buildMapContext, PatchManifest patchManifest)
{ {
List<PatchAsset> result = new List<PatchAsset>(1000); List<PatchAsset> result = new List<PatchAsset>(1000);
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
@@ -141,6 +143,7 @@ namespace YooAsset.Editor
else else
patchAsset.Address = string.Empty; patchAsset.Address = string.Empty;
patchAsset.AssetPath = assetInfo.AssetPath; patchAsset.AssetPath = assetInfo.AssetPath;
patchAsset.AssetTags = assetInfo.AssetTags.ToArray();
patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest); patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest);
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest); patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
result.Add(patchAsset); result.Add(patchAsset);
@@ -174,5 +177,45 @@ namespace YooAsset.Editor
} }
throw new Exception($"Not found bundle name : {bundleName}"); throw new Exception($"Not found bundle name : {bundleName}");
} }
/// <summary>
/// 更新Unity内置资源包的引用关系
/// </summary>
private void UpdateBuiltInBundleReference(PatchManifest patchManifest, IBundleBuildResults buildResults)
{
// 获取所有依赖内置资源包的资源包列表
List<string> builtInBundleReferenceList = new List<string>();
foreach (var valuePair in buildResults.BundleInfos)
{
if (valuePair.Value.Dependencies.Any(t => t == YooAssetSettings.UnityBuiltInShadersBundleName))
builtInBundleReferenceList.Add(valuePair.Key);
}
// 检测依赖交集并更新依赖ID
int builtInBundleId = patchManifest.BundleList.Count - 1;
foreach (var patchAsset in patchManifest.AssetList)
{
List<string> dependBundles = GetPatchAssetAllDependBundles(patchManifest, patchAsset);
List<string> conflictAssetPathList = dependBundles.Intersect(builtInBundleReferenceList).ToList();
if (conflictAssetPathList.Count > 0)
{
List<int> newDependIDs = new List<int>(patchAsset.DependIDs);
newDependIDs.Add(builtInBundleId);
patchAsset.DependIDs = newDependIDs.ToArray();
}
}
}
private List<string> GetPatchAssetAllDependBundles(PatchManifest patchManifest, PatchAsset patchAsset)
{
List<string> result = new List<string>();
string mainBundle = patchManifest.BundleList[patchAsset.BundleID].BundleName;
result.Add(mainBundle);
foreach (var dependID in patchAsset.DependIDs)
{
string dependBundle = patchManifest.BundleList[dependID].BundleName;
result.Add(dependBundle);
}
return result;
}
} }
} }

View File

@@ -8,7 +8,7 @@ namespace YooAsset.Editor
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMode = buildParameters.Parameters.BuildMode; var buildMode = buildParameters.Parameters.BuildMode;
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
{ {
@@ -19,7 +19,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 拷贝补丁文件到补丁包目录 /// 拷贝补丁文件到补丁包目录
/// </summary> /// </summary>
private void CopyPatchFiles(AssetBundleBuilder.BuildParametersContext buildParameters) private void CopyPatchFiles(BuildParametersContext buildParameters)
{ {
int resourceVersion = buildParameters.Parameters.BuildVersion; int resourceVersion = buildParameters.Parameters.BuildVersion;
string packageDirectory = buildParameters.GetPackageDirectory(); string packageDirectory = buildParameters.GetPackageDirectory();
@@ -54,18 +54,38 @@ namespace YooAsset.Editor
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝UnityManifest序列化文件 if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{ {
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; // 拷贝构建日志
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; {
EditorTools.CopyFile(sourcePath, destPath, true); string sourcePath = $"{buildParameters.PipelineOutputDirectory}/buildlogtep.json";
} string destPath = $"{packageDirectory}/buildlogtep.json";
EditorTools.CopyFile(sourcePath, destPath, true);
}
// 拷贝UnityManifest文本文件 // 拷贝代码防裁剪配置
if (buildParameters.Parameters.SBPParameters.WriteLinkXML)
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/link.xml";
string destPath = $"{packageDirectory}/link.xml";
EditorTools.CopyFile(sourcePath, destPath, true);
}
}
else
{ {
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest"; // 拷贝UnityManifest序列化文件
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest"; {
EditorTools.CopyFile(sourcePath, destPath, true); string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}";
string destPath = $"{packageDirectory}/{YooAssetSettings.OutputFolderName}";
EditorTools.CopyFile(sourcePath, destPath, true);
}
// 拷贝UnityManifest文本文件
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest";
string destPath = $"{packageDirectory}/{YooAssetSettings.OutputFolderName}.manifest";
EditorTools.CopyFile(sourcePath, destPath, true);
}
} }
// 拷贝所有补丁文件 // 拷贝所有补丁文件
@@ -75,7 +95,7 @@ namespace YooAsset.Editor
foreach (var patchBundle in patchManifest.BundleList) foreach (var patchBundle in patchManifest.BundleList)
{ {
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}"; string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}";
string destPath = $"{packageDirectory}/{patchBundle.Hash}"; string destPath = $"{packageDirectory}/{patchBundle.FileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount); EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount);
} }

View File

@@ -10,43 +10,58 @@ namespace YooAsset.Editor
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
CreateReportFile(buildParameters, buildMapContext); buildParameters.StopWatch();
var buildMode = buildParameters.Parameters.BuildMode;
if (buildMode != EBuildMode.SimulateBuild)
{
CreateReportFile(buildParameters, buildMapContext);
}
else
{
float buildSeconds = buildParameters.GetBuildingSeconds();
BuildRunner.Info($"Build time consuming {buildSeconds} seconds.");
}
} }
private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext) private void CreateReportFile(BuildParametersContext buildParameters, BuildMapContext buildMapContext)
{ {
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
BuildReport buildReport = new BuildReport(); BuildReport buildReport = new BuildReport();
buildParameters.StopWatch();
// 概述信息 // 概述信息
{ {
#if UNITY_2019_4_OR_NEWER
UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(BuildReport).Assembly);
if (packageInfo != null)
buildReport.Summary.YooVersion = packageInfo.version;
#endif
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion; buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
buildReport.Summary.BuildTime = DateTime.Now.ToString(); buildReport.Summary.BuildDate = DateTime.Now.ToString();
buildReport.Summary.BuildSeconds = buildParameters.GetBuildingSeconds(); buildReport.Summary.BuildSeconds = (int)buildParameters.GetBuildingSeconds();
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget; buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
buildReport.Summary.BuildPipeline = buildParameters.Parameters.BuildPipeline;
buildReport.Summary.BuildMode = buildParameters.Parameters.BuildMode; buildReport.Summary.BuildMode = buildParameters.Parameters.BuildMode;
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion; buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags; buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable; buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable;
buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect; buildReport.Summary.CopyBuildinTagFiles = buildParameters.Parameters.CopyBuildinTagFiles;
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension; buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
buildReport.Summary.AutoCollectShaders = AssetBundleGrouperSettingData.Setting.AutoCollectShaders; buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
buildReport.Summary.ShadersBundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName;
buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ? buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ?
"null" : buildParameters.Parameters.EncryptionServices.GetType().FullName; "null" : buildParameters.Parameters.EncryptionServices.GetType().FullName;
// 构建参数 // 构建参数
buildReport.Summary.OutputNameStyle = buildParameters.Parameters.OutputNameStyle;
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption; buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption;
buildReport.Summary.AppendHash = buildParameters.Parameters.AppendHash;
buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree; buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges; buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges;
buildReport.Summary.DisableLoadAssetByFileName = buildParameters.Parameters.DisableLoadAssetByFileName;
// 构建结果 // 构建结果
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount; buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
buildReport.Summary.MainAssetTotalCount = GetMainAssetCount(patchManifest);
buildReport.Summary.AllBundleTotalCount = GetAllBundleCount(patchManifest); buildReport.Summary.AllBundleTotalCount = GetAllBundleCount(patchManifest);
buildReport.Summary.AllBundleTotalSize = GetAllBundleSize(patchManifest); buildReport.Summary.AllBundleTotalSize = GetAllBundleSize(patchManifest);
buildReport.Summary.BuildinBundleTotalCount = GetBuildinBundleCount(patchManifest); buildReport.Summary.BuildinBundleTotalCount = GetBuildinBundleCount(patchManifest);
@@ -65,6 +80,7 @@ namespace YooAsset.Editor
ReportAssetInfo reportAssetInfo = new ReportAssetInfo(); ReportAssetInfo reportAssetInfo = new ReportAssetInfo();
reportAssetInfo.Address = patchAsset.Address; reportAssetInfo.Address = patchAsset.Address;
reportAssetInfo.AssetPath = patchAsset.AssetPath; reportAssetInfo.AssetPath = patchAsset.AssetPath;
reportAssetInfo.AssetTags = patchAsset.AssetTags;
reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath); reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath);
reportAssetInfo.MainBundleName = mainBundle.BundleName; reportAssetInfo.MainBundleName = mainBundle.BundleName;
reportAssetInfo.MainBundleSize = mainBundle.SizeBytes; reportAssetInfo.MainBundleSize = mainBundle.SizeBytes;
@@ -79,6 +95,7 @@ namespace YooAsset.Editor
{ {
ReportBundleInfo reportBundleInfo = new ReportBundleInfo(); ReportBundleInfo reportBundleInfo = new ReportBundleInfo();
reportBundleInfo.BundleName = patchBundle.BundleName; reportBundleInfo.BundleName = patchBundle.BundleName;
reportBundleInfo.FileName = patchBundle.FileName;
reportBundleInfo.Hash = patchBundle.Hash; reportBundleInfo.Hash = patchBundle.Hash;
reportBundleInfo.CRC = patchBundle.CRC; reportBundleInfo.CRC = patchBundle.CRC;
reportBundleInfo.SizeBytes = patchBundle.SizeBytes; reportBundleInfo.SizeBytes = patchBundle.SizeBytes;
@@ -144,6 +161,10 @@ namespace YooAsset.Editor
return result; return result;
} }
private int GetMainAssetCount(PatchManifest patchManifest)
{
return patchManifest.AssetList.Count;
}
private int GetAllBundleCount(PatchManifest patchManifest) private int GetAllBundleCount(PatchManifest patchManifest)
{ {
return patchManifest.BundleList.Count; return patchManifest.BundleList.Count;

View File

@@ -24,7 +24,7 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
var buildMode = buildParameters.Parameters.BuildMode; var buildMode = buildParameters.Parameters.BuildMode;
@@ -45,7 +45,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 加密文件 /// 加密文件
/// </summary> /// </summary>
private List<string> EncryptFiles(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext) private List<string> EncryptFiles(BuildParametersContext buildParameters, BuildMapContext buildMapContext)
{ {
var encryptionServices = buildParameters.Parameters.EncryptionServices; var encryptionServices = buildParameters.Parameters.EncryptionServices;

View File

@@ -12,7 +12,8 @@ namespace YooAsset.Editor
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildMapContext = BuildMapCreater.CreateBuildMap(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode);
context.SetContextObject(buildMapContext); context.SetContextObject(buildMapContext);
BuildRunner.Log("构建内容准备完毕!"); BuildRunner.Log("构建内容准备完毕!");

View File

@@ -11,7 +11,7 @@ namespace YooAsset.Editor
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
buildParameters.BeginWatch(); buildParameters.BeginWatch();
// 检测构建平台是否合法 // 检测构建平台是否合法
@@ -26,28 +26,39 @@ namespace YooAsset.Editor
if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory)) if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory))
throw new Exception("输出目录不能为空"); throw new Exception("输出目录不能为空");
// 检测当前是否正在构建资源包
if (BuildPipeline.isBuildingPlayer)
throw new Exception("当前正在构建资源包,请结束后再试");
// 检测是否有未保存场景
if (EditorTools.HasDirtyScenes())
throw new Exception("检测到未保存的场景文件");
// 保存改动的资源
AssetDatabase.SaveAssets();
// 增量更新时候的必要检测 // 增量更新时候的必要检测
var buildMode = buildParameters.Parameters.BuildMode; var buildMode = buildParameters.Parameters.BuildMode;
if (buildMode == EBuildMode.IncrementalBuild) if (buildMode == EBuildMode.IncrementalBuild)
{ {
// 检测历史版本是否存在 // 检测历史版本是否存在
if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot) == false) if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot))
throw new Exception("没有发现任何历史版本,请尝试强制重建"); {
// 检测构建版本是否合法
int maxPackageVersion = AssetBundleBuilderHelper.GetMaxPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot);
if (buildParameters.Parameters.BuildVersion <= maxPackageVersion)
throw new Exception("构建版本不能小于历史版本");
// 检测构建版本是否合法 // 检测补丁包是否已经存在
int maxPackageVersion = AssetBundleBuilderHelper.GetMaxPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot); string packageDirectory = buildParameters.GetPackageDirectory();
if (buildParameters.Parameters.BuildVersion <= maxPackageVersion) if (Directory.Exists(packageDirectory))
throw new Exception("构建版本不能小于历史版本"); throw new Exception($"补丁包已经存在:{packageDirectory}");
// 检测补丁包是否已经存在 // 检测内置资源分类标签是否一致
string packageDirectory = buildParameters.GetPackageDirectory(); var oldPatchManifest = AssetBundleBuilderHelper.GetOldPatchManifest(buildParameters.PipelineOutputDirectory);
if (Directory.Exists(packageDirectory)) if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags)
throw new Exception($"补丁包已经存在:{packageDirectory}"); throw new Exception($"增量更新时内置资源标签必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}");
}
// 检测内置资源分类标签是否一致
var oldPatchManifest = AssetBundleBuilderHelper.GetOldPatchManifest(buildParameters.PipelineOutputDirectory);
if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags)
throw new Exception($"增量更新时内置资源标签必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}");
} }
// 如果是强制重建 // 如果是强制重建

View File

@@ -13,10 +13,10 @@ namespace YooAsset.Editor
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
// 快速构建模式下跳过验证 // 模拟构建模式下跳过验证
if (buildParametersContext.Parameters.BuildMode == EBuildMode.FastRunBuild) if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
return; return;
// 验证构建结果 // 验证构建结果
@@ -32,58 +32,26 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest) private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest)
{ {
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>(); var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
string[] buildedBundles = unityManifest.GetAllAssetBundles(); string[] buildedBundles = unityManifest.GetAllAssetBundles();
// 1. 过滤掉原生Bundle // 1. 过滤掉原生Bundle
List<BuildBundleInfo> expectBundles = new List<BuildBundleInfo>(buildedBundles.Length); string[] expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToArray();
foreach(var bundleInfo in buildMapContext.BundleInfos)
{
if (bundleInfo.IsRawFile == false)
expectBundles.Add(bundleInfo);
}
// 2. 验证数量 // 2. 验证Bundle
if (buildedBundles.Length != expectBundles.Count) List<string> intersectBundleList = buildedBundles.Except(expectBundles).ToList();
if (intersectBundleList.Count > 0)
{ {
Debug.LogWarning($"构建过程中可能存在无效的资源导致和预期构建的Bundle数量不一致"); foreach (var intersectBundle in intersectBundleList)
}
// 3. 正向验证Bundle
foreach (var bundleName in buildedBundles)
{
if (buildMapContext.IsContainsBundle(bundleName) == false)
{ {
throw new Exception($"Should never get here !"); Debug.LogWarning($"差异资源包: {intersectBundle}");
} }
throw new System.Exception("存在差异资源包!请查看警告信息!");
} }
// 4. 反向验证Bundle // 3. 验证Asset
bool isPass = true; bool isPass = true;
foreach (var expectBundle in expectBundles)
{
bool isMatch = false;
foreach (var buildedBundle in buildedBundles)
{
if (buildedBundle == expectBundle.BundleName)
{
isMatch = true;
break;
}
}
if (isMatch == false)
{
isPass = false;
Debug.LogWarning($"没有找到预期构建的Bundle文件 : {expectBundle.BundleName}");
}
}
if(isPass == false)
{
throw new Exception("构建结果验证没有通过,请参考警告日志!");
}
// 5. 验证Asset
var buildMode = buildParameters.Parameters.BuildMode; var buildMode = buildParameters.Parameters.BuildMode;
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
{ {
@@ -96,38 +64,14 @@ namespace YooAsset.Editor
if (expectBuildinAssetPaths.Length != allBuildinAssetPaths.Length) if (expectBuildinAssetPaths.Length != allBuildinAssetPaths.Length)
{ {
Debug.LogWarning($"构建的Bundle文件内的资源对象数量和预期不匹配 : {buildedBundle}"); Debug.LogWarning($"构建的Bundle文件内的资源对象数量和预期不匹配 : {buildedBundle}");
var intersectAssetList = expectBuildinAssetPaths.Except(allBuildinAssetPaths).ToList();
foreach (var intersectAssset in intersectAssetList)
{
Debug.LogWarning($"构建失败的资源对象路径为 : {intersectAssset}");
}
isPass = false; isPass = false;
continue; continue;
} }
foreach (var buildinAssetPath in allBuildinAssetPaths)
{
var guid = AssetDatabase.AssetPathToGUID(buildinAssetPath);
if (string.IsNullOrEmpty(guid))
{
Debug.LogWarning($"无效的资源路径,请检查路径是否带有特殊符号或中文:{buildinAssetPath}");
isPass = false;
continue;
}
bool isMatch = false;
foreach (var exceptBuildAssetPath in expectBuildinAssetPaths)
{
var guidExcept = AssetDatabase.AssetPathToGUID(exceptBuildAssetPath);
if (guid == guidExcept)
{
isMatch = true;
break;
}
}
if (isMatch == false)
{
Debug.LogWarning($"在构建的Bundle文件里发现了没有匹配的资源对象{buildinAssetPath}");
isPass = false;
continue;
}
}
EditorTools.DisplayProgressBar("验证构建结果", ++progressValue, buildedBundles.Length); EditorTools.DisplayProgressBar("验证构建结果", ++progressValue, buildedBundles.Length);
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();
@@ -137,7 +81,6 @@ namespace YooAsset.Editor
} }
} }
// 卸载所有加载的Bundle
BuildRunner.Log("构建结果验证成功!"); BuildRunner.Log("构建结果验证成功!");
} }

View File

@@ -0,0 +1,60 @@
using System;
using System.Linq;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.Build.Pipeline.Interfaces;
namespace YooAsset.Editor
{
[TaskAttribute("验证构建结果")]
public class TaskVerifyBuildResult_SBP : IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
// 模拟构建模式下跳过验证
if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
return;
// 验证构建结果
if (buildParametersContext.Parameters.VerifyBuildingResult)
{
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.SBPBuildResultContext>();
VerifyingBuildingResult(context, buildResultContext.Results);
}
}
/// <summary>
/// 验证构建结果
/// </summary>
private void VerifyingBuildingResult(BuildContext context, IBundleBuildResults buildResults)
{
var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
// 1. 移除特定Bundle
List<string> buildedBundles = buildResults.BundleInfos.Keys.ToList();
buildedBundles.Remove(YooAssetSettings.UnityBuiltInShadersBundleName);
// 2. 过滤掉原生Bundle
List<string> expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToList();
// 3. 验证Bundle
List<string> intersectBundleList = buildedBundles.Except(expectBundles).ToList();
if (intersectBundleList.Count > 0)
{
foreach (var intersectBundle in intersectBundleList)
{
Debug.LogWarning($"差异资源包: {intersectBundle}");
}
throw new System.Exception("存在差异资源包!请查看警告信息!");
}
BuildRunner.Log("构建结果验证成功!");
}
}
}

View File

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

View File

@@ -16,14 +16,14 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
IncrementalBuild, IncrementalBuild,
/// <summary>
/// 快速构建模式
/// </summary>
FastRunBuild,
/// <summary> /// <summary>
/// 演练构建模式 /// 演练构建模式
/// </summary> /// </summary>
DryRunBuild, DryRunBuild,
/// <summary>
/// 模拟构建模式
/// </summary>
SimulateBuild,
} }
} }

View File

@@ -0,0 +1,19 @@

namespace YooAsset.Editor
{
/// <summary>
/// 构建管线类型
/// </summary>
public enum EBuildPipeline
{
/// <summary>
/// 传统内置构建管线
/// </summary>
BuiltinBuildPipeline,
/// <summary>
/// 可编程构建管线
/// </summary>
ScriptableBuildPipeline,
}
}

View File

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

View File

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

namespace YooAsset.Editor
{
/// <summary>
/// 输出文件名称的样式
/// </summary>
public enum EOutputNameStyle
{
/// <summary>
/// 000000000000000f000000000000000
/// </summary>
HashName = 1,
/// <summary>
/// 000000000000000f000000000000000.bundle
/// </summary>
HashName_Extension = 2,
/// <summary>
/// bundle_name_000000000000000f000000000000000
/// </summary>
BundleName_HashName = 3,
/// <summary>
/// bundle_name_000000000000000f000000000000000.bundle
/// </summary>
BundleName_HashName_Extension = 4,
}
}

View File

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

View File

@@ -51,13 +51,13 @@ namespace YooAsset.Editor
if (CollectorType == ECollectorType.None) if (CollectorType == ECollectorType.None)
return false; return false;
if (AssetBundleGrouperSettingData.HasAddressRuleName(AddressRuleName) == false) if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
return false; return false;
if (AssetBundleGrouperSettingData.HasPackRuleName(PackRuleName) == false) if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
return false; return false;
if (AssetBundleGrouperSettingData.HasFilterRuleName(FilterRuleName) == false) if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
return false; return false;
return true; return true;
@@ -74,21 +74,28 @@ namespace YooAsset.Editor
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 (AssetBundleGrouperSettingData.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 (AssetBundleGrouperSettingData.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 (AssetBundleGrouperSettingData.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 List<CollectAssetInfo> GetAllCollectAssets(AssetBundleGrouper grouper) public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode, AssetBundleCollectorGroup group)
{ {
// 注意:模拟构建模式下只收集主资源
if (buildMode == EBuildMode.SimulateBuild)
{
if (CollectorType != ECollectorType.MainAssetCollector)
return new List<CollectAssetInfo>();
}
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000); Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
bool isRawAsset = PackRuleName == nameof(PackRawFile); bool isRawAsset = PackRuleName == nameof(PackRawFile);
@@ -97,7 +104,7 @@ namespace YooAsset.Editor
throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}"); throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}");
if (string.IsNullOrEmpty(CollectPath)) if (string.IsNullOrEmpty(CollectPath))
throw new Exception($"The collect path is null or empty in grouper : {grouper.GrouperName}"); throw new Exception($"The collect path is null or empty in group : {group.GroupName}");
// 收集打包资源 // 收集打包资源
if (AssetDatabase.IsValidFolder(CollectPath)) if (AssetDatabase.IsValidFolder(CollectPath))
@@ -110,7 +117,7 @@ namespace YooAsset.Editor
{ {
if (result.ContainsKey(assetPath) == false) if (result.ContainsKey(assetPath) == false)
{ {
var collectAssetInfo = CreateCollectAssetInfo(grouper, assetPath, isRawAsset); var collectAssetInfo = CreateCollectAssetInfo(buildMode, group, assetPath, isRawAsset);
result.Add(assetPath, collectAssetInfo); result.Add(assetPath, collectAssetInfo);
} }
else else
@@ -125,7 +132,7 @@ namespace YooAsset.Editor
string assetPath = CollectPath; string assetPath = CollectPath;
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath)) if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
{ {
var collectAssetInfo = CreateCollectAssetInfo(grouper, assetPath, isRawAsset); var collectAssetInfo = CreateCollectAssetInfo(buildMode, group, assetPath, isRawAsset);
result.Add(assetPath, collectAssetInfo); result.Add(assetPath, collectAssetInfo);
} }
else else
@@ -135,7 +142,7 @@ namespace YooAsset.Editor
} }
// 检测可寻址地址是否重复 // 检测可寻址地址是否重复
if (AssetBundleGrouperSettingData.Setting.EnableAddressable) if (AssetBundleCollectorSettingData.Setting.EnableAddressable)
{ {
HashSet<string> adressTemper = new HashSet<string>(); HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result) foreach (var collectInfoPair in result)
@@ -155,28 +162,50 @@ namespace YooAsset.Editor
return result.Values.ToList(); return result.Values.ToList();
} }
private CollectAssetInfo CreateCollectAssetInfo(AssetBundleGrouper grouper, string assetPath, bool isRawAsset) private CollectAssetInfo CreateCollectAssetInfo(EBuildMode buildMode, AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
{ {
string address = GetAddress(grouper, assetPath); string address = GetAddress(group, assetPath);
string bundleName = GetBundleName(grouper, assetPath); string bundleName = GetBundleName(group, assetPath);
List<string> assetTags = GetAssetTags(grouper); List<string> assetTags = GetAssetTags(group);
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset); CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset);
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
// 注意:模拟构建模式下不需要收集依赖资源
if (buildMode == EBuildMode.SimulateBuild)
collectAssetInfo.DependAssets = new List<string>();
else
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
return collectAssetInfo; return collectAssetInfo;
} }
private bool IsValidateAsset(string assetPath) private bool IsValidateAsset(string assetPath)
{ {
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false) if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
{
UnityEngine.Debug.LogError($"Invalid asset path : {assetPath}");
return false; return false;
}
if (assetPath.Contains("/Gizmos/"))
{
UnityEngine.Debug.LogWarning($"Cannot pack gizmos asset : {assetPath}");
return false;
}
// 忽略文件夹
if (AssetDatabase.IsValidFolder(assetPath)) if (AssetDatabase.IsValidFolder(assetPath))
return false; return false;
// 注意:忽略编辑器下的类型资源 // 忽略编辑器下的类型资源
Type type = AssetDatabase.GetMainAssetTypeAtPath(assetPath); Type type = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (type == typeof(LightingDataAsset)) if (type == typeof(LightingDataAsset))
return false; return false;
// 忽略Unity无法识别的无效文件
if (type == typeof(UnityEditor.DefaultAsset))
{
UnityEngine.Debug.LogWarning($"Cannot pack default asset : {assetPath}");
return false;
}
string ext = System.IO.Path.GetExtension(assetPath); string ext = System.IO.Path.GetExtension(assetPath);
if (ext == "" || ext == ".dll" || ext == ".cs" || ext == ".js" || ext == ".boo" || ext == ".meta" || ext == ".cginc") if (ext == "" || ext == ".dll" || ext == ".cs" || ext == ".js" || ext == ".boo" || ext == ".meta" || ext == ".cginc")
return false; return false;
@@ -186,7 +215,7 @@ namespace YooAsset.Editor
private bool IsCollectAsset(string assetPath) private bool IsCollectAsset(string assetPath)
{ {
// 如果收集全路径着色器 // 如果收集全路径着色器
if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders) if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders)
{ {
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (assetType == typeof(UnityEngine.Shader)) if (assetType == typeof(UnityEngine.Shader))
@@ -194,41 +223,41 @@ namespace YooAsset.Editor
} }
// 根据规则设置过滤资源文件 // 根据规则设置过滤资源文件
IFilterRule filterRuleInstance = AssetBundleGrouperSettingData.GetFilterRuleInstance(FilterRuleName); IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath)); return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath));
} }
private string GetAddress(AssetBundleGrouper grouper, string assetPath) private string GetAddress(AssetBundleCollectorGroup group, string assetPath)
{ {
if (CollectorType != ECollectorType.MainAssetCollector) if (CollectorType != ECollectorType.MainAssetCollector)
return string.Empty; return string.Empty;
IAddressRule addressRuleInstance = AssetBundleGrouperSettingData.GetAddressRuleInstance(AddressRuleName); IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName);
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, grouper.GrouperName)); string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName));
return adressValue; return adressValue;
} }
private string GetBundleName(AssetBundleGrouper grouper, string assetPath) private string GetBundleName(AssetBundleCollectorGroup group, string assetPath)
{ {
// 如果自动收集所有的着色器 // 如果自动收集所有的着色器
if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders) if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders)
{ {
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (assetType == typeof(UnityEngine.Shader)) if (assetType == typeof(UnityEngine.Shader))
{ {
string bundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName; string bundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
return EditorTools.GetRegularPath(bundleName).ToLower(); return EditorTools.GetRegularPath(bundleName).ToLower();
} }
} }
// 根据规则设置获取资源包名称 // 根据规则设置获取资源包名称
{ {
IPackRule packRuleInstance = AssetBundleGrouperSettingData.GetPackRuleInstance(PackRuleName); IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, grouper.GrouperName)); string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, group.GroupName));
return EditorTools.GetRegularPath(bundleName).ToLower(); return EditorTools.GetRegularPath(bundleName).ToLower();
} }
} }
private List<string> GetAssetTags(AssetBundleGrouper grouper) private List<string> GetAssetTags(AssetBundleCollectorGroup group)
{ {
List<string> tags = StringUtility.StringToStringList(grouper.AssetTags, ';'); List<string> tags = StringUtility.StringToStringList(group.AssetTags, ';');
List<string> temper = StringUtility.StringToStringList(AssetTags, ';'); List<string> temper = StringUtility.StringToStringList(AssetTags, ';');
tags.AddRange(temper); tags.AddRange(temper);
return tags; return tags;

View File

@@ -8,14 +8,18 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleGrouperConfig public class AssetBundleCollectorConfig
{ {
public const string XmlShader = "Shader"; public const string ConfigVersion = "1.0";
public const string XmlVersion = "Version";
public const string XmlCommon = "Common";
public const string XmlEnableAddressable = "AutoAddressable";
public const string XmlAutoCollectShader = "AutoCollectShader"; public const string XmlAutoCollectShader = "AutoCollectShader";
public const string XmlShaderBundleName = "ShaderBundleName"; public const string XmlShaderBundleName = "ShaderBundleName";
public const string XmlGrouper = "Grouper"; public const string XmlGroup = "Group";
public const string XmlGrouperName = "GrouperName"; public const string XmlGroupName = "GroupName";
public const string XmlGrouperDesc = "GrouperDesc"; 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 XmlCollectorType = "CollectType"; public const string XmlCollectorType = "CollectType";
@@ -40,43 +44,54 @@ namespace YooAsset.Editor
xml.Load(filePath); xml.Load(filePath);
XmlElement root = xml.DocumentElement; XmlElement root = xml.DocumentElement;
// 读取着色器配置 // 读取配置版本
string configVersion = root.GetAttribute(XmlVersion);
if(configVersion != ConfigVersion)
{
throw new Exception($"The config version is invalid : {configVersion}");
}
// 读取公共配置
bool enableAddressable = false;
bool autoCollectShaders = false; bool autoCollectShaders = false;
string shaderBundleName = string.Empty; string shaderBundleName = string.Empty;
var shaderNodeList = root.GetElementsByTagName(XmlShader); var commonNodeList = root.GetElementsByTagName(XmlCommon);
if (shaderNodeList.Count > 0) if (commonNodeList.Count > 0)
{ {
XmlElement shaderElement = shaderNodeList[0] as XmlElement; XmlElement commonElement = commonNodeList[0] as XmlElement;
if (shaderElement.HasAttribute(XmlAutoCollectShader) == false) if (commonElement.HasAttribute(XmlEnableAddressable) == false)
throw new Exception($"Not found attribute {XmlAutoCollectShader} in {XmlShader}"); throw new Exception($"Not found attribute {XmlEnableAddressable} in {XmlCommon}");
if (shaderElement.HasAttribute(XmlShaderBundleName) == false) if (commonElement.HasAttribute(XmlAutoCollectShader) == false)
throw new Exception($"Not found attribute {XmlShaderBundleName} in {XmlShader}"); throw new Exception($"Not found attribute {XmlAutoCollectShader} in {XmlCommon}");
if (commonElement.HasAttribute(XmlShaderBundleName) == false)
throw new Exception($"Not found attribute {XmlShaderBundleName} in {XmlCommon}");
autoCollectShaders = shaderElement.GetAttribute(XmlAutoCollectShader) == "True" ? true : false; enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
shaderBundleName = shaderElement.GetAttribute(XmlShaderBundleName); autoCollectShaders = commonElement.GetAttribute(XmlAutoCollectShader) == "True" ? true : false;
shaderBundleName = commonElement.GetAttribute(XmlShaderBundleName);
} }
// 读取分组配置 // 读取分组配置
List<AssetBundleGrouper> grouperTemper = new List<AssetBundleGrouper>(); List<AssetBundleCollectorGroup> groupTemper = new List<AssetBundleCollectorGroup>();
var grouperNodeList = root.GetElementsByTagName(XmlGrouper); var groupNodeList = root.GetElementsByTagName(XmlGroup);
foreach (var grouperNode in grouperNodeList) foreach (var groupNode in groupNodeList)
{ {
XmlElement grouperElement = grouperNode as XmlElement; XmlElement groupElement = groupNode as XmlElement;
if (grouperElement.HasAttribute(XmlGrouperName) == false) if (groupElement.HasAttribute(XmlGroupName) == false)
throw new Exception($"Not found attribute {XmlGrouperName} in {XmlGrouper}"); throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}");
if (grouperElement.HasAttribute(XmlGrouperDesc) == false) if (groupElement.HasAttribute(XmlGroupDesc) == false)
throw new Exception($"Not found attribute {XmlGrouperDesc} in {XmlGrouper}"); throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}");
if (grouperElement.HasAttribute(XmlAssetTags) == false) if (groupElement.HasAttribute(XmlAssetTags) == false)
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGrouper}"); throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}");
AssetBundleGrouper grouper = new AssetBundleGrouper(); AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
grouper.GrouperName = grouperElement.GetAttribute(XmlGrouperName); group.GroupName = groupElement.GetAttribute(XmlGroupName);
grouper.GrouperDesc = grouperElement.GetAttribute(XmlGrouperDesc); group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc);
grouper.AssetTags = grouperElement.GetAttribute(XmlAssetTags); group.AssetTags = groupElement.GetAttribute(XmlAssetTags);
grouperTemper.Add(grouper); groupTemper.Add(group);
// 读取收集器配置 // 读取收集器配置
var collectorNodeList = grouperElement.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;
@@ -100,16 +115,17 @@ namespace YooAsset.Editor
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule); collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule); collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags); ; collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags); ;
grouper.Collectors.Add(collector); group.Collectors.Add(collector);
} }
} }
// 保存配置数据 // 保存配置数据
AssetBundleGrouperSettingData.ClearAll(); AssetBundleCollectorSettingData.ClearAll();
AssetBundleGrouperSettingData.Setting.AutoCollectShaders = autoCollectShaders; AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable;
AssetBundleGrouperSettingData.Setting.ShadersBundleName = shaderBundleName; AssetBundleCollectorSettingData.Setting.AutoCollectShaders = autoCollectShaders;
AssetBundleGrouperSettingData.Setting.Groupers.AddRange(grouperTemper); AssetBundleCollectorSettingData.Setting.ShadersBundleName = shaderBundleName;
AssetBundleGrouperSettingData.SaveFile(); AssetBundleCollectorSettingData.Setting.Groups.AddRange(groupTemper);
AssetBundleCollectorSettingData.SaveFile();
Debug.Log($"导入配置完毕!"); Debug.Log($"导入配置完毕!");
} }
@@ -130,22 +146,27 @@ namespace YooAsset.Editor
xmlDoc.LoadXml(sb.ToString()); xmlDoc.LoadXml(sb.ToString());
XmlElement root = xmlDoc.DocumentElement; XmlElement root = xmlDoc.DocumentElement;
// 设置着色器配置 // 设置配置版本
var shaderElement = xmlDoc.CreateElement(XmlShader); root.SetAttribute(XmlVersion, ConfigVersion);
shaderElement.SetAttribute(XmlAutoCollectShader, AssetBundleGrouperSettingData.Setting.AutoCollectShaders.ToString());
shaderElement.SetAttribute(XmlShaderBundleName, AssetBundleGrouperSettingData.Setting.ShadersBundleName); // 设置公共配置
var commonElement = xmlDoc.CreateElement(XmlCommon);
commonElement.SetAttribute(XmlEnableAddressable, AssetBundleCollectorSettingData.Setting.EnableAddressable.ToString());
commonElement.SetAttribute(XmlAutoCollectShader, AssetBundleCollectorSettingData.Setting.AutoCollectShaders.ToString());
commonElement.SetAttribute(XmlShaderBundleName, AssetBundleCollectorSettingData.Setting.ShadersBundleName);
root.AppendChild(commonElement);
// 设置分组配置 // 设置分组配置
foreach (var grouper in AssetBundleGrouperSettingData.Setting.Groupers) foreach (var group in AssetBundleCollectorSettingData.Setting.Groups)
{ {
var grouperElement = xmlDoc.CreateElement(XmlGrouper); var groupElement = xmlDoc.CreateElement(XmlGroup);
grouperElement.SetAttribute(XmlGrouperName, grouper.GrouperName); groupElement.SetAttribute(XmlGroupName, group.GroupName);
grouperElement.SetAttribute(XmlGrouperDesc, grouper.GrouperDesc); groupElement.SetAttribute(XmlGroupDesc, group.GroupDesc);
grouperElement.SetAttribute(XmlAssetTags, grouper.AssetTags); groupElement.SetAttribute(XmlAssetTags, group.AssetTags);
root.AppendChild(grouperElement); root.AppendChild(groupElement);
// 设置收集器配置 // 设置收集器配置
foreach (var collector in grouper.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);
@@ -154,7 +175,7 @@ namespace YooAsset.Editor
collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName); collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName);
collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName); collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName);
collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags); collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags);
grouperElement.AppendChild(collectorElement); groupElement.AppendChild(collectorElement);
} }
} }

View File

@@ -8,23 +8,28 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
[Serializable] [Serializable]
public class AssetBundleGrouper public class AssetBundleCollectorGroup
{ {
/// <summary> /// <summary>
/// 分组名称 /// 分组名称
/// </summary> /// </summary>
public string GrouperName = string.Empty; public string GroupName = string.Empty;
/// <summary> /// <summary>
/// 分组描述 /// 分组描述
/// </summary> /// </summary>
public string GrouperDesc = string.Empty; public string GroupDesc = string.Empty;
/// <summary> /// <summary>
/// 资源分类标签 /// 资源分类标签
/// </summary> /// </summary>
public string AssetTags = string.Empty; public string AssetTags = string.Empty;
/// <summary>
/// 分组激活规则
/// </summary>
public string ActiveRuleName = nameof(EnableGroup);
/// <summary> /// <summary>
/// 分组的收集器列表 /// 分组的收集器列表
/// </summary> /// </summary>
@@ -36,6 +41,9 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public void CheckConfigError() public void CheckConfigError()
{ {
if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false)
throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}");
foreach (var collector in Collectors) foreach (var collector in Collectors)
{ {
collector.CheckConfigError(); collector.CheckConfigError();
@@ -45,25 +53,32 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 获取打包收集的资源文件 /// 获取打包收集的资源文件
/// </summary> /// </summary>
public List<CollectAssetInfo> GetAllCollectAssets() public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
{ {
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000); Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
// 检测分组是否激活
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
if (activeRule.IsActiveGroup() == false)
{
return new List<CollectAssetInfo>();
}
// 收集打包资源 // 收集打包资源
foreach (var collector in Collectors) foreach (var collector in Collectors)
{ {
var temper = collector.GetAllCollectAssets(this); var temper = collector.GetAllCollectAssets(buildMode, this);
foreach (var assetInfo in temper) foreach (var assetInfo in temper)
{ {
if (result.ContainsKey(assetInfo.AssetPath) == false) if (result.ContainsKey(assetInfo.AssetPath) == false)
result.Add(assetInfo.AssetPath, assetInfo); result.Add(assetInfo.AssetPath, assetInfo);
else else
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in grouper : {GrouperName}"); throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group : {GroupName}");
} }
} }
// 检测可寻址地址是否重复 // 检测可寻址地址是否重复
if (AssetBundleGrouperSettingData.Setting.EnableAddressable) if (AssetBundleCollectorSettingData.Setting.EnableAddressable)
{ {
HashSet<string> adressTemper = new HashSet<string>(); HashSet<string> adressTemper = new HashSet<string>();
foreach (var collectInfoPair in result) foreach (var collectInfoPair in result)
@@ -74,7 +89,7 @@ namespace YooAsset.Editor
if (adressTemper.Contains(address) == false) if (adressTemper.Contains(address) == false)
adressTemper.Add(address); adressTemper.Add(address);
else else
throw new Exception($"The address is existed : {address} in grouper : {GrouperName}"); throw new Exception($"The address is existed : {address} in group : {GroupName}");
} }
} }
} }

View File

@@ -6,7 +6,7 @@ using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleGrouperSetting : ScriptableObject public class AssetBundleCollectorSetting : ScriptableObject
{ {
/// <summary> /// <summary>
/// 是否启用可寻址资源定位 /// 是否启用可寻址资源定位
@@ -26,7 +26,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 分组列表 /// 分组列表
/// </summary> /// </summary>
public List<AssetBundleGrouper> Groupers = new List<AssetBundleGrouper>(); public List<AssetBundleCollectorGroup> Groups = new List<AssetBundleCollectorGroup>();
/// <summary> /// <summary>
@@ -34,29 +34,29 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public void CheckConfigError() public void CheckConfigError()
{ {
foreach (var grouper in Groupers) foreach (var group in Groups)
{ {
grouper.CheckConfigError(); group.CheckConfigError();
} }
} }
/// <summary> /// <summary>
/// 获取打包收集的资源文件 /// 获取打包收集的资源文件
/// </summary> /// </summary>
public List<CollectAssetInfo> GetAllCollectAssets() public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
{ {
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000); Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
// 收集打包资源 // 收集打包资源
foreach (var grouper in Groupers) foreach (var group in Groups)
{ {
var temper = grouper.GetAllCollectAssets(); var temper = group.GetAllCollectAssets(buildMode);
foreach (var assetInfo in temper) foreach (var assetInfo in temper)
{ {
if (result.ContainsKey(assetInfo.AssetPath) == false) if (result.ContainsKey(assetInfo.AssetPath) == false)
result.Add(assetInfo.AssetPath, assetInfo); result.Add(assetInfo.AssetPath, assetInfo);
else else
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in grouper setting."); throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group setting.");
} }
} }
@@ -72,7 +72,7 @@ namespace YooAsset.Editor
if (adressTemper.Contains(address) == false) if (adressTemper.Contains(address) == false)
adressTemper.Add(address); adressTemper.Add(address);
else else
throw new Exception($"The address is existed : {address} in grouper setting."); throw new Exception($"The address is existed : {address} in group setting.");
} }
} }
} }

View File

@@ -7,8 +7,11 @@ using UnityEditor;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleGrouperSettingData public class AssetBundleCollectorSettingData
{ {
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, 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>();
@@ -24,8 +27,8 @@ namespace YooAsset.Editor
public static bool IsDirty { private set; get; } = false; public static bool IsDirty { private set; get; } = false;
private static AssetBundleGrouperSetting _setting = null; private static AssetBundleCollectorSetting _setting = null;
public static AssetBundleGrouperSetting Setting public static AssetBundleCollectorSetting Setting
{ {
get get
{ {
@@ -35,6 +38,18 @@ namespace YooAsset.Editor
} }
} }
public static List<string> GetActiveRuleNames()
{
if (_setting == null)
LoadSettingData();
List<string> names = new List<string>();
foreach (var pair in _cacheActiveRuleTypes)
{
names.Add(pair.Key);
}
return names;
}
public static List<string> GetAddressRuleNames() public static List<string> GetAddressRuleNames()
{ {
if (_setting == null) if (_setting == null)
@@ -71,6 +86,15 @@ namespace YooAsset.Editor
} }
return names; return names;
} }
public static bool HasActiveRuleName(string ruleName)
{
foreach (var pair in _cacheActiveRuleTypes)
{
if (pair.Key == ruleName)
return true;
}
return false;
}
public static bool HasAddressRuleName(string ruleName) public static bool HasAddressRuleName(string ruleName)
{ {
foreach (var pair in _cacheAddressRuleTypes) foreach (var pair in _cacheAddressRuleTypes)
@@ -105,22 +129,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private static void LoadSettingData() private static void LoadSettingData()
{ {
// 加载配置文件 _setting = EditorHelper.LoadSettingData<AssetBundleCollectorSetting>();
string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleGrouperSetting)}.asset";
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleGrouperSetting>(settingFilePath);
if (_setting == null)
{
Debug.LogWarning($"Create new {nameof(AssetBundleGrouperSetting)}.asset : {settingFilePath}");
_setting = ScriptableObject.CreateInstance<AssetBundleGrouperSetting>();
EditorTools.CreateFileDirectory(settingFilePath);
AssetDatabase.CreateAsset(Setting, settingFilePath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
else
{
Debug.Log($"Load {nameof(AssetBundleGrouperSetting)}.asset ok");
}
// IPackRule // IPackRule
{ {
@@ -135,12 +144,11 @@ namespace YooAsset.Editor
typeof(PackDirectory), typeof(PackDirectory),
typeof(PackTopDirectory), typeof(PackTopDirectory),
typeof(PackCollector), typeof(PackCollector),
typeof(PackGrouper), typeof(PackGroup),
typeof(PackRawFile), typeof(PackRawFile),
}; };
TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom<IPackRule>(); var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule));
var customTypes = collection.ToList();
types.AddRange(customTypes); types.AddRange(customTypes);
for (int i = 0; i < types.Count; i++) for (int i = 0; i < types.Count; i++)
{ {
@@ -165,8 +173,7 @@ namespace YooAsset.Editor
typeof(CollectSprite) typeof(CollectSprite)
}; };
TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom<IFilterRule>(); var customTypes = EditorTools.GetAssignableTypes(typeof(IFilterRule));
var customTypes = collection.ToList();
types.AddRange(customTypes); types.AddRange(customTypes);
for (int i = 0; i < types.Count; i++) for (int i = 0; i < types.Count; i++)
{ {
@@ -187,11 +194,10 @@ namespace YooAsset.Editor
{ {
typeof(AddressByFileName), typeof(AddressByFileName),
typeof(AddressByCollectorAndFileName), typeof(AddressByCollectorAndFileName),
typeof(AddressByGrouperAndFileName) typeof(AddressByGroupAndFileName)
}; };
TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom<IAddressRule>(); var customTypes = EditorTools.GetAssignableTypes(typeof(IAddressRule));
var customTypes = collection.ToList();
types.AddRange(customTypes); types.AddRange(customTypes);
for (int i = 0; i < types.Count; i++) for (int i = 0; i < types.Count; i++)
{ {
@@ -200,6 +206,29 @@ namespace YooAsset.Editor
_cacheAddressRuleTypes.Add(type.Name, type); _cacheAddressRuleTypes.Add(type.Name, type);
} }
} }
// IActiveRule
{
// 清空缓存集合
_cacheActiveRuleTypes.Clear();
_cacheActiveRuleInstance.Clear();
// 获取所有类型
List<Type> types = new List<Type>(100)
{
typeof(EnableGroup),
typeof(DisableGroup),
};
var customTypes = EditorTools.GetAssignableTypes(typeof(IActiveRule));
types.AddRange(customTypes);
for (int i = 0; i < types.Count; i++)
{
Type type = types[i];
if (_cacheActiveRuleTypes.ContainsKey(type.Name) == false)
_cacheActiveRuleTypes.Add(type.Name, type);
}
}
} }
/// <summary> /// <summary>
@@ -212,7 +241,7 @@ namespace YooAsset.Editor
IsDirty = false; IsDirty = false;
EditorUtility.SetDirty(Setting); EditorUtility.SetDirty(Setting);
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
Debug.Log($"{nameof(AssetBundleGrouperSetting)}.asset is saved!"); Debug.Log($"{nameof(AssetBundleCollectorSetting)}.asset is saved!");
} }
} }
@@ -223,11 +252,28 @@ namespace YooAsset.Editor
{ {
Setting.AutoCollectShaders = false; Setting.AutoCollectShaders = false;
Setting.ShadersBundleName = string.Empty; Setting.ShadersBundleName = string.Empty;
Setting.Groupers.Clear(); Setting.Groups.Clear();
SaveFile(); SaveFile();
} }
// 实例类相关 // 实例类相关
public static IActiveRule GetActiveRuleInstance(string ruleName)
{
if (_cacheActiveRuleInstance.TryGetValue(ruleName, out IActiveRule instance))
return instance;
// 如果不存在创建类的实例
if (_cacheActiveRuleTypes.TryGetValue(ruleName, out Type type))
{
instance = (IActiveRule)Activator.CreateInstance(type);
_cacheActiveRuleInstance.Add(ruleName, instance);
return instance;
}
else
{
throw new Exception($"{nameof(IActiveRule)}类型无效:{ruleName}");
}
}
public static IAddressRule GetAddressRuleInstance(string ruleName) public static IAddressRule GetAddressRuleInstance(string ruleName)
{ {
if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance)) if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance))
@@ -296,43 +342,43 @@ namespace YooAsset.Editor
} }
// 资源分组编辑相关 // 资源分组编辑相关
public static void CreateGrouper(string grouperName) public static void CreateGroup(string groupName)
{ {
AssetBundleGrouper grouper = new AssetBundleGrouper(); AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
grouper.GrouperName = grouperName; group.GroupName = groupName;
Setting.Groupers.Add(grouper); Setting.Groups.Add(group);
IsDirty = true; IsDirty = true;
} }
public static void RemoveGrouper(AssetBundleGrouper grouper) public static void RemoveGroup(AssetBundleCollectorGroup group)
{ {
if (Setting.Groupers.Remove(grouper)) if (Setting.Groups.Remove(group))
{ {
IsDirty = true; IsDirty = true;
} }
else else
{ {
Debug.LogWarning($"Failed remove grouper : {grouper.GrouperName}"); Debug.LogWarning($"Failed remove group : {group.GroupName}");
} }
} }
public static void ModifyGrouper(AssetBundleGrouper grouper) public static void ModifyGroup(AssetBundleCollectorGroup group)
{ {
if (grouper != null) if (group != null)
{ {
IsDirty = true; IsDirty = true;
} }
} }
// 资源收集器编辑相关 // 资源收集器编辑相关
public static void CreateCollector(AssetBundleGrouper grouper, string collectPath) public static void CreateCollector(AssetBundleCollectorGroup group, string collectPath)
{ {
AssetBundleCollector collector = new AssetBundleCollector(); AssetBundleCollector collector = new AssetBundleCollector();
collector.CollectPath = collectPath; collector.CollectPath = collectPath;
grouper.Collectors.Add(collector); group.Collectors.Add(collector);
IsDirty = true; IsDirty = true;
} }
public static void RemoveCollector(AssetBundleGrouper grouper, AssetBundleCollector collector) public static void RemoveCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
{ {
if (grouper.Collectors.Remove(collector)) if (group.Collectors.Remove(collector))
{ {
IsDirty = true; IsDirty = true;
} }
@@ -341,9 +387,9 @@ namespace YooAsset.Editor
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}"); Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
} }
} }
public static void ModifyCollector(AssetBundleGrouper grouper, AssetBundleCollector collector) public static void ModifyCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
{ {
if (grouper != null && collector != null) if (group != null && collector != null)
{ {
IsDirty = true; IsDirty = true;
} }

View File

@@ -9,138 +9,145 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleGrouperWindow : EditorWindow public class AssetBundleCollectorWindow : EditorWindow
{ {
[MenuItem("YooAsset/AssetBundle Grouper", false, 101)] [MenuItem("YooAsset/AssetBundle Collector", false, 101)]
public static void ShowExample() public static void ShowExample()
{ {
AssetBundleGrouperWindow window = GetWindow<AssetBundleGrouperWindow>("资源包分组工具", true, EditorDefine.DockedWindowTypes); AssetBundleCollectorWindow window = GetWindow<AssetBundleCollectorWindow>("资源包收集工具", true, EditorDefine.DockedWindowTypes);
window.minSize = new Vector2(800, 600); window.minSize = new Vector2(800, 600);
} }
private Button _saveButton;
private List<string> _collectorTypeList; private List<string> _collectorTypeList;
private List<string> _activeRuleList;
private List<string> _addressRuleList; private List<string> _addressRuleList;
private List<string> _packRuleList; private List<string> _packRuleList;
private List<string> _filterRuleList; private List<string> _filterRuleList;
private ListView _grouperListView; private ListView _groupListView;
private ScrollView _collectorScrollView; private ScrollView _collectorScrollView;
private PopupField<string> _activeRulePopupField;
private Toggle _enableAddressableToogle; private Toggle _enableAddressableToogle;
private Toggle _autoCollectShaderToogle; private Toggle _autoCollectShaderToogle;
private TextField _shaderBundleNameTxt; private TextField _shaderBundleNameTxt;
private TextField _grouperNameTxt; private TextField _groupNameTxt;
private TextField _grouperDescTxt; private TextField _groupDescTxt;
private TextField _grouperAssetTagsTxt; private TextField _groupAssetTagsTxt;
private VisualElement _grouperContainer; private VisualElement _groupContainer;
private string _lastModifyGroup = string.Empty;
public void CreateGUI() public void CreateGUI()
{ {
Undo.undoRedoPerformed -= RefreshWindow; Undo.undoRedoPerformed -= RefreshWindow;
Undo.undoRedoPerformed += RefreshWindow; Undo.undoRedoPerformed += RefreshWindow;
VisualElement root = this.rootVisualElement;
_collectorTypeList = new List<string>()
{
$"{nameof(ECollectorType.MainAssetCollector)}",
$"{nameof(ECollectorType.StaticAssetCollector)}",
$"{nameof(ECollectorType.DependAssetCollector)}"
};
_addressRuleList = AssetBundleGrouperSettingData.GetAddressRuleNames();
_packRuleList = AssetBundleGrouperSettingData.GetPackRuleNames();
_filterRuleList = AssetBundleGrouperSettingData.GetFilterRuleNames();
// 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleGrouper/{nameof(AssetBundleGrouperWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleGrouperWindow)}.uxml : {uxml}");
return;
}
visualAsset.CloneTree(root);
try try
{ {
_collectorTypeList = new List<string>()
{
$"{nameof(ECollectorType.MainAssetCollector)}",
$"{nameof(ECollectorType.StaticAssetCollector)}",
$"{nameof(ECollectorType.DependAssetCollector)}"
};
_activeRuleList = AssetBundleCollectorSettingData.GetActiveRuleNames();
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
VisualElement root = this.rootVisualElement;
// 加载布局文件
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleCollectorWindow>();
if (visualAsset == null)
return;
visualAsset.CloneTree(root);
// 导入导出按钮 // 导入导出按钮
var exportBtn = root.Q<Button>("ExportButton"); var exportBtn = root.Q<Button>("ExportButton");
exportBtn.clicked += ExportBtn_clicked; exportBtn.clicked += ExportBtn_clicked;
var importBtn = root.Q<Button>("ImportButton"); var importBtn = root.Q<Button>("ImportButton");
importBtn.clicked += ImportBtn_clicked; importBtn.clicked += ImportBtn_clicked;
// 配置保存按钮
_saveButton = root.Q<Button>("SaveButton");
_saveButton.clicked += SaveBtn_clicked;
// 公共设置相关 // 公共设置相关
_enableAddressableToogle = root.Q<Toggle>("EnableAddressable"); _enableAddressableToogle = root.Q<Toggle>("EnableAddressable");
_enableAddressableToogle.RegisterValueChangedCallback(evt => _enableAddressableToogle.RegisterValueChangedCallback(evt =>
{ {
AssetBundleGrouperSettingData.ModifyAddressable(evt.newValue); AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
RefreshWindow();
}); });
_autoCollectShaderToogle = root.Q<Toggle>("AutoCollectShader"); _autoCollectShaderToogle = root.Q<Toggle>("AutoCollectShader");
_autoCollectShaderToogle.RegisterValueChangedCallback(evt => _autoCollectShaderToogle.RegisterValueChangedCallback(evt =>
{ {
AssetBundleGrouperSettingData.ModifyShader(evt.newValue, _shaderBundleNameTxt.value); AssetBundleCollectorSettingData.ModifyShader(evt.newValue, _shaderBundleNameTxt.value);
_shaderBundleNameTxt.SetEnabled(evt.newValue); _shaderBundleNameTxt.SetEnabled(evt.newValue);
}); });
_shaderBundleNameTxt = root.Q<TextField>("ShaderBundleName"); _shaderBundleNameTxt = root.Q<TextField>("ShaderBundleName");
_shaderBundleNameTxt.RegisterValueChangedCallback(evt => _shaderBundleNameTxt.RegisterValueChangedCallback(evt =>
{ {
AssetBundleGrouperSettingData.ModifyShader(_autoCollectShaderToogle.value, evt.newValue); AssetBundleCollectorSettingData.ModifyShader(_autoCollectShaderToogle.value, evt.newValue);
}); });
// 分组列表相关 // 分组列表相关
_grouperListView = root.Q<ListView>("GrouperListView"); _groupListView = root.Q<ListView>("GroupListView");
_grouperListView.makeItem = MakeGrouperListViewItem; _groupListView.makeItem = MakeGroupListViewItem;
_grouperListView.bindItem = BindGrouperListViewItem; _groupListView.bindItem = BindGroupListViewItem;
#if UNITY_2020_1_OR_NEWER #if UNITY_2020_1_OR_NEWER
_grouperListView.onSelectionChange += GrouperListView_onSelectionChange; _groupListView.onSelectionChange += GroupListView_onSelectionChange;
#else #else
_grouperListView.onSelectionChanged += GrouperListView_onSelectionChange; _groupListView.onSelectionChanged += GroupListView_onSelectionChange;
#endif #endif
// 分组添加删除按钮 // 分组添加删除按钮
var grouperAddContainer = root.Q("GrouperAddContainer"); var groupAddContainer = root.Q("GroupAddContainer");
{ {
var addBtn = grouperAddContainer.Q<Button>("AddBtn"); var addBtn = groupAddContainer.Q<Button>("AddBtn");
addBtn.clicked += AddGrouperBtn_clicked; addBtn.clicked += AddGroupBtn_clicked;
var removeBtn = grouperAddContainer.Q<Button>("RemoveBtn"); var removeBtn = groupAddContainer.Q<Button>("RemoveBtn");
removeBtn.clicked += RemoveGrouperBtn_clicked; removeBtn.clicked += RemoveGroupBtn_clicked;
} }
// 分组容器 // 分组容器
_grouperContainer = root.Q("GrouperContainer"); _groupContainer = root.Q("GroupContainer");
// 分组名称 // 分组名称
_grouperNameTxt = root.Q<TextField>("GrouperName"); _groupNameTxt = root.Q<TextField>("GroupName");
_grouperNameTxt.RegisterValueChangedCallback(evt => _groupNameTxt.RegisterValueChangedCallback(evt =>
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper != null) if (selectGroup != null)
{ {
selectGrouper.GrouperName = evt.newValue; selectGroup.GroupName = evt.newValue;
AssetBundleGrouperSettingData.ModifyGrouper(selectGrouper); AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
} }
}); });
// 分组备注 // 分组备注
_grouperDescTxt = root.Q<TextField>("GrouperDesc"); _groupDescTxt = root.Q<TextField>("GroupDesc");
_grouperDescTxt.RegisterValueChangedCallback(evt => _groupDescTxt.RegisterValueChangedCallback(evt =>
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper != null) if (selectGroup != null)
{ {
selectGrouper.GrouperDesc = evt.newValue; selectGroup.GroupDesc = evt.newValue;
AssetBundleGrouperSettingData.ModifyGrouper(selectGrouper); AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
} }
}); });
// 分组的资源标签 // 分组的资源标签
_grouperAssetTagsTxt = root.Q<TextField>("GrouperAssetTags"); _groupAssetTagsTxt = root.Q<TextField>("GroupAssetTags");
_grouperAssetTagsTxt.RegisterValueChangedCallback(evt => _groupAssetTagsTxt.RegisterValueChangedCallback(evt =>
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper != null) if (selectGroup != null)
{ {
selectGrouper.AssetTags = evt.newValue; selectGroup.AssetTags = evt.newValue;
AssetBundleGrouperSettingData.ModifyGrouper(selectGrouper); AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
} }
}); });
@@ -156,6 +163,25 @@ namespace YooAsset.Editor
addBtn.clicked += AddCollectorBtn_clicked; addBtn.clicked += AddCollectorBtn_clicked;
} }
// 分组激活规则
var activeRuleContainer = root.Q("ActiveRuleContainer");
{
_activeRulePopupField = new PopupField<string>("Active Rule", _activeRuleList, 0);
_activeRulePopupField.name = "ActiveRuleMaskField";
_activeRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
activeRuleContainer.Add(_activeRulePopupField);
_activeRulePopupField.RegisterValueChangedCallback(evt =>
{
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGroup != null)
{
selectGroup.ActiveRuleName = evt.newValue;
AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
FillGroupViewData();
}
});
}
// 刷新窗体 // 刷新窗体
RefreshWindow(); RefreshWindow();
} }
@@ -166,26 +192,45 @@ namespace YooAsset.Editor
} }
public void OnDestroy() public void OnDestroy()
{ {
if (AssetBundleGrouperSettingData.IsDirty) // 注意:清空所有撤销操作
AssetBundleGrouperSettingData.SaveFile(); Undo.ClearAll();
if (AssetBundleCollectorSettingData.IsDirty)
AssetBundleCollectorSettingData.SaveFile();
}
public void Update()
{
if (_saveButton != null)
{
if (AssetBundleCollectorSettingData.IsDirty)
{
if (_saveButton.enabledSelf == false)
_saveButton.SetEnabled(true);
}
else
{
if (_saveButton.enabledSelf)
_saveButton.SetEnabled(false);
}
}
} }
private void RefreshWindow() private void RefreshWindow()
{ {
_enableAddressableToogle.SetValueWithoutNotify(AssetBundleGrouperSettingData.Setting.EnableAddressable); _enableAddressableToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.EnableAddressable);
_autoCollectShaderToogle.SetValueWithoutNotify(AssetBundleGrouperSettingData.Setting.AutoCollectShaders); _autoCollectShaderToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.AutoCollectShaders);
_shaderBundleNameTxt.SetEnabled(AssetBundleGrouperSettingData.Setting.AutoCollectShaders); _shaderBundleNameTxt.SetEnabled(AssetBundleCollectorSettingData.Setting.AutoCollectShaders);
_shaderBundleNameTxt.SetValueWithoutNotify(AssetBundleGrouperSettingData.Setting.ShadersBundleName); _shaderBundleNameTxt.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShadersBundleName);
_grouperContainer.visible = false; _groupContainer.visible = false;
FillGrouperViewData(); FillGroupViewData();
} }
private void ExportBtn_clicked() private void ExportBtn_clicked()
{ {
string resultPath = EditorTools.OpenFolderPanel("Export XML", "Assets/"); string resultPath = EditorTools.OpenFolderPanel("Export XML", "Assets/");
if (resultPath != null) if (resultPath != null)
{ {
AssetBundleGrouperConfig.ExportXmlConfig($"{resultPath}/{nameof(AssetBundleGrouperConfig)}.xml"); AssetBundleCollectorConfig.ExportXmlConfig($"{resultPath}/{nameof(AssetBundleCollectorConfig)}.xml");
} }
} }
private void ImportBtn_clicked() private void ImportBtn_clicked()
@@ -193,20 +238,34 @@ namespace YooAsset.Editor
string resultPath = EditorTools.OpenFilePath("Import XML", "Assets/", "xml"); string resultPath = EditorTools.OpenFilePath("Import XML", "Assets/", "xml");
if (resultPath != null) if (resultPath != null)
{ {
AssetBundleGrouperConfig.ImportXmlConfig(resultPath); AssetBundleCollectorConfig.ImportXmlConfig(resultPath);
RefreshWindow(); RefreshWindow();
} }
} }
private void SaveBtn_clicked()
{
AssetBundleCollectorSettingData.SaveFile();
}
// 分组列表相关 // 分组列表相关
private void FillGrouperViewData() private void FillGroupViewData()
{ {
_grouperListView.Clear(); _groupListView.Clear();
_grouperListView.ClearSelection(); _groupListView.ClearSelection();
_grouperListView.itemsSource = AssetBundleGrouperSettingData.Setting.Groupers; _groupListView.itemsSource = AssetBundleCollectorSettingData.Setting.Groups;
_grouperListView.Rebuild(); _groupListView.Rebuild();
for (int index = 0; index < AssetBundleCollectorSettingData.Setting.Groups.Count; index++)
{
var group = AssetBundleCollectorSettingData.Setting.Groups[index];
if (group.GroupName == _lastModifyGroup)
{
_groupListView.selectedIndex = index;
break;
}
}
} }
private VisualElement MakeGrouperListViewItem() private VisualElement MakeGroupListViewItem()
{ {
VisualElement element = new VisualElement(); VisualElement element = new VisualElement();
@@ -221,57 +280,63 @@ namespace YooAsset.Editor
return element; return element;
} }
private void BindGrouperListViewItem(VisualElement element, int index) private void BindGroupListViewItem(VisualElement element, int index)
{ {
var grouper = AssetBundleGrouperSettingData.Setting.Groupers[index]; var group = AssetBundleCollectorSettingData.Setting.Groups[index];
// Grouper Name // Group Name
var textField1 = element.Q<Label>("Label1"); var textField1 = element.Q<Label>("Label1");
if (string.IsNullOrEmpty(grouper.GrouperDesc)) if (string.IsNullOrEmpty(group.GroupDesc))
textField1.text = grouper.GrouperName; textField1.text = group.GroupName;
else else
textField1.text = $"{grouper.GrouperName} ({grouper.GrouperDesc})"; textField1.text = $"{group.GroupName} ({group.GroupDesc})";
// 激活状态
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(group.ActiveRuleName);
bool isActive = activeRule.IsActiveGroup();
textField1.SetEnabled(isActive);
} }
private void GrouperListView_onSelectionChange(IEnumerable<object> objs) private void GroupListView_onSelectionChange(IEnumerable<object> objs)
{ {
FillCollectorViewData(); FillCollectorViewData();
} }
private void AddGrouperBtn_clicked() private void AddGroupBtn_clicked()
{ {
Undo.RecordObject(AssetBundleGrouperSettingData.Setting, "YooAsset AddGrouper"); Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddGroup");
AssetBundleGrouperSettingData.CreateGrouper("Default Grouper"); AssetBundleCollectorSettingData.CreateGroup("Default Group");
FillGrouperViewData(); FillGroupViewData();
} }
private void RemoveGrouperBtn_clicked() private void RemoveGroupBtn_clicked()
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper == null) if (selectGroup == null)
return; return;
Undo.RecordObject(AssetBundleGrouperSettingData.Setting, "YooAsset RemoveGrouper"); Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow RemoveGroup");
AssetBundleCollectorSettingData.RemoveGroup(selectGroup);
AssetBundleGrouperSettingData.RemoveGrouper(selectGrouper); FillGroupViewData();
FillGrouperViewData();
} }
// 收集列表相关 // 收集列表相关
private void FillCollectorViewData() private void FillCollectorViewData()
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper == null) if (selectGroup == null)
{ {
_grouperContainer.visible = false; _groupContainer.visible = false;
return; return;
} }
_grouperContainer.visible = true; _lastModifyGroup = selectGroup.GroupName;
_grouperNameTxt.SetValueWithoutNotify(selectGrouper.GrouperName); _groupContainer.visible = true;
_grouperDescTxt.SetValueWithoutNotify(selectGrouper.GrouperDesc); _activeRulePopupField.SetValueWithoutNotify(selectGroup.ActiveRuleName);
_grouperAssetTagsTxt.SetValueWithoutNotify(selectGrouper.AssetTags); _groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
// 填充数据 // 填充数据
_collectorScrollView.Clear(); _collectorScrollView.Clear();
for (int i = 0; i < selectGrouper.Collectors.Count; i++) for (int i = 0; i < selectGroup.Collectors.Count; i++)
{ {
VisualElement element = MakeCollectorListViewItem(); VisualElement element = MakeCollectorListViewItem();
BindCollectorListViewItem(element, i); BindCollectorListViewItem(element, i);
@@ -391,18 +456,24 @@ namespace YooAsset.Editor
} }
private void BindCollectorListViewItem(VisualElement element, int index) private void BindCollectorListViewItem(VisualElement element, int index)
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper == null) if (selectGroup == null)
return; return;
var collector = selectGrouper.Collectors[index]; var collector = selectGroup.Collectors[index];
var collectObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(collector.CollectPath); var collectObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(collector.CollectPath);
if (collectObject != null) if (collectObject != null)
collectObject.name = collector.CollectPath; collectObject.name = collector.CollectPath;
// Foldout // Foldout
var foldout = element.Q<Foldout>("Foldout1"); var foldout = element.Q<Foldout>("Foldout1");
RefreshFoldout(foldout, selectGrouper, collector); foldout.RegisterValueChangedCallback(evt =>
{
if (evt.newValue)
RefreshFoldout(foldout, selectGroup, collector);
else
foldout.Clear();
});
// Remove Button // Remove Button
var removeBtn = element.Q<Button>("Button1"); var removeBtn = element.Q<Button>("Button1");
@@ -418,8 +489,11 @@ namespace YooAsset.Editor
{ {
collector.CollectPath = AssetDatabase.GetAssetPath(evt.newValue); collector.CollectPath = AssetDatabase.GetAssetPath(evt.newValue);
objectField1.value.name = collector.CollectPath; objectField1.value.name = collector.CollectPath;
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
RefreshFoldout(foldout, selectGrouper, collector); if (foldout.value)
{
RefreshFoldout(foldout, selectGroup, collector);
}
}); });
// Collector Type // Collector Type
@@ -428,8 +502,11 @@ namespace YooAsset.Editor
popupField0.RegisterValueChangedCallback(evt => popupField0.RegisterValueChangedCallback(evt =>
{ {
collector.CollectorType = StringUtility.NameToEnum<ECollectorType>(evt.newValue); collector.CollectorType = StringUtility.NameToEnum<ECollectorType>(evt.newValue);
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
RefreshFoldout(foldout, selectGrouper, collector); if (foldout.value)
{
RefreshFoldout(foldout, selectGroup, collector);
}
}); });
// Address Rule // Address Rule
@@ -440,8 +517,11 @@ namespace YooAsset.Editor
popupField1.RegisterValueChangedCallback(evt => popupField1.RegisterValueChangedCallback(evt =>
{ {
collector.AddressRuleName = evt.newValue; collector.AddressRuleName = evt.newValue;
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
RefreshFoldout(foldout, selectGrouper, collector); if (foldout.value)
{
RefreshFoldout(foldout, selectGroup, collector);
}
}); });
} }
@@ -451,8 +531,11 @@ namespace YooAsset.Editor
popupField2.RegisterValueChangedCallback(evt => popupField2.RegisterValueChangedCallback(evt =>
{ {
collector.PackRuleName = evt.newValue; collector.PackRuleName = evt.newValue;
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
RefreshFoldout(foldout, selectGrouper, collector); if (foldout.value)
{
RefreshFoldout(foldout, selectGroup, collector);
}
}); });
// Filter Rule // Filter Rule
@@ -461,8 +544,11 @@ namespace YooAsset.Editor
popupField3.RegisterValueChangedCallback(evt => popupField3.RegisterValueChangedCallback(evt =>
{ {
collector.FilterRuleName = evt.newValue; collector.FilterRuleName = evt.newValue;
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
RefreshFoldout(foldout, selectGrouper, collector); if (foldout.value)
{
RefreshFoldout(foldout, selectGroup, collector);
}
}); });
// Tags // Tags
@@ -471,17 +557,17 @@ namespace YooAsset.Editor
textFiled1.RegisterValueChangedCallback(evt => textFiled1.RegisterValueChangedCallback(evt =>
{ {
collector.AssetTags = evt.newValue; collector.AssetTags = evt.newValue;
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector); AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
}); });
} }
private void RefreshFoldout(Foldout foldout, AssetBundleGrouper grouper, AssetBundleCollector collector) private void RefreshFoldout(Foldout foldout, AssetBundleCollectorGroup group, AssetBundleCollector collector)
{ {
// 清空旧元素 // 清空旧元素
foldout.Clear(); foldout.Clear();
if (collector.IsValid() == false) if (collector.IsValid() == false)
{ {
Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in grouper : {grouper.GrouperName}"); Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in group : {group.GroupName}");
return; return;
} }
@@ -491,7 +577,7 @@ namespace YooAsset.Editor
try try
{ {
collectAssetInfos = collector.GetAllCollectAssets(grouper); collectAssetInfos = collector.GetAllCollectAssets(EBuildMode.DryRunBuild, group);
} }
catch (System.Exception e) catch (System.Exception e)
{ {
@@ -509,8 +595,8 @@ namespace YooAsset.Editor
string showInfo = collectAssetInfo.AssetPath; string showInfo = collectAssetInfo.AssetPath;
if (_enableAddressableToogle.value) if (_enableAddressableToogle.value)
{ {
IAddressRule instance = AssetBundleGrouperSettingData.GetAddressRuleInstance(collector.AddressRuleName); IAddressRule instance = AssetBundleCollectorSettingData.GetAddressRuleInstance(collector.AddressRuleName);
AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, grouper.GrouperName); AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, group.GroupName);
string addressValue = instance.GetAssetAddress(ruleData); string addressValue = instance.GetAssetAddress(ruleData);
showInfo = $"[{addressValue}] {showInfo}"; showInfo = $"[{addressValue}] {showInfo}";
} }
@@ -527,21 +613,24 @@ namespace YooAsset.Editor
} }
private void AddCollectorBtn_clicked() private void AddCollectorBtn_clicked()
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper == null) if (selectGroup == null)
return; return;
AssetBundleGrouperSettingData.CreateCollector(selectGrouper, string.Empty); Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddCollector");
AssetBundleCollectorSettingData.CreateCollector(selectGroup, string.Empty);
FillCollectorViewData(); FillCollectorViewData();
} }
private void RemoveCollectorBtn_clicked(AssetBundleCollector selectCollector) private void RemoveCollectorBtn_clicked(AssetBundleCollector selectCollector)
{ {
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper; var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
if (selectGrouper == null) if (selectGroup == null)
return; return;
if (selectCollector == null) if (selectCollector == null)
return; return;
AssetBundleGrouperSettingData.RemoveCollector(selectGrouper, selectCollector);
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow RemoveCollector");
AssetBundleCollectorSettingData.RemoveCollector(selectGroup, selectCollector);
FillCollectorViewData(); FillCollectorViewData();
} }

View File

@@ -1,12 +1,13 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True"> <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;"> <uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" /> <ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="导入" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" /> <ui:Button text="导入" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
</uie:Toolbar> </uie:Toolbar>
<ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;"> <ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;">
<ui:VisualElement name="LeftContainer" style="width: 200px; flex-grow: 0; background-color: rgb(67, 67, 67); border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;"> <ui:VisualElement name="LeftContainer" style="width: 200px; flex-grow: 0; background-color: rgb(67, 67, 67); border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:ListView focusable="true" name="GrouperListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" /> <ui:ListView focusable="true" name="GroupListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:VisualElement name="GrouperAddContainer" style="height: 20px; flex-direction: row; justify-content: center;"> <ui:VisualElement name="GroupAddContainer" style="height: 20px; flex-direction: row; justify-content: center;">
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" /> <ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" /> <ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
</ui:VisualElement> </ui:VisualElement>
@@ -17,10 +18,11 @@
<ui:Toggle label="Auto Collect Shaders" name="AutoCollectShader" style="width: 196px; -unity-text-align: middle-left;" /> <ui:Toggle label="Auto Collect Shaders" name="AutoCollectShader" style="width: 196px; -unity-text-align: middle-left;" />
<ui:TextField picking-mode="Ignore" label="Shader Bundle Name" name="ShaderBundleName" style="flex-grow: 1; -unity-text-align: middle-left;" /> <ui:TextField picking-mode="Ignore" label="Shader Bundle Name" name="ShaderBundleName" style="flex-grow: 1; -unity-text-align: middle-left;" />
</ui:VisualElement> </ui:VisualElement>
<ui:VisualElement name="GrouperContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;"> <ui:VisualElement name="GroupContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:TextField picking-mode="Ignore" label="Grouper Name" name="GrouperName" /> <ui:VisualElement name="ActiveRuleContainer" style="height: 20px;" />
<ui:TextField picking-mode="Ignore" label="Grouper Desc" name="GrouperDesc" /> <ui:TextField picking-mode="Ignore" label="Group Name" name="GroupName" />
<ui:TextField picking-mode="Ignore" label="Grouper Asset Tags" name="GrouperAssetTags" /> <ui:TextField picking-mode="Ignore" label="Group Desc" name="GroupDesc" />
<ui:TextField picking-mode="Ignore" label="Group Asset Tags" name="GroupAssetTags" />
<ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;"> <ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;">
<ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" /> <ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" />
</ui:VisualElement> </ui:VisualElement>

View File

@@ -0,0 +1,25 @@

namespace YooAsset.Editor
{
/// <summary>
/// 启用分组
/// </summary>
public class EnableGroup : IActiveRule
{
public bool IsActiveGroup()
{
return true;
}
}
/// <summary>
/// 禁用分组
/// </summary>
public class DisableGroup : IActiveRule
{
public bool IsActiveGroup()
{
return false;
}
}
}

View File

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

View File

@@ -16,12 +16,12 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 以组名+文件名为定位地址 /// 以组名+文件名为定位地址
/// </summary> /// </summary>
public class AddressByGrouperAndFileName : IAddressRule public class AddressByGroupAndFileName : IAddressRule
{ {
string IAddressRule.GetAssetAddress(AddressRuleData data) string IAddressRule.GetAssetAddress(AddressRuleData data)
{ {
string fileName = Path.GetFileNameWithoutExtension(data.AssetPath); string fileName = Path.GetFileNameWithoutExtension(data.AssetPath);
return $"{data.GrouperName}_{fileName}"; return $"{data.GroupName}_{fileName}";
} }
} }

View File

@@ -44,10 +44,19 @@ namespace YooAsset.Editor
{ {
public bool IsCollectAsset(FilterRuleData data) public bool IsCollectAsset(FilterRuleData data)
{ {
if (AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath) == typeof(Sprite)) var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath);
return true; if(mainAssetType == typeof(Texture2D))
{
var texImporter = AssetImporter.GetAtPath(data.AssetPath) as TextureImporter;
if (texImporter != null && texImporter.textureType == TextureImporterType.Sprite)
return true;
else
return false;
}
else else
{
return false; return false;
}
} }
} }
} }

View File

@@ -28,6 +28,8 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public class PackDirectory : IPackRule public class PackDirectory : IPackRule
{ {
public static PackDirectory StaticPackRule = new PackDirectory();
string IPackRule.GetBundleName(PackRuleData data) string IPackRule.GetBundleName(PackRuleData data)
{ {
return Path.GetDirectoryName(data.AssetPath); return Path.GetDirectoryName(data.AssetPath);
@@ -78,11 +80,11 @@ namespace YooAsset.Editor
/// 以分组名称作为资源包名 /// 以分组名称作为资源包名
/// 注意:收集的所有文件打进一个资源包 /// 注意:收集的所有文件打进一个资源包
/// </summary> /// </summary>
public class PackGrouper : IPackRule public class PackGroup : IPackRule
{ {
string IPackRule.GetBundleName(PackRuleData data) string IPackRule.GetBundleName(PackRuleData data)
{ {
return data.GrouperName; return data.GroupName;
} }
} }

View File

@@ -0,0 +1,14 @@

namespace YooAsset.Editor
{
/// <summary>
/// 资源分组激活规则接口
/// </summary>
public interface IActiveRule
{
/// <summary>
/// 是否激活分组
/// </summary>
bool IsActiveGroup();
}
}

View File

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

View File

@@ -5,13 +5,13 @@ namespace YooAsset.Editor
{ {
public string AssetPath; public string AssetPath;
public string CollectPath; public string CollectPath;
public string GrouperName; public string GroupName;
public AddressRuleData(string assetPath, string collectPath, string grouperName) public AddressRuleData(string assetPath, string collectPath, string groupName)
{ {
AssetPath = assetPath; AssetPath = assetPath;
CollectPath = collectPath; CollectPath = collectPath;
GrouperName = grouperName; GroupName = groupName;
} }
} }

View File

@@ -5,19 +5,19 @@ namespace YooAsset.Editor
{ {
public string AssetPath; public string AssetPath;
public string CollectPath; public string CollectPath;
public string GrouperName; public string GroupName;
public PackRuleData(string assetPath) public PackRuleData(string assetPath)
{ {
AssetPath = assetPath; AssetPath = assetPath;
CollectPath = string.Empty; CollectPath = string.Empty;
GrouperName = string.Empty; GroupName = string.Empty;
} }
public PackRuleData(string assetPath, string collectPath, string grouperName) public PackRuleData(string assetPath, string collectPath, string groupName)
{ {
AssetPath = assetPath; AssetPath = assetPath;
CollectPath = collectPath; CollectPath = collectPath;
GrouperName = grouperName; GroupName = groupName;
} }
} }

View File

@@ -1,140 +1,298 @@
#if UNITY_2019_4_OR_NEWER #if UNITY_2019_4_OR_NEWER
using System;
using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements; using UnityEngine.UIElements;
using UnityEditor.UIElements; using UnityEditor.UIElements;
using UnityEditor.Networking.PlayerConnection;
using UnityEngine.Networking.PlayerConnection;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class AssetBundleDebuggerWindow : EditorWindow public class AssetBundleDebuggerWindow : EditorWindow
{ {
[MenuItem("YooAsset/AssetBundle Debugger", false, 104)] [MenuItem("YooAsset/AssetBundle Debugger", false, 104)]
public static void ShowExample() public static void ShowExample()
{ {
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>("资源包调试工具", true, EditorDefine.DockedWindowTypes); AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>("资源包调试工具", true, EditorDefine.DockedWindowTypes);
wnd.minSize = new Vector2(800, 600); wnd.minSize = new Vector2(800, 600);
} }
/// <summary> /// <summary>
/// 视图模式 /// 视图模式
/// </summary> /// </summary>
private enum EViewMode private enum EViewMode
{ {
/// <summary> /// <summary>
/// 内存视图 /// 内存视图
/// </summary> /// </summary>
MemoryView, MemoryView,
/// <summary> /// <summary>
/// 资源对象视图 /// 资源对象视图
/// </summary> /// </summary>
AssetView, AssetView,
/// <summary> /// <summary>
/// 资源包视图 /// 资源包视图
/// </summary> /// </summary>
BundleView, BundleView,
} }
private ToolbarMenu _viewModeMenu;
private AssetListDebuggerViewer _assetListViewer;
private BundleListDebuggerViewer _bundleListViewer;
private EViewMode _viewMode;
private readonly DebugReport _debugReport = new DebugReport();
private string _searchKeyWord;
public void CreateGUI() private readonly Dictionary<int, RemotePlayerSession> _playerSessions = new Dictionary<int, RemotePlayerSession>();
{
VisualElement root = rootVisualElement;
// 加载布局文件 private Label _playerName;
string rootPath = EditorTools.GetYooAssetSourcePath(); private ToolbarMenu _viewModeMenu;
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/{nameof(AssetBundleDebuggerWindow)}.uxml"; private SliderInt _frameSlider;
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); private DebuggerAssetListViewer _assetListViewer;
if (visualAsset == null) private DebuggerBundleListViewer _bundleListViewer;
{
Debug.LogError($"Not found {nameof(AssetBundleDebuggerWindow)}.uxml : {uxml}");
return;
}
visualAsset.CloneTree(root);
// 采样按钮 private EViewMode _viewMode;
var sampleBtn = root.Q<Button>("SampleButton"); private string _searchKeyWord;
sampleBtn.clicked += SampleBtn_onClick; private DebugReport _currentReport;
private RemotePlayerSession _currentPlayerSession;
private int _rangeIndex = 0;
// 视口模式菜单
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
//_viewModeMenu.menu.AppendAction(EViewMode.MemoryView.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
// 搜索栏 public void CreateGUI()
var searchField = root.Q<ToolbarSearchField>("SearchField"); {
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange); try
{
VisualElement root = rootVisualElement;
// 加载视图 // 加载布局文件
_assetListViewer = new AssetListDebuggerViewer(); var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleDebuggerWindow>();
_assetListViewer.InitViewer(); if (visualAsset == null)
return;
// 加载视图 visualAsset.CloneTree(root);
_bundleListViewer = new BundleListDebuggerViewer();
_bundleListViewer.InitViewer();
// 显示视图 // 采样按钮
_viewMode = EViewMode.AssetView; var sampleBtn = root.Q<Button>("SampleButton");
_viewModeMenu.text = EViewMode.AssetView.ToString(); sampleBtn.clicked += SampleBtn_onClick;
_assetListViewer.AttachParent(root);
} // 用户列表菜单
private void SampleBtn_onClick() _playerName = root.Q<Label>("PlayerName");
{ _playerName.text = "Editor player";
YooAssets.GetDebugReport(_debugReport);
_assetListViewer.FillViewData(_debugReport, _searchKeyWord); // 视口模式菜单
_bundleListViewer.FillViewData(_debugReport, _searchKeyWord); _viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
} _viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.AssetView);
private void OnSearchKeyWordChange(ChangeEvent<string> e) _viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.BundleView);
{ _viewModeMenu.text = EViewMode.AssetView.ToString();
_searchKeyWord = e.newValue;
_assetListViewer.FillViewData(_debugReport, _searchKeyWord); // 搜索栏
_bundleListViewer.FillViewData(_debugReport, _searchKeyWord); var searchField = root.Q<ToolbarSearchField>("SearchField");
} searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
private void ViewModeMenuAction1(DropdownMenuAction action)
{ // 帧数相关
if (_viewMode != EViewMode.AssetView) {
{ _frameSlider = root.Q<SliderInt>("FrameSlider");
_viewMode = EViewMode.AssetView; _frameSlider.label = "Frame:";
VisualElement root = this.rootVisualElement; _frameSlider.highValue = 0;
_viewModeMenu.text = EViewMode.AssetView.ToString(); _frameSlider.lowValue = 0;
_assetListViewer.AttachParent(root); _frameSlider.value = 0;
_bundleListViewer.DetachParent(); _frameSlider.RegisterValueChangedCallback(evt =>
} {
} OnFrameSliderChange(evt.newValue);
private void ViewModeMenuAction2(DropdownMenuAction action) });
{
if (_viewMode != EViewMode.BundleView) var frameLast = root.Q<ToolbarButton>("FrameLast");
{ frameLast.clicked += OnFrameLast_clicked;
_viewMode = EViewMode.BundleView;
VisualElement root = this.rootVisualElement; var frameNext = root.Q<ToolbarButton>("FrameNext");
_viewModeMenu.text = EViewMode.BundleView.ToString(); frameNext.clicked += OnFrameNext_clicked;
_assetListViewer.DetachParent();
_bundleListViewer.AttachParent(root); var frameClear = root.Q<ToolbarButton>("FrameClear");
} frameClear.clicked += OnFrameClear_clicked;
} }
private DropdownMenuAction.Status ViewModeMenuFun1(DropdownMenuAction action)
{ // 加载视图
if (_viewMode == EViewMode.AssetView) _assetListViewer = new DebuggerAssetListViewer();
return DropdownMenuAction.Status.Checked; _assetListViewer.InitViewer();
else
return DropdownMenuAction.Status.Normal; // 加载视图
} _bundleListViewer = new DebuggerBundleListViewer();
private DropdownMenuAction.Status ViewModeMenuFun2(DropdownMenuAction action) _bundleListViewer.InitViewer();
{
if (_viewMode == EViewMode.BundleView) // 显示视图
return DropdownMenuAction.Status.Checked; _viewMode = EViewMode.AssetView;
else _assetListViewer.AttachParent(root);
return DropdownMenuAction.Status.Normal;
} // 远程调试
} EditorConnection.instance.Initialize();
EditorConnection.instance.RegisterConnection(OnHandleConnectionEvent);
EditorConnection.instance.RegisterDisconnection(OnHandleDisconnectionEvent);
EditorConnection.instance.Register(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
RemoteDebuggerInRuntime.EditorHandleDebugReportCallback = OnHandleDebugReport;
}
catch (Exception e)
{
Debug.LogError(e.ToString());
}
}
public void OnDestroy()
{
// 远程调试
EditorConnection.instance.UnregisterConnection(OnHandleConnectionEvent);
EditorConnection.instance.UnregisterDisconnection(OnHandleDisconnectionEvent);
EditorConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
_playerSessions.Clear();
}
private void OnHandleConnectionEvent(int playerId)
{
Debug.Log($"Game player connection : {playerId}");
_playerName.text = $"Connected player : {playerId}";
}
private void OnHandleDisconnectionEvent(int playerId)
{
Debug.Log($"Game player disconnection : {playerId}");
_playerName.text = $"Disconneced player : {playerId}";
}
private void OnHandlePlayerMessage(MessageEventArgs args)
{
var debugReport = DebugReport.Deserialize(args.data);
OnHandleDebugReport(args.playerId, debugReport);
}
private void OnHandleDebugReport(int playerId, DebugReport debugReport)
{
Debug.Log($"Handle player {playerId} debug report !");
_currentPlayerSession = GetOrCreatePlayerSession(playerId);
_currentPlayerSession.AddDebugReport(debugReport);
_frameSlider.highValue = _currentPlayerSession.MaxRangeValue;
_frameSlider.value = _currentPlayerSession.MaxRangeValue;
UpdateFrameView(_currentPlayerSession);
}
private void OnFrameSliderChange(int sliderValue)
{
if (_currentPlayerSession != null)
{
_rangeIndex = _currentPlayerSession.ClampRangeIndex(sliderValue); ;
UpdateFrameView(_currentPlayerSession, _rangeIndex);
}
}
private void OnFrameLast_clicked()
{
if (_currentPlayerSession != null)
{
_rangeIndex = _currentPlayerSession.ClampRangeIndex(_rangeIndex - 1);
_frameSlider.value = _rangeIndex;
UpdateFrameView(_currentPlayerSession, _rangeIndex);
}
}
private void OnFrameNext_clicked()
{
if (_currentPlayerSession != null)
{
_rangeIndex = _currentPlayerSession.ClampRangeIndex(_rangeIndex + 1);
_frameSlider.value = _rangeIndex;
UpdateFrameView(_currentPlayerSession, _rangeIndex);
}
}
private void OnFrameClear_clicked()
{
if (_currentPlayerSession != null)
{
_frameSlider.label = $"Frame:";
_frameSlider.value = 0;
_frameSlider.lowValue = 0;
_frameSlider.highValue = 0;
_currentPlayerSession.ClearDebugReport();
_assetListViewer.ClearView();
_bundleListViewer.ClearView();
}
}
private RemotePlayerSession GetOrCreatePlayerSession(int playerId)
{
if (_playerSessions.TryGetValue(playerId, out RemotePlayerSession session))
{
return session;
}
else
{
RemotePlayerSession newSession = new RemotePlayerSession(playerId);
_playerSessions.Add(playerId, newSession);
return newSession;
}
}
private void UpdateFrameView(RemotePlayerSession playerSession)
{
if (playerSession != null)
{
UpdateFrameView(playerSession, playerSession.MaxRangeValue);
}
}
private void UpdateFrameView(RemotePlayerSession playerSession, int rangeIndex)
{
if (playerSession == null)
return;
var debugReport = playerSession.GetDebugReport(rangeIndex);
if (debugReport != null)
{
_currentReport = debugReport;
_frameSlider.label = $"Frame: {debugReport.FrameCount}";
_assetListViewer.FillViewData(debugReport, _searchKeyWord);
_bundleListViewer.FillViewData(debugReport, _searchKeyWord);
}
}
private void SampleBtn_onClick()
{
// 发送采集数据的命令
RemoteCommand command = new RemoteCommand();
command.CommandType = (int)ERemoteCommand.SampleOnce;
command.CommandParam = string.Empty;
byte[] data = RemoteCommand.Serialize(command);
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgSendEditorToPlayer, data);
RemoteDebuggerInRuntime.EditorRequestDebugReport();
}
private void OnSearchKeyWordChange(ChangeEvent<string> e)
{
_searchKeyWord = e.newValue;
if (_currentReport != null)
{
_assetListViewer.FillViewData(_currentReport, _searchKeyWord);
_bundleListViewer.FillViewData(_currentReport, _searchKeyWord);
}
}
private void OnViewModeMenuChange(DropdownMenuAction action)
{
var viewMode = (EViewMode)action.userData;
if (_viewMode != viewMode)
{
_viewMode = viewMode;
VisualElement root = this.rootVisualElement;
_viewModeMenu.text = viewMode.ToString();
if (viewMode == EViewMode.AssetView)
{
_assetListViewer.AttachParent(root);
_bundleListViewer.DetachParent();
}
else if (viewMode == EViewMode.BundleView)
{
_assetListViewer.DetachParent();
_bundleListViewer.AttachParent(root);
}
else
{
throw new NotImplementedException(viewMode.ToString());
}
}
}
private DropdownMenuAction.Status OnViewModeMenuStatusUpdate(DropdownMenuAction action)
{
var viewMode = (EViewMode)action.userData;
if (_viewMode == viewMode)
return DropdownMenuAction.Status.Checked;
else
return DropdownMenuAction.Status.Normal;
}
}
} }
#endif #endif

View File

@@ -1,7 +1,14 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True"> <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<uie:Toolbar name="Toolbar" style="display: flex;"> <uie:Toolbar name="TopToolbar" style="display: flex;">
<ui:Label text="Player" display-tooltip-when-elided="true" name="PlayerName" style="width: 200px; -unity-text-align: middle-left; padding-left: 5px;" />
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" /> <uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" />
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" /> <uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
<uie:ToolbarButton text="刷新" display-tooltip-when-elided="true" name="SampleButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" /> <uie:ToolbarButton text="刷新" display-tooltip-when-elided="true" name="SampleButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" />
</uie:Toolbar> </uie:Toolbar>
<uie:Toolbar name="FrameToolbar">
<ui:SliderInt picking-mode="Ignore" label="Frame:" value="42" high-value="100" name="FrameSlider" style="flex-grow: 1;" />
<uie:ToolbarButton text=" &lt;&lt; " display-tooltip-when-elided="true" name="FrameLast" />
<uie:ToolbarButton text=" &gt;&gt; " display-tooltip-when-elided="true" name="FrameNext" />
<uie:ToolbarButton text="Clear" display-tooltip-when-elided="true" name="FrameClear" />
</uie:Toolbar>
</ui:UXML> </ui:UXML>

View File

@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset.Editor
{
internal class RemotePlayerSession
{
private readonly List<DebugReport> _reportList = new List<DebugReport>();
/// <summary>
/// 用户ID
/// </summary>
public int PlayerId { private set; get; }
/// <summary>
/// 保存的报告最大数量
/// </summary>
public int MaxReportCount { private set; get; }
public int MinRangeValue
{
get
{
return 0;
}
}
public int MaxRangeValue
{
get
{
int index = _reportList.Count - 1;
if (index < 0)
index = 0;
return index;
}
}
public RemotePlayerSession(int playerId, int maxReportCount = 1000)
{
PlayerId = playerId;
MaxReportCount = maxReportCount;
}
/// <summary>
/// 清理缓存数据
/// </summary>
public void ClearDebugReport()
{
_reportList.Clear();
}
/// <summary>
/// 添加一个调试报告
/// </summary>
public void AddDebugReport(DebugReport report)
{
if (report == null)
Debug.LogWarning("Invalid debug report data !");
if (_reportList.Count >= MaxReportCount)
_reportList.RemoveAt(0);
_reportList.Add(report);
}
/// <summary>
/// 获取调试报告
/// </summary>
public DebugReport GetDebugReport(int rangeIndex)
{
if (_reportList.Count == 0)
return null;
if (rangeIndex < 0 || rangeIndex >= _reportList.Count)
return null;
return _reportList[rangeIndex];
}
/// <summary>
/// 规范索引值
/// </summary>
public int ClampRangeIndex(int rangeIndex)
{
if (rangeIndex < 0)
return 0;
if (rangeIndex > MaxRangeValue)
return MaxRangeValue;
return rangeIndex;
}
}
}

View File

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

View File

@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class AssetListDebuggerViewer internal class DebuggerAssetListViewer
{ {
private VisualTreeAsset _visualAsset; private VisualTreeAsset _visualAsset;
private TemplateContainer _root; private TemplateContainer _root;
@@ -23,15 +23,11 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); _visualAsset = EditorHelper.LoadWindowUXML<DebuggerAssetListViewer>();
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(AssetListDebuggerViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetListDebuggerViewer)}.uxml : {uxml}");
return; return;
}
_root = _visualAsset.CloneTree(); _root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f; _root.style.flexGrow = 1f;
@@ -51,6 +47,18 @@ namespace YooAsset.Editor
_dependListView.bindItem = BindDependListViewItem; _dependListView.bindItem = BindDependListViewItem;
} }
/// <summary>
/// 清空页面
/// </summary>
public void ClearView()
{
_debugReport = null;
_assetListView.Clear();
_assetListView.ClearSelection();
_assetListView.itemsSource.Clear();
_assetListView.Rebuild();
}
/// <summary> /// <summary>
/// 填充页面数据 /// 填充页面数据
/// </summary> /// </summary>
@@ -175,7 +183,7 @@ namespace YooAsset.Editor
// Status // Status
StyleColor textColor; StyleColor textColor;
if (providerInfo.Status == ProviderBase.EStatus.Fail) if (providerInfo.Status == (int)ProviderBase.EStatus.Fail)
textColor = new StyleColor(Color.yellow); textColor = new StyleColor(Color.yellow);
else else
textColor = label1.style.color; textColor = label1.style.color;

View File

@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class BundleListDebuggerViewer internal class DebuggerBundleListViewer
{ {
private VisualTreeAsset _visualAsset; private VisualTreeAsset _visualAsset;
private TemplateContainer _root; private TemplateContainer _root;
@@ -24,14 +24,10 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); _visualAsset = EditorHelper.LoadWindowUXML<DebuggerBundleListViewer>();
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(BundleListDebuggerViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(BundleListDebuggerViewer)}.uxml : {uxml}");
return; return;
}
_root = _visualAsset.CloneTree(); _root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f; _root.style.flexGrow = 1f;
@@ -39,17 +35,29 @@ namespace YooAsset.Editor
_bundleListView = _root.Q<ListView>("TopListView"); _bundleListView = _root.Q<ListView>("TopListView");
_bundleListView.makeItem = MakeAssetListViewItem; _bundleListView.makeItem = MakeAssetListViewItem;
_bundleListView.bindItem = BindAssetListViewItem; _bundleListView.bindItem = BindAssetListViewItem;
#if UNITY_2020_1_OR_NEWER #if UNITY_2020_1_OR_NEWER
_bundleListView.onSelectionChange += BundleListView_onSelectionChange; _bundleListView.onSelectionChange += BundleListView_onSelectionChange;
#else #else
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange; _bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
#endif #endif
// 使用列表 // 使用列表
_usingListView = _root.Q<ListView>("BottomListView"); _usingListView = _root.Q<ListView>("BottomListView");
_usingListView.makeItem = MakeIncludeListViewItem; _usingListView.makeItem = MakeIncludeListViewItem;
_usingListView.bindItem = BindIncludeListViewItem; _usingListView.bindItem = BindIncludeListViewItem;
} }
/// <summary>
/// 清空页面
/// </summary>
public void ClearView()
{
_debugReport = null;
_bundleListView.Clear();
_bundleListView.ClearSelection();
_bundleListView.itemsSource.Clear();
_bundleListView.Rebuild();
}
/// <summary> /// <summary>
/// 填充页面数据 /// 填充页面数据
@@ -151,7 +159,7 @@ namespace YooAsset.Editor
// Status // Status
StyleColor textColor; StyleColor textColor;
if (bundleInfo.Status == AssetBundleLoaderBase.EStatus.Failed) if (bundleInfo.Status == (int)AssetBundleLoaderBase.EStatus.Failed)
textColor = new StyleColor(Color.yellow); textColor = new StyleColor(Color.yellow);
else else
textColor = label1.style.color; textColor = label1.style.color;

View File

@@ -0,0 +1,46 @@
using System.IO;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
public class AssetBundleInspector
{
[CustomEditor(typeof(AssetBundle))]
internal class AssetBundleEditor : UnityEditor.Editor
{
internal bool pathFoldout = false;
internal bool advancedFoldout = false;
public override void OnInspectorGUI()
{
AssetBundle bundle = target as AssetBundle;
using (new EditorGUI.DisabledScope(true))
{
var leftStyle = new GUIStyle(GUI.skin.GetStyle("Label"));
leftStyle.alignment = TextAnchor.UpperLeft;
GUILayout.Label(new GUIContent("Name: " + bundle.name), leftStyle);
var assetNames = bundle.GetAllAssetNames();
pathFoldout = EditorGUILayout.Foldout(pathFoldout, "Source Asset Paths");
if (pathFoldout)
{
EditorGUI.indentLevel++;
foreach (var asset in assetNames)
EditorGUILayout.LabelField(asset);
EditorGUI.indentLevel--;
}
advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced Data");
}
if (advancedFoldout)
{
EditorGUI.indentLevel++;
base.OnInspectorGUI();
EditorGUI.indentLevel--;
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,65 @@
using System.IO;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
public static class AssetBundleRecorder
{
private static readonly Dictionary<string, AssetBundle> _loadedAssetBundles = new Dictionary<string, AssetBundle>(1000);
/// <summary>
/// 获取AssetBundle对象如果没有被缓存就重新加载。
/// </summary>
public static AssetBundle GetAssetBundle(string filePath)
{
// 如果文件不存在
if (File.Exists(filePath) == false)
{
Debug.LogWarning($"Not found asset bundle file : {filePath}");
return null;
}
// 验证文件有效性(可能文件被加密)
byte[] fileData = File.ReadAllBytes(filePath);
if (EditorTools.CheckBundleFileValid(fileData) == false)
{
Debug.LogWarning($"The asset bundle file is invalid and may be encrypted : {filePath}");
return null;
}
if (_loadedAssetBundles.TryGetValue(filePath, out AssetBundle bundle))
{
return bundle;
}
else
{
AssetBundle newBundle = AssetBundle.LoadFromFile(filePath);
if(newBundle != null)
{
string[] assetNames = newBundle.GetAllAssetNames();
foreach (string name in assetNames)
{
newBundle.LoadAsset(name);
}
_loadedAssetBundles.Add(filePath, newBundle);
}
return newBundle;
}
}
/// <summary>
/// 卸载所有已经加载的AssetBundle文件
/// </summary>
public static void UnloadAll()
{
foreach(var valuePair in _loadedAssetBundles)
{
if (valuePair.Value != null)
valuePair.Value.Unload(true);
}
_loadedAssetBundles.Clear();
}
}
}

View File

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

View File

@@ -1,4 +1,5 @@
#if UNITY_2019_4_OR_NEWER #if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEditor.UIElements; using UnityEditor.UIElements;
@@ -37,60 +38,68 @@ namespace YooAsset.Editor
} }
private ToolbarMenu _viewModeMenu; private ToolbarMenu _viewModeMenu;
private SummaryReporterViewer _summaryViewer; private ReporterSummaryViewer _summaryViewer;
private AssetListReporterViewer _assetListViewer; private ReporterAssetListViewer _assetListViewer;
private BundleListReporterViewer _bundleListViewer; private ReporterBundleListViewer _bundleListViewer;
private EViewMode _viewMode; private EViewMode _viewMode;
private string _searchKeyWord;
private BuildReport _buildReport; private BuildReport _buildReport;
private string _reportFilePath;
private string _searchKeyWord;
public void CreateGUI() public void CreateGUI()
{ {
VisualElement root = this.rootVisualElement; try
// 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/{nameof(AssetBundleReporterWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null)
{ {
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml : {uxml}"); VisualElement root = this.rootVisualElement;
return;
// 加载布局文件
var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleReporterWindow>();
if (visualAsset == null)
return;
visualAsset.CloneTree(root);
// 导入按钮
var importBtn = root.Q<Button>("ImportButton");
importBtn.clicked += ImportBtn_onClick;
// 视图模式菜单
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
_viewModeMenu.menu.AppendAction(EViewMode.Summary.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
// 搜索栏
var searchField = root.Q<ToolbarSearchField>("SearchField");
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
// 加载视图
_summaryViewer = new ReporterSummaryViewer();
_summaryViewer.InitViewer();
// 加载视图
_assetListViewer = new ReporterAssetListViewer();
_assetListViewer.InitViewer();
// 加载视图
_bundleListViewer = new ReporterBundleListViewer();
_bundleListViewer.InitViewer();
// 显示视图
_viewMode = EViewMode.Summary;
_viewModeMenu.text = EViewMode.Summary.ToString();
_summaryViewer.AttachParent(root);
} }
visualAsset.CloneTree(root); catch (Exception e)
{
// 导入按钮 Debug.LogError(e.ToString());
var importBtn = root.Q<Button>("ImportButton"); }
importBtn.clicked += ImportBtn_onClick; }
public void OnDestroy()
// 视图模式菜单 {
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu"); AssetBundleRecorder.UnloadAll();
_viewModeMenu.menu.AppendAction(EViewMode.Summary.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
// 搜索栏
var searchField = root.Q<ToolbarSearchField>("SearchField");
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
// 加载视图
_summaryViewer = new SummaryReporterViewer();
_summaryViewer.InitViewer();
// 加载视图
_assetListViewer = new AssetListReporterViewer();
_assetListViewer.InitViewer();
// 加载视图
_bundleListViewer = new BundleListReporterViewer();
_bundleListViewer.InitViewer();
// 显示视图
_viewMode = EViewMode.Summary;
_viewModeMenu.text = EViewMode.Summary.ToString();
_summaryViewer.AttachParent(root);
} }
private void ImportBtn_onClick() private void ImportBtn_onClick()
@@ -99,19 +108,20 @@ namespace YooAsset.Editor
if (string.IsNullOrEmpty(selectFilePath)) if (string.IsNullOrEmpty(selectFilePath))
return; return;
string jsonData = FileUtility.ReadFile(selectFilePath); _reportFilePath = selectFilePath;
string jsonData = FileUtility.ReadFile(_reportFilePath);
_buildReport = BuildReport.Deserialize(jsonData); _buildReport = BuildReport.Deserialize(jsonData);
_assetListViewer.FillViewData(_buildReport, _searchKeyWord); _assetListViewer.FillViewData(_buildReport, _searchKeyWord);
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord); _bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
_summaryViewer.FillViewData(_buildReport); _summaryViewer.FillViewData(_buildReport);
} }
private void OnSearchKeyWordChange(ChangeEvent<string> e) private void OnSearchKeyWordChange(ChangeEvent<string> e)
{ {
_searchKeyWord = e.newValue; _searchKeyWord = e.newValue;
if(_buildReport != null) if (_buildReport != null)
{ {
_assetListViewer.FillViewData(_buildReport, _searchKeyWord); _assetListViewer.FillViewData(_buildReport, _searchKeyWord);
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord); _bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
} }
} }
private void ViewModeMenuAction0(DropdownMenuAction action) private void ViewModeMenuAction0(DropdownMenuAction action)

View File

@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class AssetListReporterViewer internal class ReporterAssetListViewer
{ {
private enum ESortMode private enum ESortMode
{ {
@@ -38,48 +38,36 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); _visualAsset = EditorHelper.LoadWindowUXML<ReporterAssetListViewer>();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(AssetListReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetListReporterViewer)}.uxml : {uxml}");
return; return;
}
try _root = _visualAsset.CloneTree();
{ _root.style.flexGrow = 1f;
_root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f;
// 顶部按钮栏 // 顶部按钮栏
_topBar1 = _root.Q<ToolbarButton>("TopBar1"); _topBar1 = _root.Q<ToolbarButton>("TopBar1");
_topBar2 = _root.Q<ToolbarButton>("TopBar2"); _topBar2 = _root.Q<ToolbarButton>("TopBar2");
_topBar1.clicked += TopBar1_clicked; _topBar1.clicked += TopBar1_clicked;
_topBar2.clicked += TopBar2_clicked; _topBar2.clicked += TopBar2_clicked;
// 底部按钮栏 // 底部按钮栏
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1"); _bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
// 资源列表 // 资源列表
_assetListView = _root.Q<ListView>("TopListView"); _assetListView = _root.Q<ListView>("TopListView");
_assetListView.makeItem = MakeAssetListViewItem; _assetListView.makeItem = MakeAssetListViewItem;
_assetListView.bindItem = BindAssetListViewItem; _assetListView.bindItem = BindAssetListViewItem;
#if UNITY_2020_1_OR_NEWER #if UNITY_2020_1_OR_NEWER
_assetListView.onSelectionChange += AssetListView_onSelectionChange; _assetListView.onSelectionChange += AssetListView_onSelectionChange;
#else #else
_assetListView.onSelectionChanged += AssetListView_onSelectionChange; _assetListView.onSelectionChanged += AssetListView_onSelectionChange;
#endif #endif
// 依赖列表 // 依赖列表
_dependListView = _root.Q<ListView>("BottomListView"); _dependListView = _root.Q<ListView>("BottomListView");
_dependListView.makeItem = MakeDependListViewItem; _dependListView.makeItem = MakeDependListViewItem;
_dependListView.bindItem = BindDependListViewItem; _dependListView.bindItem = BindDependListViewItem;
}
catch (Exception e)
{
Debug.LogError(e.ToString());
}
} }
/// <summary> /// <summary>
@@ -322,7 +310,7 @@ namespace YooAsset.Editor
// Size // Size
var label2 = element.Q<Label>("Label2"); var label2 = element.Q<Label>("Label2");
label2.text = (bundleInfo.SizeBytes / 1024f).ToString("f1") + " KB"; label2.text = EditorUtility.FormatBytes(bundleInfo.SizeBytes);
// Hash // Hash
var label3 = element.Q<Label>("Label3"); var label3 = element.Q<Label>("Label3");

View File

@@ -10,7 +10,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
internal class BundleListReporterViewer internal class ReporterBundleListViewer
{ {
private enum ESortMode private enum ESortMode
{ {
@@ -31,71 +31,60 @@ namespace YooAsset.Editor
private ListView _includeListView; private ListView _includeListView;
private BuildReport _buildReport; private BuildReport _buildReport;
private string _reportFilePath;
private string _searchKeyWord; private string _searchKeyWord;
private ESortMode _sortMode = ESortMode.BundleName; private ESortMode _sortMode = ESortMode.BundleName;
private bool _descendingSort = false; private bool _descendingSort = false;
/// <summary> /// <summary>
/// 初始化页面 /// 初始化页面
/// </summary> /// </summary>
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath(); _visualAsset = EditorHelper.LoadWindowUXML<ReporterBundleListViewer>();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(BundleListReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(BundleListReporterViewer)}.uxml : {uxml}");
return; return;
}
try _root = _visualAsset.CloneTree();
{ _root.style.flexGrow = 1f;
_root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f;
// 顶部按钮栏 // 顶部按钮栏
_topBar1 = _root.Q<ToolbarButton>("TopBar1"); _topBar1 = _root.Q<ToolbarButton>("TopBar1");
_topBar2 = _root.Q<ToolbarButton>("TopBar2"); _topBar2 = _root.Q<ToolbarButton>("TopBar2");
_topBar3 = _root.Q<ToolbarButton>("TopBar3"); _topBar3 = _root.Q<ToolbarButton>("TopBar3");
_topBar4 = _root.Q<ToolbarButton>("TopBar4"); _topBar4 = _root.Q<ToolbarButton>("TopBar4");
_topBar1.clicked += TopBar1_clicked; _topBar1.clicked += TopBar1_clicked;
_topBar2.clicked += TopBar2_clicked; _topBar2.clicked += TopBar2_clicked;
_topBar3.clicked += TopBar3_clicked; _topBar3.clicked += TopBar3_clicked;
_topBar4.clicked += TopBar4_clicked; _topBar4.clicked += TopBar4_clicked;
// 底部按钮栏 // 底部按钮栏
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1"); _bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
// 资源包列表 // 资源包列表
_bundleListView = _root.Q<ListView>("TopListView"); _bundleListView = _root.Q<ListView>("TopListView");
_bundleListView.makeItem = MakeBundleListViewItem; _bundleListView.makeItem = MakeBundleListViewItem;
_bundleListView.bindItem = BindBundleListViewItem; _bundleListView.bindItem = BindBundleListViewItem;
#if UNITY_2020_1_OR_NEWER #if UNITY_2020_1_OR_NEWER
_bundleListView.onSelectionChange += BundleListView_onSelectionChange; _bundleListView.onSelectionChange += BundleListView_onSelectionChange;
#else #else
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange; _bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
#endif #endif
// 包含列表 // 包含列表
_includeListView = _root.Q<ListView>("BottomListView"); _includeListView = _root.Q<ListView>("BottomListView");
_includeListView.makeItem = MakeIncludeListViewItem; _includeListView.makeItem = MakeIncludeListViewItem;
_includeListView.bindItem = BindIncludeListViewItem; _includeListView.bindItem = BindIncludeListViewItem;
}
catch (Exception e)
{
Debug.LogError(e.ToString());
}
} }
/// <summary> /// <summary>
/// 填充页面数据 /// 填充页面数据
/// </summary> /// </summary>
public void FillViewData(BuildReport buildReport, string searchKeyWord) public void FillViewData(BuildReport buildReport, string reprotFilePath, string searchKeyWord)
{ {
_buildReport = buildReport; _buildReport = buildReport;
_reportFilePath = reprotFilePath;
_searchKeyWord = searchKeyWord; _searchKeyWord = searchKeyWord;
RefreshView(); RefreshView();
} }
@@ -139,7 +128,7 @@ namespace YooAsset.Editor
} }
else if (_sortMode == ESortMode.BundleTags) else if (_sortMode == ESortMode.BundleTags)
{ {
if(_descendingSort) if (_descendingSort)
return result.OrderByDescending(a => a.GetTagsString()).ToList(); return result.OrderByDescending(a => a.GetTagsString()).ToList();
else else
return result.OrderBy(a => a.GetTagsString()).ToList(); return result.OrderBy(a => a.GetTagsString()).ToList();
@@ -171,7 +160,7 @@ namespace YooAsset.Editor
else else
_topBar2.text = "Size ↑"; _topBar2.text = "Size ↑";
} }
else if(_sortMode == ESortMode.BundleTags) else if (_sortMode == ESortMode.BundleTags)
{ {
if (_descendingSort) if (_descendingSort)
_topBar4.text = "Tags ↓"; _topBar4.text = "Tags ↓";
@@ -260,7 +249,7 @@ namespace YooAsset.Editor
// Size // Size
var label2 = element.Q<Label>("Label2"); var label2 = element.Q<Label>("Label2");
label2.text = (bundleInfo.SizeBytes / 1024f).ToString("f1") + " KB"; label2.text = EditorUtility.FormatBytes(bundleInfo.SizeBytes);
// Hash // Hash
var label3 = element.Q<Label>("Label3"); var label3 = element.Q<Label>("Label3");
@@ -276,8 +265,22 @@ namespace YooAsset.Editor
{ {
ReportBundleInfo bundleInfo = item as ReportBundleInfo; ReportBundleInfo bundleInfo = item as ReportBundleInfo;
FillIncludeListView(bundleInfo); FillIncludeListView(bundleInfo);
ShowAssetBundleInspector(bundleInfo);
break;
} }
} }
private void ShowAssetBundleInspector(ReportBundleInfo bundleInfo)
{
if (bundleInfo.IsRawFile())
return;
string rootDirectory = Path.GetDirectoryName(_reportFilePath);
string filePath = $"{rootDirectory}/{bundleInfo.FileName}";
if (File.Exists(filePath))
Selection.activeObject = AssetBundleRecorder.GetAssetBundle(filePath);
else
Selection.activeObject = null;
}
private void TopBar1_clicked() private void TopBar1_clicked()
{ {
if (_sortMode != ESortMode.BundleName) if (_sortMode != ESortMode.BundleName)

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