Compare commits

...

251 Commits

Author SHA1 Message Date
何冠峰
fcc729a0bf Update CHANGELOG.md 2025-03-08 15:53:46 +08:00
何冠峰
d10e54248b Update package.json 2025-03-08 15:53:35 +08:00
何冠峰
b84800a905 update assembly 2025-03-08 15:51:27 +08:00
何冠峰
8ccd7e552c fix #498 2025-03-08 15:41:03 +08:00
何冠峰
772ba484eb Update HandleFactory.cs 2025-03-08 15:01:19 +08:00
何冠峰
cdbedee705 update asmdef
YooAsset版本宏定义
2025-03-08 14:34:41 +08:00
何冠峰
10cce48e71 Merge pull request #497 from Y-way/support-macros
Support DefineConstants for YooAsset Package
2025-03-08 12:05:07 +08:00
何冠峰
13e8410d80 fix #389 2025-03-08 11:50:35 +08:00
何冠峰
6f07faf4da fix #495 2025-03-08 11:24:17 +08:00
何冠峰
e3228d406e update resource manager
优化Handle生成和移除逻辑
2025-03-08 10:58:19 +08:00
何冠峰
daf2133535 fix #496 2025-03-07 15:03:13 +08:00
Y-way
9bcbc10862 Support DefineConstants for YooAsset Package
自定义YOO_VERSION_2  以及版本管理宏,用于YooAsset升级时的宏定义处理
2025-03-07 15:00:20 +08:00
何冠峰
e6958d205e Update CHANGELOG.md 2025-03-06 15:05:52 +08:00
何冠峰
b03d9db2b0 Update package.json 2025-03-06 15:05:39 +08:00
何冠峰
30853b6d62 update space shooter 2025-03-06 14:31:40 +08:00
何冠峰
a7cafcb328 update UIElements
展示单位Units
2025-03-06 14:31:26 +08:00
何冠峰
d03bca5512 update asset bundle debugger 2025-03-06 12:20:45 +08:00
何冠峰
af3fc50188 update UIElements 2025-03-06 12:20:13 +08:00
何冠峰
b71eeeb855 update UIElements 2025-03-06 11:45:51 +08:00
何冠峰
317c42521a update test sample 2025-03-06 11:39:26 +08:00
何冠峰
064d69269e Update PakcageInvokeBuildParam.cs 2025-03-06 11:17:20 +08:00
何冠峰
9e6401d3c0 update space shooter 2025-03-06 11:17:00 +08:00
何冠峰
2aaba328ee fix #488 2025-03-06 11:16:21 +08:00
何冠峰
62fdc93a82 update test sample 2025-03-06 10:55:54 +08:00
何冠峰
408f0942ee update test sample 2025-03-05 20:00:02 +08:00
何冠峰
ddda9e29db fix #491 2025-03-05 17:39:33 +08:00
何冠峰
c2b33f5ec4 fix #492 2025-03-05 17:29:52 +08:00
何冠峰
e58999e484 update asset bundle debugger 2025-03-05 17:26:58 +08:00
何冠峰
ed9692574c Update AssetBundleSimulateBuilder.cs
模拟构建默认启用依赖关系数据库
2025-03-05 10:54:33 +08:00
何冠峰
f7e078e064 update file system 2025-03-05 10:54:02 +08:00
何冠峰
b74a44dc36 update UIElements 2025-03-03 20:57:50 +08:00
何冠峰
6b36cdb5ee update AssetBundleDebugger
内置了新的UIElments的TreeViewer组件。
2025-03-03 18:28:02 +08:00
何冠峰
56ae1a8f95 update UIElements 2025-02-28 19:06:17 +08:00
何冠峰
3069b1d1f1 update diagnostic system 2025-02-28 18:38:18 +08:00
何冠峰
e7d346e4e1 update diagnostic system
调试窗口增加异步操作视图
2025-02-27 20:37:28 +08:00
何冠峰
7d9e00a574 update resource package 2025-02-27 18:15:02 +08:00
何冠峰
7382afe535 Update CHANGELOG.md 2025-02-27 17:43:10 +08:00
何冠峰
af7d4774d6 Update package.json 2025-02-27 17:43:02 +08:00
何冠峰
520a8a0623 code style 2025-02-27 17:14:20 +08:00
何冠峰
fbd0d8ec40 code style 2025-02-27 17:14:12 +08:00
何冠峰
3fea98ce4c fix #480 2025-02-27 17:13:49 +08:00
何冠峰
7c561ce254 update resource package 2025-02-27 17:01:26 +08:00
何冠峰
522ddb5115 update resource package
增加CustomPlayMode运行模式
2025-02-27 16:31:56 +08:00
何冠峰
47f5790507 update resource package
CreateBundleDownloader下载器增加参数:recursiveDownload
2025-02-27 10:31:05 +08:00
何冠峰
0cdcfe7f52 update file system 2025-02-26 19:31:06 +08:00
何冠峰
e4d69d869b update resource package
修复2.3.1版本 抖音和微信小游戏 下载器不生效的问题。
2025-02-26 14:22:59 +08:00
何冠峰
61afb70cb9 Update CHANGELOG.md 2025-02-25 14:17:41 +08:00
何冠峰
79580697a1 Update package.json 2025-02-25 14:17:32 +08:00
何冠峰
6cb74760b0 update extension sample 2025-02-25 14:06:36 +08:00
何冠峰
c758aa81ff update runtime code
重构了OperationSystem的机制。从列表模式修改为链模式
2025-02-25 12:18:16 +08:00
何冠峰
400c2ccefe code style 2025-02-22 16:29:25 +08:00
何冠峰
64e9734bbe update sapce shooter 2025-02-22 14:14:18 +08:00
何冠峰
f6244885be update diagnostic system
优化了Debugger窗口的显示页面
2025-02-22 14:14:05 +08:00
何冠峰
82c57c382f update TableView
支持Counter
2025-02-21 16:54:43 +08:00
何冠峰
7eacb46555 update resource package 2025-02-21 15:29:42 +08:00
何冠峰
d9c911d89b update asset bundle reporter 2025-02-20 18:50:26 +08:00
何冠峰
a3ceb3dcb6 update asset bundle builder 2025-02-20 12:04:42 +08:00
何冠峰
a5b68b28b2 update asset bundle builder 2025-02-20 11:27:44 +08:00
何冠峰
bd285faf37 update space shooter 2025-02-20 11:27:30 +08:00
何冠峰
8a4960b560 code style 2025-02-20 11:02:59 +08:00
何冠峰
83c6ae2057 update asset bundle builder
修复怀旧依赖模式下,TAG传染不正确的问题。
2025-02-20 11:01:25 +08:00
何冠峰
b71563e889 Update EBuildBundleType.cs 2025-02-20 10:02:12 +08:00
何冠峰
79e0cf85f9 Update CHANGELOG.md 2025-02-19 19:10:36 +08:00
何冠峰
e996eaa008 Update package.json 2025-02-19 19:10:28 +08:00
何冠峰
5088c9e985 update asset bundle builder 2025-02-19 18:46:39 +08:00
何冠峰
610b3c6d32 Update FileSystemParameters.cs 2025-02-19 18:36:43 +08:00
何冠峰
cc7290f10e update operation system
快速启动模式
2025-02-19 18:36:33 +08:00
何冠峰
576b842368 support legacy dependency mode
YOOASSET_LEGACY_DEPENDENCY
2025-02-19 18:27:23 +08:00
何冠峰
d23c0ba715 update space shooter 2025-02-18 19:35:46 +08:00
何冠峰
98e19baebd Update TextureSchema.cs 2025-02-18 19:34:41 +08:00
何冠峰
f5947db44a Update ReorderableListView.cs 2025-02-18 19:34:34 +08:00
何冠峰
e978164329 Update ReorderableListView.cs 2025-02-18 19:28:55 +08:00
何冠峰
966c8f2efa update space shooter 2025-02-18 18:41:05 +08:00
何冠峰
a57fec3d71 update UIElements 2025-02-18 18:38:00 +08:00
何冠峰
84844eda20 update UIElements 2025-02-18 17:31:49 +08:00
何冠峰
698cdcba61 update AssetArtScanner 2025-02-17 18:18:07 +08:00
何冠峰
1d6c9393d4 Update AssetBundleCollector
支持列表元素上下拖拽排序
2025-02-17 17:54:46 +08:00
何冠峰
b654ac156d update AssetArtScanner
支持列表元素上下拖拽排序
2025-02-17 17:54:34 +08:00
何冠峰
d133a9a692 update extension sample 2025-02-17 15:44:41 +08:00
何冠峰
d55db19f0e update extension sample
微信小游戏和抖音小游戏AssetBundle使用插件卸载机制。
2025-02-14 16:37:23 +08:00
何冠峰
e3fc3df32c update space shooter 2025-02-14 12:05:30 +08:00
何冠峰
f2334da72d update extension sample 2025-02-14 12:05:24 +08:00
何冠峰
2902b6c2cf fix #472 2025-02-14 11:29:13 +08:00
何冠峰
dfa95b57b9 Update CHANGELOG.md 2025-02-14 10:03:39 +08:00
何冠峰
33a2cf66d0 Update CHANGELOG.md 2025-02-14 10:03:15 +08:00
何冠峰
5f52cf5b51 Update package.json 2025-02-14 10:03:09 +08:00
何冠峰
9d07905f2d fix #471 2025-02-13 20:14:33 +08:00
何冠峰
26dbe9dfdd update extension sample 2025-02-13 19:08:23 +08:00
何冠峰
98c5851071 update extension file system
解决微信小游戏预下载和正常下载冲突的问题
2025-02-13 18:57:39 +08:00
何冠峰
a6ee571d65 update file system 2025-02-13 18:56:24 +08:00
何冠峰
a138701afe update extension sample
抖音小游戏支持资源加密
2025-02-13 12:12:52 +08:00
何冠峰
e52bdea255 fix #467
微信小游戏资源加密
2025-02-13 12:02:09 +08:00
何冠峰
068a712a30 Merge pull request #470 from suxf/dev
fix: 微信加密资源解密错误
2025-02-13 10:13:28 +08:00
枫似锦
80a5300648 fix: 微信加密资源解密错误 2025-02-13 00:12:26 +08:00
何冠峰
0c36e458f7 update space shooter 2025-02-12 17:43:15 +08:00
何冠峰
b2fa52e4c4 update AssetArtScanner 2025-02-12 17:43:07 +08:00
何冠峰
151e978e5b update space shoot 2025-02-12 16:29:26 +08:00
何冠峰
9e806861ec update extension sample 2025-02-12 16:28:31 +08:00
何冠峰
a9a9368b9b update test sample 2025-02-12 16:27:51 +08:00
何冠峰
7936ba31ea update file system
WebGL网页平台支持资源加密。
2025-02-12 16:27:30 +08:00
何冠峰
afc456de9a Update UnloadAllAssetsOperation.cs 2025-02-12 14:44:02 +08:00
何冠峰
a98db0ba83 update extension sample 2025-02-12 14:43:51 +08:00
何冠峰
fb8720edd3 update extension sample
抖音小游戏支持文件加密。
2025-02-12 11:59:09 +08:00
何冠峰
2aa2a0ac3a update space shooter 2025-02-12 11:46:38 +08:00
何冠峰
0531b6ef3a update extension sample 2025-02-12 11:45:12 +08:00
何冠峰
24142de11f update extension sample
支持微信小游戏文件加密
2025-02-12 11:23:27 +08:00
何冠峰
7fad6eb70b update services
增加WebGL端解密接口
2025-02-12 11:22:09 +08:00
何冠峰
f60227abdf Merge pull request #469 from suxf/dev
优化微信小游戏文件系统逻辑
2025-02-12 10:10:32 +08:00
枫似锦
18d6a74c53 Merge branch 'dev' of https://github.com/suxf/YooAsset into dev 2025-02-12 00:30:22 +08:00
枫似锦
03d06ba657 优化微信小游戏文件系统逻辑 2025-02-12 00:29:10 +08:00
何冠峰
07086b68c8 update extension sample
优化了抖音小游戏文件系统缓存机制
2025-02-11 18:44:51 +08:00
何冠峰
0a85f3126f update extension sample
优化了微信小游戏文件系统缓存机制。
2025-02-11 18:18:29 +08:00
何冠峰
efa4180340 update resource manager
UnloadUnusedAssetsOperation逻辑里移除了Resources.UnloadUnusedAssets调用
2025-02-11 18:15:45 +08:00
何冠峰
fb06f2aa11 update resource manager
UnloadAllAssetsAsync新增UnloadAllAssetsOptions参数
2025-02-11 17:32:31 +08:00
何冠峰
ce023cedb8 update extension sample 2025-02-11 15:13:45 +08:00
何冠峰
3d1a28a50e update file system 2025-02-11 15:09:23 +08:00
何冠峰
5d2d0b4168 fix #341 2025-02-11 10:20:33 +08:00
何冠峰
fa985a5a93 Merge branch 'dev' of https://github.com/tuyoogame/YooAsset into dev 2025-02-11 09:55:38 +08:00
何冠峰
40f9937b60 update space shooter 2025-02-11 09:55:37 +08:00
何冠峰
c543c629c3 Merge pull request #466 from suxf/dev
fix:微信小游戏缓存文件系统查询机制不生效
2025-02-11 09:43:16 +08:00
何冠峰
f861279c49 Update CHANGELOG.md 2025-02-10 20:04:35 +08:00
何冠峰
ee89f81d46 Update package.json 2025-02-10 20:04:31 +08:00
何冠峰
6d216561f8 fix #468 2025-02-10 20:00:48 +08:00
枫似锦
0a96e583d3 Merge branch 'dev' of https://github.com/suxf/YooAsset into dev 2025-02-10 16:39:31 +08:00
枫似锦
c9d263c60d fix:微信小游戏缓存文件系统查询机制不生效 2025-02-10 16:38:23 +08:00
何冠峰
2d6488abf4 update AssetArtScanner
配置和报告容错性检测
2025-02-10 16:21:43 +08:00
何冠峰
7dfbac4a24 update AssetBundleCollector 2025-02-10 16:19:07 +08:00
何冠峰
7cfe4cb2c9 fix #465 2025-02-10 16:17:38 +08:00
何冠峰
30cba8ca5f Update CHANGELOG.md 2025-02-08 14:43:41 +08:00
何冠峰
e9261a0ec0 Update package.json 2025-02-08 14:43:39 +08:00
何冠峰
89ee22837d Update BuildParameters.cs 2025-02-08 14:35:10 +08:00
何冠峰
939f3747cd Update AssetBundleCollectorSetting.cs 2025-02-08 14:07:20 +08:00
何冠峰
f72814a51b fix #462 2025-02-08 11:45:06 +08:00
何冠峰
94ee2ba5c1 update test sample 2025-02-08 10:10:39 +08:00
何冠峰
fd9533d63f update extension sample 2025-02-08 10:10:18 +08:00
何冠峰
6571faae4e update AssetBundleBuilder
ScriptableBuildParameters类新增BuiltinShadersBundleName和MonoScriptsBundleName字段
2025-02-08 10:09:52 +08:00
何冠峰
e031498d5b update UIElements 2025-02-07 18:47:05 +08:00
何冠峰
31a0017351 Merge pull request #455 from suxf/dev
fix: 拷贝内置资源路径不正确
2025-02-07 16:27:15 +08:00
何冠峰
6e8cb0366d update extension sample
抖音小游戏文件重命名
2025-02-07 16:21:25 +08:00
何冠峰
a02b3fbf6e update extension sample
优化了小游戏文件系统的缓存机制。
2025-02-07 15:30:53 +08:00
何冠峰
37a663e0e1 update file system 2025-02-07 15:26:49 +08:00
何冠峰
e925d9892f fix #448 2025-02-06 17:43:40 +08:00
何冠峰
e7907eeaa7 fix #454
内置文件系统新增COPY_BUILDIN_PACKAGE_MANIFEST参数
2025-02-06 17:35:10 +08:00
何冠峰
644e6655ff update extension sample 2025-02-06 16:44:25 +08:00
何冠峰
20c07af504 update YooAssetSettings 2025-02-06 16:43:55 +08:00
何冠峰
38471cdd6c fix #452 2025-02-06 11:49:21 +08:00
何冠峰
0b5d16bd0e fix #456 2025-02-06 11:15:09 +08:00
何冠峰
203b9994df update AssetArtReporter 2025-02-05 19:04:05 +08:00
何冠峰
e76bbb6a85 update space shooter 2025-02-05 18:49:20 +08:00
何冠峰
4e6c146bde update UIElements 2025-02-05 18:49:11 +08:00
何冠峰
7e1dc7ef24 update UIElements 2025-02-05 17:26:19 +08:00
何冠峰
698d81a433 update AssetBundleDebugger 2025-02-05 10:51:31 +08:00
何冠峰
012f9b9f03 update UIElements 2025-02-05 10:38:47 +08:00
何冠峰
12bd282ace update space shooter 2025-01-24 00:43:27 +08:00
何冠峰
31a89fa1a3 update asset art reporter 2025-01-24 00:43:16 +08:00
何冠峰
57d1e92e59 update space shooter 2025-01-23 15:01:48 +08:00
何冠峰
377fca20d9 Update AssetArtReporterWindow.cs 2025-01-22 20:00:47 +08:00
何冠峰
415f844982 update asset art scanner 2025-01-22 19:17:05 +08:00
何冠峰
cbb8472153 update space shooter 2025-01-22 18:29:08 +08:00
何冠峰
c85ced89ef update space shooter 2025-01-22 18:28:15 +08:00
何冠峰
d5b8c90c94 update asset art scanner 2025-01-22 18:28:01 +08:00
何冠峰
9bcfb04f91 update space shooter 2025-01-22 17:23:23 +08:00
何冠峰
ae0fbd4b10 update asset art scanner 2025-01-22 17:22:45 +08:00
何冠峰
ef4f011cf6 update asset art scanner 2025-01-22 16:33:33 +08:00
何冠峰
7cc985205a update AssetArtScanner
资源扫描工具
2025-01-22 15:19:16 +08:00
何冠峰
a38b76eb8f update UIElements 2025-01-22 15:16:44 +08:00
阿枫
9f844912cf fix: 拷贝内置资源路径不正确 2025-01-21 14:10:35 +08:00
何冠峰
d72b0b10d4 update asset bundle reporter 2025-01-20 19:14:45 +08:00
何冠峰
655f756d56 update asset bundle debugger 2025-01-20 19:14:29 +08:00
何冠峰
912e2c28a3 update UIElements 2025-01-20 19:12:23 +08:00
何冠峰
9add447566 update asset bundle reporter 2025-01-20 17:14:47 +08:00
何冠峰
7c435f6dc0 update UIElements 2025-01-20 17:13:20 +08:00
何冠峰
5e2fc84ebf update UIElements 2025-01-20 10:07:16 +08:00
何冠峰
793a57647d update table view
新增单元格视图类
2025-01-17 16:23:31 +08:00
何冠峰
c32e7bc525 Update YooAssets.cs 2025-01-17 15:21:35 +08:00
何冠峰
20fac33efc fix #424 2025-01-14 16:43:44 +08:00
何冠峰
8cf356cadb fix #447 2025-01-14 16:03:24 +08:00
何冠峰
17d2c8bf0a Update CHANGELOG.md 2025-01-14 14:32:21 +08:00
何冠峰
3dec5ac004 Update LICENSE.md 2025-01-14 14:32:11 +08:00
何冠峰
cf2ada8f2b Update package.json 2025-01-14 14:32:08 +08:00
何冠峰
c801f601d3 fix #438 2025-01-14 14:19:24 +08:00
何冠峰
6a97704dab update test sample 2025-01-07 15:14:43 +08:00
何冠峰
ee6c8301c4 update asset bundle builder 2025-01-07 10:06:03 +08:00
何冠峰
de35f4308d update extension sample
修复小游戏插件验证清单方法不对的问题
2025-01-04 15:59:12 +08:00
何冠峰
3d4ed38f17 update extension sample
修正扩展文件系统类编译错误
2025-01-04 14:10:10 +08:00
何冠峰
a84f981147 update test scene 2025-01-03 19:15:51 +08:00
何冠峰
b70d821384 update space shooter 2025-01-03 19:15:38 +08:00
何冠峰
bc7c6c1f33 update package invoke builder
新增包裹构建器,运行时构建资源包裹
2025-01-03 19:15:29 +08:00
何冠峰
2a8761c29e Update CHANGELOG.md 2025-01-03 18:10:59 +08:00
何冠峰
0c732755ec Update package.json 2025-01-03 18:10:53 +08:00
何冠峰
5c638d713e update space shooter 2025-01-03 17:49:20 +08:00
何冠峰
8ff16f7205 update test sample 2025-01-03 17:27:04 +08:00
何冠峰
6bf8e3643b fix #428 2025-01-03 15:44:44 +08:00
何冠峰
6ab704bb77 fix #435 2025-01-03 15:37:32 +08:00
何冠峰
41329f3bbc update space shooter 2025-01-03 15:09:29 +08:00
何冠峰
a59ebd69b4 update extension sample 2025-01-03 15:09:20 +08:00
何冠峰
278b6e3cc8 fix #429
ClearCacheBundleFilesAsync重命名为ClearCacheFilesAsync
2025-01-03 15:08:57 +08:00
何冠峰
1d0c0ee7cb update asset bundle collector 2025-01-03 10:23:27 +08:00
何冠峰
a8bf0a62fa update asset bundle collector
增加视频文件打包规则
2025-01-02 20:56:18 +08:00
何冠峰
fc58fb27e2 Update AssemblyInfo.cs 2025-01-02 20:55:57 +08:00
何冠峰
b1abeb4ec2 update test sample
单元测试用例
2025-01-02 20:55:47 +08:00
何冠峰
d9b7f33bde update space shooter 2025-01-02 20:15:20 +08:00
何冠峰
c0a1061204 update extension sample
更新抖音小游戏文件系统
2025-01-02 18:45:54 +08:00
何冠峰
7cbdfeec51 fix #434 2025-01-02 15:58:49 +08:00
何冠峰
381c16d574 update space shooter 2025-01-02 14:10:21 +08:00
何冠峰
3e6be2f293 update resource package 2025-01-02 14:10:11 +08:00
何冠峰
1bd62c4673 update space shooter 2025-01-02 10:51:32 +08:00
何冠峰
04aa4067cd update space shooter 2025-01-02 10:47:07 +08:00
何冠峰
499fb8239e fix #433 2025-01-02 10:46:52 +08:00
何冠峰
fe75491024 update resource manager
整理文件目录结构
2025-01-02 10:45:56 +08:00
何冠峰
8803003cf7 fix #432
FileSystemParameters.RootDirectory字段重命名为PackageRoot
2024-12-31 19:22:00 +08:00
何冠峰
5a850aef07 Update AssetBundleCollectorSettingData.cs 2024-12-31 16:43:50 +08:00
何冠峰
d1d6e023c4 update space shooter 2024-12-31 15:13:13 +08:00
何冠峰
4370ed544f update cache system 2024-12-31 11:15:46 +08:00
何冠峰
42c87519e1 Update SceneHandle.cs 2024-12-31 10:16:29 +08:00
何冠峰
769134eaf9 update cache system
移除ThreadSyncContext类
2024-12-31 10:16:20 +08:00
何冠峰
51b688bbdd fix #426 2024-12-31 10:02:01 +08:00
何冠峰
748e74e515 Update CHANGELOG.md 2024-12-30 17:13:07 +08:00
何冠峰
d1d3ad9869 Update package.json 2024-12-30 17:12:59 +08:00
何冠峰
f9b72a22ae fix #423 2024-12-30 16:27:50 +08:00
何冠峰
766cf90a19 fix #422 2024-12-30 10:27:04 +08:00
何冠峰
8a2dc86cf7 update code summary 2024-12-27 18:37:29 +08:00
何冠峰
5ca54b88fa update download system 2024-12-27 17:51:21 +08:00
何冠峰
7257c8778d Merge pull request #332 from Pro-Ly/dev
fix url path special cases
2024-12-27 17:45:00 +08:00
何冠峰
dc21696ae1 update extension sample
新增示例代码HandleBaseExtension
2024-12-27 17:34:22 +08:00
何冠峰
7f566e5388 update extension sample
重新整理目录结构
2024-12-27 17:29:00 +08:00
何冠峰
fe352ceb84 update operation system
新增字段PackageName
2024-12-27 17:23:55 +08:00
何冠峰
10750a0123 update space shooter 2024-12-27 17:08:59 +08:00
何冠峰
f2e6da649b update resource package
重构了下载器的委托方法
2024-12-27 17:08:39 +08:00
何冠峰
9737cd06dd Merge pull request #392 from absences/newv
upgrade deprecated event in newer version
2024-12-27 16:06:24 +08:00
何冠峰
df8cf4d9ca update extension sample 2024-12-27 16:04:01 +08:00
何冠峰
36b4cbb8c2 Update DefaultAddressRule.cs 2024-12-27 16:03:47 +08:00
何冠峰
bae84f65da Merge pull request #370 from BoysheO/patch-1
append an addressRule
2024-12-27 15:50:14 +08:00
何冠峰
313ec2d100 Merge pull request #418 from GodChouyu/dev
Fix a bug when initializing DefaultWebRemoteFileSystem.
2024-12-27 15:16:38 +08:00
何冠峰
bfda5ec952 Update CHANGELOG.md 2024-12-27 15:09:04 +08:00
何冠峰
248bdba839 Update package.json 2024-12-27 15:08:54 +08:00
何冠峰
75dd3d0e5e fix #410 2024-12-27 12:02:08 +08:00
何冠峰
8944ec0e02 fix #419
优化场景卸载逻辑
2024-12-27 11:53:55 +08:00
GodChouyu
25c5683a09 Fix a bug when initializing DefaultWebRemoteFileSystem. 2024-12-27 10:16:57 +08:00
何冠峰
069e29ac07 update resource manager 2024-12-27 10:07:15 +08:00
何冠峰
942e4bf672 fix #413 2024-12-26 21:53:02 +08:00
何冠峰
dca37a3794 update resource package 2024-12-26 21:35:44 +08:00
何冠峰
f84419b7a6 fix #417 2024-12-26 15:43:58 +08:00
何冠峰
aa3a049985 fix #414 2024-12-26 14:57:37 +08:00
何冠峰
3f8c7bd91f update space shooter 2024-12-26 12:17:37 +08:00
何冠峰
11984d6972 update asset bundle reporter 2024-12-26 12:17:18 +08:00
何冠峰
31b0a3fb54 update extension sample
移除冗余的命名空间
2024-12-26 10:55:58 +08:00
何冠峰
666d0b53a6 fix script compile error in unity 2020 2024-12-26 10:55:30 +08:00
unknown
02250c3352 upgrade deprecated method in newer version 2024-11-12 14:40:49 +08:00
BoysheO
9e2030c83d Update DefaultAddressRule.cs
添加一个寻址规则,效果极好
2024-09-10 11:36:46 +08:00
Pro-Ly
be3fa0b688 fix url path special cases 2024-07-31 23:28:47 +08:00
838 changed files with 23771 additions and 10720 deletions

View File

@@ -2,6 +2,397 @@
All notable changes to this package will be documented in this file.
## [2.3.4-preview] - 2025-03-08
### Improvements
- YooAsset支持了版本宏定义。
```csharp
YOO_ASSET_2
YOO_ASSET_2_3
YOO_ASSET_2_3_OR_NEWER
```
### Fixed
- (#389) 修复了禁用域重载(Reload Domain)的情况下,再次启动游戏报错的问题。
- (#496) 修复了文件系统参数RESUME_DOWNLOAD_MINMUM_SIZE传入int值会导致异常的错误。
- (#498) 修复了v2.3版本尝试加载安卓包内的原生资源包失败的问题。
### Added
- 新增了YooAssets.GetAllPackages()方法
```csharp
/// <summary>
/// 获取所有资源包裹
/// </summary>
public static List<ResourcePackage> GetAllPackages()
```
## [2.3.3-preview] - 2025-03-06
### Improvements
- 新增了异步操作任务调试器AssetBundleDebugger窗口-->OperationView视图模式
- 编辑器下模拟构建默认启用依赖关系数据库,可以大幅降低编辑器下启动游戏的时间。
- 单元测试用例增加加密解密测试用例。
### Fixed
- (#492) 修复了发布的MAC平台应用在启动的时候提示权限无法获取的问题。
## [2.3.2-preview] - 2025-02-27
### Fixed
- (2.3.1) 修复小游戏平台下载器不生效的问题。
- (#480) 修复了Unity工程打包导出时的报错。
### Added
- 下载器新增参数recursiveDownload
```csharp
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包
public ResourceDownloaderOperation CreateBundleDownloader()
```
- 新增CustomPlayMode模式
```csharp
/// <summary>
/// 自定义运行模式的初始化参数
/// </summary>
public class CustomPlayModeParameters : InitializeParameters
{
/// <summary>
/// 文件系统初始化参数列表
/// 注意:列表最后一个元素作为主文件系统!
/// </summary>
public List<FileSystemParameters> FileSystemParameterList;
}
```
## [2.3.1-preview] - 2025-02-25
**资源加载依赖计算方式还原为了1.5x版本的模式,只加载资源对象实际依赖的资源包,不再以资源对象所在资源包的依赖关系为加载标准**。
### Improvements
- 优化OperationSystem的更新机制异步加载的耗时降低了50%。
- 优化了Debugger窗口的显示页面BundleView页面增加资源包的引用列表。
- 优化了Reporter窗口的显示页面。
### Fixed
- 修复了怀旧依赖模式下TAG传染不正确的问题。
## [2.3.0-preview] - 2025-02-19
### Improvements
资源收集窗口列表元素支持手动上下拖拽排序!
资源扫描窗口列表元素支持手动上下拖拽排序!
### Added
- 新增了UIElements扩展类ReorderableListView
- 新增初始化方法
```csharp
public class YooAssets
{
/// <summary>
/// 设置异步系统参数,快速启动模式的开关
/// 注意:该模式默认开启
/// </summary>
public static void SetOperationSystemQuickStartMode(bool state)
}
```
- 新增打包构建参数
```csharp
public class BuildParameters
{
/// <summary>
/// 旧版依赖模式
/// 说明兼容YooAssets1.5.x版本
/// </summary>
public bool LegacyDependency = false;
}
```
### Fixed
- (#472) 修复了Unity6平台TableView视图无法显示问题。
- 修复了微信小游戏和抖音小游戏未正确使用插件的卸载方法。
## [2.2.12] - 2025-02-14
### Improvements
- WebGL网页平台支持文件加密。
- 微信小游戏平台支持文件加密。
- 抖音小游戏平台支持文件加密。
### Fixed
- (#466) 修复了微信小游戏文件系统查询机制不生效!
- (#341) 修复了微信小游戏的下载进度异常问题。
- (#471) 修复了Unity2019,Unity2020平台上TableView视图无法显示的问题。
### Added
- 新增了ResourcePackage.UnloadAllAssetsAsync(UnloadAllAssetsOptions options)方法
```csharp
public sealed class UnloadAllAssetsOptions
{
/// <summary>
/// 释放所有资源句柄,防止卸载过程中触发完成回调!
/// </summary>
public bool ReleaseAllHandles = true;
/// <summary>
/// 卸载过程中锁定加载操作,防止新的任务请求!
/// </summary>
public bool LockLoadOperation = true;
}
```
## [2.2.11] - 2025-02-10
### Improvements
- AssetArtScanner配置和生成报告的容错性检测。
### Fixed
- (#465) 修复了特殊情况下,没有配置资源包文件后缀名构建失败的问题。
- (#468) 修复了安卓平台二次启动加载原生文件或加密文件失败的问题。
## [2.2.10] - 2025-02-08
### Improvements
- 新增了可扩展的AssetArtScanner资源扫描工具详细请见官方说明文档。
- 优化了AssetBundleReporter页面。
- 优化了AssetBundleDebugger页面。
- 优化了微信小游戏文件系统的缓存查询机制。
- 优化了抖音小游戏文件系统的缓存查询机制。
### Fixed
- (#447) 修复了Unity2019平台代码编译错误问题。
- (#456) 修复了在Package未激活有效清单之前无法销毁的问题。
- (#452) 修复了内置文件系统类NeedPack方法总是返回TRUE的问题。
- (#424) 适配了Unity6000版本替换了过时方法。
### Added
- 新增了SBP构建管线构建参数BuiltinShadersBundleName
- 新增了SBP构建管线构建参数MonoScriptsBundleName
- 新增了全局构建管线构建参数SingleReferencedPackAlone
```csharp
/// <summary>
/// 对单独引用的共享资源进行独立打包
/// 说明:关闭该选项单独引用的共享资源将会构建到引用它的资源包内!
/// </summary>
public bool SingleReferencedPackAlone = true;
```
- 新增了内置文件系统初始化参数COPY_BUILDIN_PACKAGE_MANIFEST
```csharp
// 内置文件系统初始化的时候,自动拷贝内置清单到沙盒目录。
var systemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
systemParameters.AddParameter(FileSystemParametersDefine.COPY_BUILDIN_PACKAGE_MANIFEST, true);
```
## [2.2.9] - 2025-01-14
### Fixed
- (#438) 修复了纯血鸿蒙加载本地文件失败的问题。
- (#445) 修复了小游戏扩展文件系统脚本编译错误。
### Changed
- EditorSimulateModeHelper.SimulateBuild()方法变更
```csharp
public static PackageInvokeBuildResult SimulateBuild(string packageName);
```
## [2.2.8-preview] - 2025-01-03
新增了单元测试用例。
### Improvements
- EditorSimulateModeHelper.SimulateBuild()方法提供指定自定义构建类
```csharp
public class EditorSimulateBuildParam
{
/// <summary>
/// 模拟构建类所属程序集名称
/// </summary>
public string InvokeAssmeblyName = "YooAsset.Editor";
/// <summary>
/// 模拟构建执行的类名全称
/// 注意:类名必须包含命名空间!
/// </summary>
public string InvokeClassFullName = "YooAsset.Editor.AssetBundleSimulateBuilder";
/// <summary>
/// 模拟构建执行的方法名称
/// 注意:执行方法必须满足 BindingFlags.Public | BindingFlags.Static
/// </summary>
public string InvokeMethodName = "SimulateBuild";
}
```
- 文件清理方式新增清理缓存清单。
```csharp
/// <summary>
/// 文件清理方式
/// </summary>
public enum EFileClearMode
{
/// <summary>
/// 清理所有清单
/// </summary>
ClearAllManifestFiles,
/// <summary>
/// 清理未在使用的清单
/// </summary>
ClearUnusedManifestFiles,
}
```
### Fixed
- (#426) 修复了鸿蒙next平台加载内置文件路径报错的问题。
- (#428) 修复了鸿蒙next平台加载内置文件路径报错的问题。
- (#434) 修复了2.2版本 catalog文件对Json格式原生文件不记录的问题。
- (#435) 修复了WebGL平台调用MD5算法触发异常的问题。
### Added
- 新增了视频打包规则。
```csharp
/// <summary>
/// 打包视频文件
/// </summary>
[DisplayName("打包视频文件")]
public class PackVideoFile : IPackRule
```
### Changed
- 重命名FileSystemParameters.RootDirectory字段为PackageRoot
- 重命名ResourcePackage.ClearCacheBundleFilesAsync()方法为ClearCacheFilesAsync()
## [2.2.7-preview] - 2024-12-30
### Improvements
- 重构了下载器的委托方法。
- YooAssetSettings配置文件新增Package Manifest Prefix参数。
```csharp
/// <summary>
/// 资源清单前缀名称(默认为空)
/// </summary>
public string PackageManifestPrefix = string.Empty;
```
### Fixed
- (#422) 修复了同步加载场景的NotImplementedException异常报错。
- (#418) 修复了web远程文件系统初始化不正确的问题
- (#392) 修复了引擎版本代码兼容相关的警告。
- (#332) 修复了当用户的设备中有特殊字符时URL路径无法被正确识别的问题。
### Added
- 新增代码字段AsyncOperationBase.PackageName
### Changed
- 重命名DownloaderOperation.OnDownloadOver()方法为DownloaderFinish()
- 重命名DownloaderOperation.OnDownloadProgress()方法为DownloadUpdate()
- 重命名DownloaderOperation.OnDownloadError()方法为DownloadError()
- 重命名DownloaderOperation.OnStartDownloadFile()方法为DownloadFileBegin()
## [2.2.6-preview] - 2024-12-27
### Improvements
- 增强了对Steam平台DLC拓展包的支持。
```csharp
// 新增参数关闭Catalog目录查询内置文件的功能
var fileSystemParams = CreateDefaultBuildinFileSystemParameters();
fileSystemParams .AddParameter(FileSystemParametersDefine.DISABLE_CATALOG_FILE, true);
```
- 资源句柄基类提供了统一的Release方法。
```csharp
public abstract class HandleBase : IEnumerator, IDisposable
{
/// <summary>
/// 释放资源句柄
/// </summary>
public void Release();
/// <summary>
/// 释放资源句柄
/// </summary>
public void Dispose();
}
```
- 优化了场景卸载逻辑。
```csharp
//框架内不在区分主场景和附加场景。
//场景卸载后自动释放资源句柄。
```
### Fixed
- 修复了Unity2020版本提示的脚本编译错误。
- (#417) 修复了DefaultWebServerFileSystem文件系统内Catalog未起效的问题。
### Added
- 新增示例文件 GetCacheBundleSizeOperation.cs
可以获取指定Package的缓存资源总大小。
### Removed
- 移除了SceneHandle.IsMainScene()方法。
## [2.2.5-preview] - 2024-12-25
依赖的ScriptableBuildPipeline (SBP) 插件库版本切换为1.21.25版本!

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: ce78de82d3ce1a841a1e6bad099e0bab
guid: fab3cd742c11be2479b07f5d447a78c9
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -0,0 +1,109 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using UnityEditor;
namespace YooAsset.Editor
{
[InitializeOnLoad]
public class MacrosProcessor : AssetPostprocessor
{
static MacrosProcessor()
{
}
/// <summary>
/// YooAsset版本宏定义
/// </summary>
private static readonly List<string> YooAssetMacros = new List<string>()
{
"YOO_ASSET_2",
"YOO_ASSET_2_3",
"YOO_ASSET_2_3_OR_NEWER",
};
static string OnGeneratedCSProject(string path, string content)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(content);
if (IsCSProjectReferenced(xmlDoc.DocumentElement) == false)
return content;
if (ProcessDefineConstants(xmlDoc.DocumentElement) == false)
return content;
// 将修改后的XML结构重新输出为文本
var stringWriter = new StringWriter();
var writerSettings = new XmlWriterSettings();
writerSettings.Indent = true;
var xmlWriter = XmlWriter.Create(stringWriter, writerSettings);
xmlDoc.WriteTo(xmlWriter);
xmlWriter.Flush();
return stringWriter.ToString();
}
/// <summary>
/// 处理宏定义
/// </summary>
private static bool ProcessDefineConstants(XmlElement element)
{
if (element == null)
return false;
bool processed = false;
foreach (XmlNode node in element.ChildNodes)
{
if (node.Name != "PropertyGroup")
continue;
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.Name != "DefineConstants")
continue;
string[] defines = childNode.InnerText.Split(';');
HashSet<string> hashSets = new HashSet<string>(defines);
foreach (string yooMacro in YooAssetMacros)
{
string tmpMacro = yooMacro.Trim();
if (hashSets.Contains(tmpMacro) == false)
hashSets.Add(tmpMacro);
}
childNode.InnerText = string.Join(";", hashSets.ToArray());
processed = true;
}
}
return processed;
}
/// <summary>
/// 检测工程是否引用了YooAsset
/// </summary>
private static bool IsCSProjectReferenced(XmlElement element)
{
if (element == null)
return false;
foreach (XmlNode node in element.ChildNodes)
{
if (node.Name != "ItemGroup")
continue;
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.Name != "Reference" && childNode.Name != "ProjectReference")
continue;
string include = childNode.Attributes["Include"].Value;
if (include.Contains("YooAsset"))
return true;
}
}
return false;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 1c8ce2c52a3e9964fa50a9c031e4e593
guid: 88d5a41d078a82e40b82265ed4c3631a
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 58462a7dcef164e43878a037395d4417
guid: bdbb4647038dcc842802f546c2fedc83
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -0,0 +1,624 @@
#if UNITY_2019_4_OR_NEWER
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class AssetArtReporterWindow : EditorWindow
{
[MenuItem("YooAsset/AssetArt Reporter", false, 302)]
public static AssetArtReporterWindow OpenWindow()
{
AssetArtReporterWindow window = GetWindow<AssetArtReporterWindow>("AssetArt Reporter", true, WindowsDefine.DockedWindowTypes);
window.minSize = new Vector2(800, 600);
return window;
}
private class ElementTableData : DefaultTableData
{
public ReportElement Element;
}
private class PassesBtnCell : ITableCell, IComparable
{
public object CellValue { set; get; }
public string SearchTag { private set; get; }
public ReportElement Element
{
get
{
return (ReportElement)CellValue;
}
}
public PassesBtnCell(string searchTag, ReportElement element)
{
SearchTag = searchTag;
CellValue = element;
}
public object GetDisplayObject()
{
return string.Empty;
}
public int CompareTo(object other)
{
if (other is PassesBtnCell cell)
{
return this.Element.Passes.CompareTo(cell.Element.Passes);
}
else
{
return 0;
}
}
}
private class WhiteListBtnCell : ITableCell, IComparable
{
public object CellValue { set; get; }
public string SearchTag { private set; get; }
public ReportElement Element
{
get
{
return (ReportElement)CellValue;
}
}
public WhiteListBtnCell(string searchTag, ReportElement element)
{
SearchTag = searchTag;
CellValue = element;
}
public object GetDisplayObject()
{
return string.Empty;
}
public int CompareTo(object other)
{
if (other is WhiteListBtnCell cell)
{
return this.Element.IsWhiteList.CompareTo(cell.Element.IsWhiteList);
}
else
{
return 0;
}
}
}
private ToolbarSearchField _searchField;
private Button _showHiddenBtn;
private Button _whiteListVisibleBtn;
private Button _passesVisibleBtn;
private Label _titleLabel;
private Label _descLabel;
private TableViewer _elementTableView;
private ScanReportCombiner _reportCombiner;
private string _lastestOpenFolder;
private List<ITableData> _sourceDatas;
private bool _elementVisibleState = true;
private bool _whiteListVisibleState = true;
private bool _passesVisibleState = true;
public void CreateGUI()
{
try
{
VisualElement root = this.rootVisualElement;
// 加载布局文件
var visualAsset = UxmlLoader.LoadWindowUXML<AssetArtReporterWindow>();
if (visualAsset == null)
return;
visualAsset.CloneTree(root);
// 导入按钮
var importSingleBtn = root.Q<Button>("SingleImportButton");
importSingleBtn.clicked += ImportSingleBtn_clicked;
var importMultiBtn = root.Q<Button>("MultiImportButton");
importMultiBtn.clicked += ImportMultiBtn_clicked;
// 修复按钮
var fixAllBtn = root.Q<Button>("FixAllButton");
fixAllBtn.clicked += FixAllBtn_clicked;
var fixSelectBtn = root.Q<Button>("FixSelectButton");
fixSelectBtn.clicked += FixSelectBtn_clicked;
// 可见性按钮
_showHiddenBtn = root.Q<Button>("ShowHiddenButton");
_showHiddenBtn.clicked += ShowHiddenBtn_clicked;
_whiteListVisibleBtn = root.Q<Button>("WhiteListVisibleButton");
_whiteListVisibleBtn.clicked += WhiteListVisibleBtn_clicked;
_passesVisibleBtn = root.Q<Button>("PassesVisibleButton");
_passesVisibleBtn.clicked += PassesVsibleBtn_clicked;
// 文件导出按钮
var exportFilesBtn = root.Q<Button>("ExportFilesButton");
exportFilesBtn.clicked += ExportFilesBtn_clicked;
// 搜索过滤
_searchField = root.Q<ToolbarSearchField>("SearchField");
_searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
// 标题和备注
_titleLabel = root.Q<Label>("ReportTitle");
_descLabel = root.Q<Label>("ReportDesc");
// 列表相关
_elementTableView = root.Q<TableViewer>("TopTableView");
_elementTableView.ClickTableDataEvent = OnClickTableViewItem;
_lastestOpenFolder = EditorTools.GetProjectPath();
}
catch (System.Exception e)
{
Debug.LogError(e.ToString());
}
}
public void OnDestroy()
{
if (_reportCombiner != null)
_reportCombiner.SaveChange();
}
/// <summary>
/// 导入单个报告文件
/// </summary>
public void ImportSingleReprotFile(string filePath)
{
// 记录本次打开目录
_lastestOpenFolder = Path.GetDirectoryName(filePath);
_reportCombiner = new ScanReportCombiner();
try
{
var scanReport = ScanReportConfig.ImportJsonConfig(filePath);
_reportCombiner.Combine(scanReport);
// 刷新页面
RefreshToolbar();
FillTableView();
RebuildView();
}
catch (System.Exception e)
{
_reportCombiner = null;
_titleLabel.text = "导入报告失败!";
_descLabel.text = e.Message;
UnityEngine.Debug.LogError(e.StackTrace);
}
}
private void ImportSingleBtn_clicked()
{
string selectFilePath = EditorUtility.OpenFilePanel("导入报告", _lastestOpenFolder, "json");
if (string.IsNullOrEmpty(selectFilePath))
return;
ImportSingleReprotFile(selectFilePath);
}
private void ImportMultiBtn_clicked()
{
string selectFolderPath = EditorUtility.OpenFolderPanel("导入报告", _lastestOpenFolder, null);
if (string.IsNullOrEmpty(selectFolderPath))
return;
// 记录本次打开目录
_lastestOpenFolder = selectFolderPath;
_reportCombiner = new ScanReportCombiner();
try
{
string[] files = Directory.GetFiles(selectFolderPath);
foreach (string filePath in files)
{
string extension = System.IO.Path.GetExtension(filePath);
if (extension == ".json")
{
var scanReport = ScanReportConfig.ImportJsonConfig(filePath);
_reportCombiner.Combine(scanReport);
}
}
// 刷新页面
RefreshToolbar();
FillTableView();
RebuildView();
}
catch (System.Exception e)
{
_reportCombiner = null;
_titleLabel.text = "导入报告失败!";
_descLabel.text = e.Message;
UnityEngine.Debug.LogError(e.StackTrace);
}
}
private void FixAllBtn_clicked()
{
if (EditorUtility.DisplayDialog("提示", "修复全部资源(排除白名单和隐藏元素)", "Yes", "No"))
{
if (_reportCombiner != null)
_reportCombiner.FixAll();
}
}
private void FixSelectBtn_clicked()
{
if (EditorUtility.DisplayDialog("提示", "修复勾选资源(包含白名单和隐藏元素)", "Yes", "No"))
{
if (_reportCombiner != null)
_reportCombiner.FixSelect();
}
}
private void ShowHiddenBtn_clicked()
{
_elementVisibleState = !_elementVisibleState;
RefreshToolbar();
RebuildView();
}
private void WhiteListVisibleBtn_clicked()
{
_whiteListVisibleState = !_whiteListVisibleState;
RefreshToolbar();
RebuildView();
}
private void PassesVsibleBtn_clicked()
{
_passesVisibleState = !_passesVisibleState;
RefreshToolbar();
RebuildView();
}
private void ExportFilesBtn_clicked()
{
string selectFolderPath = EditorUtility.OpenFolderPanel("导入所有选中资源", EditorTools.GetProjectPath(), string.Empty);
if (string.IsNullOrEmpty(selectFolderPath) == false)
{
if (_reportCombiner != null)
_reportCombiner.ExportFiles(selectFolderPath);
}
}
private void RefreshToolbar()
{
if (_reportCombiner == null)
return;
_titleLabel.text = _reportCombiner.ReportTitle;
_descLabel.text = _reportCombiner.ReportDesc;
var enableColor = new Color32(18, 100, 18, 255);
var disableColor = new Color32(100, 100, 100, 255);
if (_elementVisibleState)
_showHiddenBtn.style.backgroundColor = new StyleColor(enableColor);
else
_showHiddenBtn.style.backgroundColor = new StyleColor(disableColor);
if (_whiteListVisibleState)
_whiteListVisibleBtn.style.backgroundColor = new StyleColor(enableColor);
else
_whiteListVisibleBtn.style.backgroundColor = new StyleColor(disableColor);
if (_passesVisibleState)
_passesVisibleBtn.style.backgroundColor = new StyleColor(enableColor);
else
_passesVisibleBtn.style.backgroundColor = new StyleColor(disableColor);
}
private void FillTableView()
{
if (_reportCombiner == null)
return;
_elementTableView.ClearAll(true, true);
// 眼睛标题
{
var columnStyle = new ColumnStyle(20);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = false;
var column = new TableColumn("眼睛框", string.Empty, columnStyle);
column.MakeCell = () =>
{
var toggle = new ToggleDisplay();
toggle.text = string.Empty;
toggle.style.unityTextAlign = TextAnchor.MiddleCenter;
toggle.RegisterValueChangedCallback((evt) => { OnDisplayToggleValueChange(toggle, evt); });
return toggle;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var toggle = element as ToggleDisplay;
toggle.userData = data;
var tableData = data as ElementTableData;
toggle.SetValueWithoutNotify(tableData.Element.Hidden);
};
_elementTableView.AddColumn(column);
var headerElement = _elementTableView.GetHeaderElement("眼睛框");
headerElement.style.unityTextAlign = TextAnchor.MiddleCenter;
}
// 通过标题
{
var columnStyle = new ColumnStyle(70);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("通过", "通过", columnStyle);
column.MakeCell = () =>
{
var button = new Button();
button.text = "通过";
button.style.unityTextAlign = TextAnchor.MiddleCenter;
button.SetEnabled(false);
return button;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
Button button = element as Button;
var elementTableData = data as ElementTableData;
if (elementTableData.Element.Passes)
{
button.style.backgroundColor = new StyleColor(new Color32(56, 147, 58, 255));
button.text = "通过";
}
else
{
button.style.backgroundColor = new StyleColor(new Color32(137, 0, 0, 255));
button.text = "失败";
}
};
_elementTableView.AddColumn(column);
var headerElement = _elementTableView.GetHeaderElement("通过");
headerElement.style.unityTextAlign = TextAnchor.MiddleCenter;
}
// 白名单标题
{
var columnStyle = new ColumnStyle(70);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("白名单", "白名单", columnStyle);
column.MakeCell = () =>
{
Button button = new Button();
button.text = "白名单";
button.style.unityTextAlign = TextAnchor.MiddleCenter;
button.clickable.clickedWithEventInfo += OnClickWhitListButton;
return button;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
Button button = element as Button;
button.userData = data;
var elementTableData = data as ElementTableData;
if (elementTableData.Element.IsWhiteList)
button.style.backgroundColor = new StyleColor(new Color32(56, 147, 58, 255));
else
button.style.backgroundColor = new StyleColor(new Color32(100, 100, 100, 255));
};
_elementTableView.AddColumn(column);
var headerElement = _elementTableView.GetHeaderElement("白名单");
headerElement.style.unityTextAlign = TextAnchor.MiddleCenter;
}
// 选中标题
{
var columnStyle = new ColumnStyle(20);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = false;
var column = new TableColumn("选中框", string.Empty, columnStyle);
column.MakeCell = () =>
{
var toggle = new Toggle();
toggle.text = string.Empty;
toggle.style.unityTextAlign = TextAnchor.MiddleCenter;
toggle.RegisterValueChangedCallback((evt) => { OnSelectToggleValueChange(toggle, evt); });
return toggle;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var toggle = element as Toggle;
toggle.userData = data;
var tableData = data as ElementTableData;
toggle.SetValueWithoutNotify(tableData.Element.IsSelected);
};
_elementTableView.AddColumn(column);
}
// 自定义标题栏
foreach (var header in _reportCombiner.Headers)
{
var columnStyle = new ColumnStyle(header.Width, header.MinWidth, header.MaxWidth);
columnStyle.Stretchable = header.Stretchable;
columnStyle.Searchable = header.Searchable;
columnStyle.Sortable = header.Sortable;
columnStyle.Counter = header.Counter;
columnStyle.Units = header.Units;
var column = new TableColumn(header.HeaderTitle, header.HeaderTitle, columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.marginLeft = 3f;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_elementTableView.AddColumn(column);
}
// 填充数据源
_sourceDatas = new List<ITableData>(_reportCombiner.Elements.Count);
foreach (var element in _reportCombiner.Elements)
{
var tableData = new ElementTableData();
tableData.Element = element;
// 固定标题
tableData.AddButtonCell("眼睛框");
tableData.AddCell(new PassesBtnCell("通过", element));
tableData.AddCell(new WhiteListBtnCell("白名单", element));
tableData.AddButtonCell("选中框");
// 自定义标题
foreach (var scanInfo in element.ScanInfos)
{
var header = _reportCombiner.GetHeader(scanInfo.HeaderTitle);
if (header.HeaderType == EHeaderType.AssetPath)
{
tableData.AddAssetPathCell(scanInfo.HeaderTitle, scanInfo.ScanInfo);
}
else if (header.HeaderType == EHeaderType.StringValue)
{
tableData.AddStringValueCell(scanInfo.HeaderTitle, scanInfo.ScanInfo);
}
else if (header.HeaderType == EHeaderType.LongValue)
{
long value = Convert.ToInt64(scanInfo.ScanInfo);
tableData.AddLongValueCell(scanInfo.HeaderTitle, value);
}
else if (header.HeaderType == EHeaderType.DoubleValue)
{
double value = Convert.ToDouble(scanInfo.ScanInfo);
tableData.AddDoubleValueCell(scanInfo.HeaderTitle, value);
}
else
{
throw new NotImplementedException(header.HeaderType.ToString());
}
}
_sourceDatas.Add(tableData);
}
_elementTableView.itemsSource = _sourceDatas;
}
private void RebuildView()
{
if (_reportCombiner == null)
return;
string searchKeyword = _searchField.value;
// 搜索匹配
DefaultSearchSystem.Search(_sourceDatas, searchKeyword);
// 开关匹配
foreach (var tableData in _sourceDatas)
{
var elementTableData = tableData as ElementTableData;
if (_elementVisibleState == false && elementTableData.Element.Hidden)
{
tableData.Visible = false;
continue;
}
if (_passesVisibleState == false && elementTableData.Element.Passes)
{
tableData.Visible = false;
continue;
}
if (_whiteListVisibleState == false && elementTableData.Element.IsWhiteList)
{
tableData.Visible = false;
continue;
}
}
// 重建视图
_elementTableView.RebuildView();
}
private void OnClickTableViewItem(PointerDownEvent evt, ITableData tableData)
{
// 双击后检视对应的资源
if (evt.clickCount == 2)
{
foreach (var cell in tableData.Cells)
{
if (cell is AssetPathCell assetPathCell)
{
if (assetPathCell.PingAssetObject())
break;
}
}
}
}
private void OnSearchKeyWordChange(ChangeEvent<string> e)
{
RebuildView();
}
private void OnSelectToggleValueChange(Toggle toggle, ChangeEvent<bool> e)
{
// 处理自身
toggle.SetValueWithoutNotify(e.newValue);
// 记录数据
var elementTableData = toggle.userData as ElementTableData;
elementTableData.Element.IsSelected = e.newValue;
// 处理多选目标
var selectedItems = _elementTableView.selectedItems;
foreach (var selectedItem in selectedItems)
{
var selectElement = selectedItem as ElementTableData;
selectElement.Element.IsSelected = e.newValue;
}
// 重绘视图
RebuildView();
}
private void OnDisplayToggleValueChange(ToggleDisplay toggle, ChangeEvent<bool> e)
{
// 处理自身
toggle.SetValueWithoutNotify(e.newValue);
// 记录数据
var elementTableData = toggle.userData as ElementTableData;
elementTableData.Element.Hidden = e.newValue;
// 处理多选目标
var selectedItems = _elementTableView.selectedItems;
foreach (var selectedItem in selectedItems)
{
var selectElement = selectedItem as ElementTableData;
if (selectElement != null)
selectElement.Element.Hidden = e.newValue;
}
// 重绘视图
RebuildView();
}
private void OnClickWhitListButton(EventBase evt)
{
// 刷新点击的按钮
Button button = evt.target as Button;
var elementTableData = button.userData as ElementTableData;
elementTableData.Element.IsWhiteList = !elementTableData.Element.IsWhiteList;
// 刷新框选的按钮
var selectedItems = _elementTableView.selectedItems;
if (selectedItems.Count() > 1)
{
foreach (var selectedItem in selectedItems)
{
var selectElement = selectedItem as ElementTableData;
selectElement.Element.IsWhiteList = selectElement.Element.IsWhiteList;
}
}
RebuildView();
}
}
}
#endif

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 0c3f4136cf7142346ae33e8a82cbdb27
guid: 4048f85b9ff1f424a89a9d6109e6faaf
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,22 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row;">
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
<ui:Button text="Fix Select" display-tooltip-when-elided="true" name="FixSelectButton" style="width: 80px; background-color: rgb(56, 147, 58);" />
<ui:Button text="Fix All" display-tooltip-when-elided="true" name="FixAllButton" style="width: 80px; background-color: rgb(56, 147, 58);" />
<ui:Button text="Export Select" display-tooltip-when-elided="true" name="ExportFilesButton" style="width: 100px; background-color: rgb(56, 147, 58);" />
<ui:Button text=" Multi-Import" display-tooltip-when-elided="true" name="MultiImportButton" style="width: 100px; background-color: rgb(56, 147, 58);" />
<ui:Button text="Import" display-tooltip-when-elided="true" name="SingleImportButton" style="width: 100px; background-color: rgb(56, 147, 58);" />
</uie:Toolbar>
<ui:VisualElement name="PublicContainer" style="background-color: rgb(79, 79, 79); flex-direction: column; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
<ui:Label text="标题" display-tooltip-when-elided="true" name="ReportTitle" style="height: 16px; -unity-font-style: bold; -unity-text-align: middle-center;" />
<ui:Label text="说明" display-tooltip-when-elided="true" name="ReportDesc" style="-unity-text-align: upper-left; -unity-font-style: bold; background-color: rgb(42, 42, 42); min-height: 50px; border-top-left-radius: 3px; border-bottom-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; white-space: normal;" />
</ui:VisualElement>
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row;">
<ui:Button text="显示隐藏元素" display-tooltip-when-elided="true" name="ShowHiddenButton" style="width: 100px;" />
<ui:Button text="显示通过元素" display-tooltip-when-elided="true" name="PassesVisibleButton" style="width: 100px;" />
<ui:Button text="显示白名单元素" display-tooltip-when-elided="true" name="WhiteListVisibleButton" style="width: 100px;" />
</uie:Toolbar>
<ui:VisualElement name="AssetGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
<YooAsset.Editor.TableViewer name="TopTableView" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b87fc70b750616849942173af3bdfd90
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -0,0 +1,26 @@

namespace YooAsset.Editor
{
public enum EHeaderType
{
/// <summary>
/// 资源路径
/// </summary>
AssetPath,
/// <summary>
/// 字符串
/// </summary>
StringValue,
/// <summary>
/// 整数数值
/// </summary>
LongValue,
/// <summary>
/// 浮点数数值
/// </summary>
DoubleValue,
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f878bc9a12f5d2d40aee754ddfaada86
guid: 97cd7d0d616708e42bc53ed7d88718c9
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,88 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset.Editor
{
[Serializable]
public class ReportElement
{
/// <summary>
/// GUID白名单存储对象
/// </summary>
public string GUID;
/// <summary>
/// 扫描是否通过
/// </summary>
public bool Passes = true;
/// <summary>
/// 反馈的信息列表
/// </summary>
public List<ReportScanInfo> ScanInfos = new List<ReportScanInfo>();
public ReportElement(string guid)
{
GUID = guid;
}
/// <summary>
/// 添加扫描信息
/// </summary>
public void AddScanInfo(string headerTitle, string value)
{
var reportScanInfo = new ReportScanInfo(headerTitle, value);
ScanInfos.Add(reportScanInfo);
}
/// <summary>
/// 添加扫描信息
/// </summary>
public void AddScanInfo(string headerTitle, long value)
{
AddScanInfo(headerTitle, value.ToString());
}
/// <summary>
/// 添加扫描信息
/// </summary>
public void AddScanInfo(string headerTitle, double value)
{
AddScanInfo(headerTitle, value.ToString());
}
/// <summary>
/// 获取扫描信息
/// </summary>
public ReportScanInfo GetScanInfo(string headerTitle)
{
foreach (var scanInfo in ScanInfos)
{
if (scanInfo.HeaderTitle == headerTitle)
return scanInfo;
}
UnityEngine.Debug.LogWarning($"Not found {nameof(ReportScanInfo)} : {headerTitle}");
return null;
}
#region
/// <summary>
/// 是否在列表里选中
/// </summary>
public bool IsSelected { set; get; }
/// <summary>
/// 是否在白名单里
/// </summary>
public bool IsWhiteList { set; get; }
/// <summary>
/// 是否隐藏元素
/// </summary>
public bool Hidden { set; get; }
#endregion
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2fb1b9a2a91f1af4a86acfcfac424e0b
guid: d61f7ee1a8215bf438071055f0a9cb09
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,148 @@
using System;
using UnityEditor;
namespace YooAsset.Editor
{
[Serializable]
public class ReportHeader
{
public const int MaxValue = 8388608;
/// <summary>
/// 标题
/// </summary>
public string HeaderTitle;
/// <summary>
/// 标题宽度
/// </summary>
public int Width;
/// <summary>
/// 单元列最小宽度
/// </summary>
public int MinWidth = 50;
/// <summary>
/// 单元列最大宽度
/// </summary>
public int MaxWidth = MaxValue;
/// <summary>
/// 可伸缩选项
/// </summary>
public bool Stretchable = false;
/// <summary>
/// 可搜索选项
/// </summary>
public bool Searchable = false;
/// <summary>
/// 可排序选项
/// </summary>
public bool Sortable = false;
/// <summary>
/// 统计数量
/// </summary>
public bool Counter = false;
/// <summary>
/// 展示单位
/// </summary>
public string Units = string.Empty;
/// <summary>
/// 数值类型
/// </summary>
public EHeaderType HeaderType = EHeaderType.StringValue;
public ReportHeader(string headerTitle, int width)
{
HeaderTitle = headerTitle;
Width = width;
MinWidth = width;
MaxWidth = width;
}
public ReportHeader(string headerTitle, int width, int minWidth, int maxWidth)
{
HeaderTitle = headerTitle;
Width = width;
MinWidth = minWidth;
MaxWidth = maxWidth;
}
public ReportHeader SetMinWidth(int value)
{
MinWidth = value;
return this;
}
public ReportHeader SetMaxWidth(int value)
{
MaxWidth = value;
return this;
}
public ReportHeader SetStretchable()
{
Stretchable = true;
return this;
}
public ReportHeader SetSearchable()
{
Searchable = true;
return this;
}
public ReportHeader SetSortable()
{
Sortable = true;
return this;
}
public ReportHeader SetCounter()
{
Counter = true;
return this;
}
public ReportHeader SetUnits(string units)
{
Units = units;
return this;
}
public ReportHeader SetHeaderType(EHeaderType value)
{
HeaderType = value;
return this;
}
/// <summary>
/// 检测数值有效性
/// </summary>
public void CheckValueValid(string value)
{
if (HeaderType == EHeaderType.AssetPath)
{
string guid = AssetDatabase.AssetPathToGUID(value);
if (string.IsNullOrEmpty(guid))
throw new Exception($"{HeaderTitle} value is invalid asset path : {value}");
}
else if (HeaderType == EHeaderType.DoubleValue)
{
if (double.TryParse(value, out double doubleValue) == false)
throw new Exception($"{HeaderTitle} value is invalid double value : {value}");
}
else if (HeaderType == EHeaderType.LongValue)
{
if (long.TryParse(value, out long longValue) == false)
throw new Exception($"{HeaderTitle} value is invalid long value : {value}");
}
else if (HeaderType == EHeaderType.StringValue)
{
}
else
{
throw new System.NotImplementedException(HeaderType.ToString());
}
}
}
}

View File

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

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset.Editor
{
[Serializable]
public class ReportScanInfo
{
/// <summary>
/// 标题
/// </summary>
public string HeaderTitle;
/// <summary>
/// 扫描反馈的信息
/// </summary>
public string ScanInfo;
public ReportScanInfo(string headerTitle, string scanInfo)
{
HeaderTitle = headerTitle;
ScanInfo = scanInfo;
}
}
}

View File

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

View File

@@ -0,0 +1,118 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset.Editor
{
[Serializable]
public class ScanReport
{
/// <summary>
/// 文件签名(自动填写)
/// </summary>
public string FileSign;
/// <summary>
/// 文件版本(自动填写)
/// </summary>
public string FileVersion;
/// <summary>
/// 模式类型(自动填写)
/// </summary>
public string SchemaType;
/// <summary>
/// 扫描器GUID自动填写
/// </summary>
public string ScannerGUID;
/// <summary>
/// 报告名称
/// </summary>
public string ReportName;
/// <summary>
/// 报告介绍
/// </summary>
public string ReportDesc;
/// <summary>
/// 报告的标题列表
/// </summary>
public List<ReportHeader> ReportHeaders = new List<ReportHeader>();
/// <summary>
/// 扫描的元素列表
/// </summary>
public List<ReportElement> ReportElements = new List<ReportElement>();
public ScanReport(string reportName, string reportDesc)
{
ReportName = reportName;
ReportDesc = reportDesc;
}
/// <summary>
/// 添加标题
/// </summary>
public ReportHeader AddHeader(string headerTitle, int width)
{
var reportHeader = new ReportHeader(headerTitle, width);
ReportHeaders.Add(reportHeader);
return reportHeader;
}
/// <summary>
/// 添加标题
/// </summary>
public ReportHeader AddHeader(string headerTitle, int width, int minWidth, int maxWidth)
{
var reportHeader = new ReportHeader(headerTitle, width, minWidth, maxWidth);
ReportHeaders.Add(reportHeader);
return reportHeader;
}
/// <summary>
/// 检测错误
/// </summary>
public void CheckError()
{
// 检测标题
Dictionary<string, ReportHeader> headerMap = new Dictionary<string, ReportHeader>();
foreach (var header in ReportHeaders)
{
string headerTitle = header.HeaderTitle;
if (headerMap.ContainsKey(headerTitle))
throw new Exception($"The header title {headerTitle} already exists !");
else
headerMap.Add(headerTitle, header);
}
// 检测扫描元素
HashSet<string> elementMap = new HashSet<string>();
foreach (var element in ReportElements)
{
if (string.IsNullOrEmpty(element.GUID))
throw new Exception($"The report element GUID is null or empty !");
if (elementMap.Contains(element.GUID))
throw new Exception($"The report element GUID already exists ! {element.GUID}");
else
elementMap.Add(element.GUID);
foreach (var scanInfo in element.ScanInfos)
{
if (headerMap.ContainsKey(scanInfo.HeaderTitle) == false)
throw new Exception($"The report element header {scanInfo.HeaderTitle} is missing !");
// 检测数值有效性
var header = headerMap[scanInfo.HeaderTitle];
header.CheckValueValid(scanInfo.ScanInfo);
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,221 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using UnityEngine;
using UnityEditor;
namespace YooAsset.Editor
{
/// <summary>
/// 资源扫描报告合并器
/// 说明:相同类型的报告可以合并查看
/// </summary>
public class ScanReportCombiner
{
/// <summary>
/// 模式类型
/// </summary>
public string SchemaType { private set; get; }
/// <summary>
/// 报告标题
/// </summary>
public string ReportTitle { private set; get; }
/// <summary>
/// 报告介绍
/// </summary>
public string ReportDesc { private set; get; }
/// <summary>
/// 标题列表
/// </summary>
public List<ReportHeader> Headers = new List<ReportHeader>();
/// <summary>
/// 扫描结果
/// </summary>
public readonly List<ReportElement> Elements = new List<ReportElement>(10000);
private readonly Dictionary<string, ScanReport> _combines = new Dictionary<string, ScanReport>(100);
/// <summary>
/// 合并报告文件
/// 注意:模式不同的报告文件会合并失败!
/// </summary>
public bool Combine(ScanReport scanReport)
{
if (string.IsNullOrEmpty(scanReport.SchemaType))
{
Debug.LogError("Scan report schema type is null or empty !");
return false;
}
if (string.IsNullOrEmpty(SchemaType))
{
SchemaType = scanReport.SchemaType;
ReportTitle = scanReport.ReportName;
ReportDesc = scanReport.ReportDesc;
Headers = scanReport.ReportHeaders;
}
if (SchemaType != scanReport.SchemaType)
{
Debug.LogWarning($"Scan report has different schema type{scanReport.SchemaType} != {SchemaType}");
return false;
}
if (_combines.ContainsKey(scanReport.ScannerGUID))
{
Debug.LogWarning($"Scan report has already existed : {scanReport.ScannerGUID}");
return false;
}
_combines.Add(scanReport.ScannerGUID, scanReport);
CombineInternal(scanReport);
return true;
}
private void CombineInternal(ScanReport scanReport)
{
string scannerGUID = scanReport.ScannerGUID;
List<ReportElement> elements = scanReport.ReportElements;
// 设置白名单
var scanner = AssetArtScannerSettingData.Setting.GetScanner(scannerGUID);
if (scanner != null)
{
foreach (var element in elements)
{
if (scanner.CheckWhiteList(element.GUID))
element.IsWhiteList = true;
}
}
// 添加到集合
Elements.AddRange(elements);
}
/// <summary>
/// 获取指定的标题类
/// </summary>
public ReportHeader GetHeader(string headerTitle)
{
foreach (var header in Headers)
{
if (header.HeaderTitle == headerTitle)
return header;
}
UnityEngine.Debug.LogWarning($"Not found {nameof(ReportHeader)} : {headerTitle}");
return null;
}
/// <summary>
/// 导出选中文件
/// </summary>
public void ExportFiles(string exportFolderPath)
{
if (string.IsNullOrEmpty(exportFolderPath))
return;
foreach (var element in Elements)
{
if (element.IsSelected)
{
string assetPath = AssetDatabase.GUIDToAssetPath(element.GUID);
if (string.IsNullOrEmpty(assetPath) == false)
{
string destPath = Path.Combine(exportFolderPath, assetPath);
EditorTools.CopyFile(assetPath, destPath, true);
}
}
}
}
/// <summary>
/// 保存改变数据
/// </summary>
public void SaveChange()
{
// 存储白名单
foreach (var scanReport in _combines.Values)
{
string scannerGUID = scanReport.ScannerGUID;
var elements = scanReport.ReportElements;
var scanner = AssetArtScannerSettingData.Setting.GetScanner(scannerGUID);
if (scanner != null)
{
List<string> whiteList = new List<string>(elements.Count);
foreach (var element in elements)
{
if (element.IsWhiteList)
whiteList.Add(element.GUID);
}
whiteList.Sort();
scanner.WhiteList = whiteList;
AssetArtScannerSettingData.SaveFile();
}
}
}
/// <summary>
/// 修复所有元素
/// 注意:排除白名单和隐藏元素
/// </summary>
public void FixAll()
{
foreach (var scanReport in _combines.Values)
{
string scannerGUID = scanReport.ScannerGUID;
var elements = scanReport.ReportElements;
List<ReportElement> fixList = new List<ReportElement>(elements.Count);
foreach (var element in elements)
{
if (element.Passes || element.IsWhiteList || element.Hidden)
continue;
fixList.Add(element);
}
FixInternal(scannerGUID, fixList);
}
}
/// <summary>
/// 修复选定元素
/// 注意:包含白名单和隐藏元素
/// </summary>
public void FixSelect()
{
foreach (var scanReport in _combines.Values)
{
string scannerGUID = scanReport.ScannerGUID;
var elements = scanReport.ReportElements;
List<ReportElement> fixList = new List<ReportElement>(elements.Count);
foreach (var element in elements)
{
if (element.Passes)
continue;
if (element.IsSelected)
fixList.Add(element);
}
FixInternal(scannerGUID, fixList);
}
}
private void FixInternal(string scannerGUID, List<ReportElement> fixList)
{
AssetArtScanner scanner = AssetArtScannerSettingData.Setting.GetScanner(scannerGUID);
if (scanner != null)
{
var schema = scanner.LoadSchema();
if (schema != null)
{
schema.FixResult(fixList);
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using UnityEngine;
namespace YooAsset.Editor
{
public class ScanReportConfig
{
/// <summary>
/// 导入JSON报告文件
/// </summary>
public static ScanReport ImportJsonConfig(string filePath)
{
if (File.Exists(filePath) == false)
throw new FileNotFoundException(filePath);
string jsonData = FileUtility.ReadAllText(filePath);
ScanReport report = JsonUtility.FromJson<ScanReport>(jsonData);
// 检测配置文件的签名
if (report.FileSign != ScannerDefine.ReportFileSign)
throw new Exception($"导入的报告文件无法识别 : {filePath}");
// 检测报告文件的版本
if (report.FileVersion != ScannerDefine.ReportFileVersion)
throw new Exception($"报告文件的版本不匹配 : {report.FileVersion} != {ScannerDefine.ReportFileVersion}");
// 检测标题数和内容是否匹配
foreach (var element in report.ReportElements)
{
if (element.ScanInfos.Count != report.ReportHeaders.Count)
{
throw new Exception($"报告的标题数和内容不匹配!");
}
}
return report;
}
/// <summary>
/// 导出JSON报告文件
/// </summary>
public static void ExportJsonConfig(string savePath, ScanReport scanReport)
{
if (File.Exists(savePath))
File.Delete(savePath);
string json = JsonUtility.ToJson(scanReport, true);
FileUtility.WriteAllText(savePath, json);
}
}
}

View File

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

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: db23997b705e34a419ba834ac85344f5
guid: 9bc1ecc3b72dfc34782fb6926d679f92
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -0,0 +1,13 @@
using System;
namespace YooAsset.Editor
{
[Serializable]
public class AssetArtCollector
{
/// <summary>
/// 扫描目录
/// </summary>
public string CollectPath = string.Empty;
}
}

View File

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

View File

@@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
[Serializable]
public class AssetArtScanner
{
/// <summary>
/// 扫描器GUID
/// </summary>
public string ScannerGUID = string.Empty;
/// <summary>
/// 扫描器名称
/// </summary>
public string ScannerName = string.Empty;
/// <summary>
/// 扫描器描述
/// </summary>
public string ScannerDesc = string.Empty;
/// <summary>
/// 扫描模式
/// 注意文件路径或文件GUID
/// </summary>
public string ScannerSchema = string.Empty;
/// <summary>
/// 存储目录
/// </summary>
public string SaveDirectory = string.Empty;
/// <summary>
/// 收集列表
/// </summary>
public List<AssetArtCollector> Collectors = new List<AssetArtCollector>();
/// <summary>
/// 白名单
/// </summary>
public List<string> WhiteList = new List<string>();
/// <summary>
/// 检测关键字匹配
/// </summary>
public bool CheckKeyword(string keyword)
{
if (ScannerName.Contains(keyword) || ScannerDesc.Contains(keyword))
return true;
else
return false;
}
/// <summary>
/// 是否在白名单里
/// </summary>
public bool CheckWhiteList(string guid)
{
return WhiteList.Contains(guid);
}
/// <summary>
/// 检测配置错误
/// </summary>
public void CheckConfigError()
{
if (string.IsNullOrEmpty(ScannerName))
throw new Exception($"Scanner name is null or empty !");
if (string.IsNullOrEmpty(ScannerSchema))
throw new Exception($"Scanner {ScannerName} schema is null !");
if (string.IsNullOrEmpty(SaveDirectory) == false)
{
if (Directory.Exists(SaveDirectory) == false)
throw new Exception($"Scanner {ScannerName} save directory is invalid : {SaveDirectory}");
}
}
/// <summary>
/// 加载扫描模式实例
/// </summary>
public ScannerSchema LoadSchema()
{
if (string.IsNullOrEmpty(ScannerSchema))
return null;
string filePath;
if (ScannerSchema.StartsWith("Assets/"))
{
filePath = ScannerSchema;
}
else
{
string guid = ScannerSchema;
filePath = AssetDatabase.GUIDToAssetPath(guid);
}
var schema = AssetDatabase.LoadMainAssetAtPath(filePath) as ScannerSchema;
if (schema == null)
Debug.LogWarning($"Failed load scanner schema : {filePath}");
return schema;
}
/// <summary>
/// 运行扫描器生成报告类
/// </summary>
public ScanReport RunScanner()
{
if (Collectors.Count == 0)
Debug.LogWarning($"Scanner {ScannerName} collector is empty !");
ScannerSchema schema = LoadSchema();
if (schema == null)
throw new Exception($"Failed to load schema : {ScannerSchema}");
var report = schema.RunScanner(this);
report.FileSign = ScannerDefine.ReportFileSign;
report.FileVersion = ScannerDefine.ReportFileVersion;
report.SchemaType = schema.GetType().FullName;
report.ScannerGUID = ScannerGUID;
return report;
}
}
}

View File

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

View File

@@ -0,0 +1,85 @@
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
public class AssetArtScannerConfig
{
public class ConfigWrapper
{
/// <summary>
/// 文件签名
/// </summary>
public string FileSign;
/// <summary>
/// 文件版本
/// </summary>
public string FileVersion;
/// <summary>
/// 扫描器列表
/// </summary>
public List<AssetArtScanner> Scanners = new List<AssetArtScanner>();
}
/// <summary>
/// 导入JSON配置文件
/// </summary>
public static void ImportJsonConfig(string filePath)
{
if (File.Exists(filePath) == false)
throw new FileNotFoundException(filePath);
string json = FileUtility.ReadAllText(filePath);
ConfigWrapper setting = JsonUtility.FromJson<ConfigWrapper>(json);
// 检测配置文件的签名
if (setting.FileSign != ScannerDefine.SettingFileSign)
throw new Exception($"导入的配置文件无法识别 : {filePath}");
// 检测配置文件的版本
if (setting.FileVersion != ScannerDefine.SettingFileVersion)
throw new Exception($"配置文件的版本不匹配 : {setting.FileVersion} != {ScannerDefine.SettingFileVersion}");
// 检测配置合法性
HashSet<string> scanGUIDs = new HashSet<string>();
foreach (var sacnner in setting.Scanners)
{
if (scanGUIDs.Contains(sacnner.ScannerGUID))
{
throw new Exception($"Scanner {sacnner.ScannerName} GUID is existed : {sacnner.ScannerGUID} ");
}
else
{
scanGUIDs.Add(sacnner.ScannerGUID);
}
}
AssetArtScannerSettingData.Setting.Scanners = setting.Scanners;
AssetArtScannerSettingData.SaveFile();
}
/// <summary>
/// 导出JSON配置文件
/// </summary>
public static void ExportJsonConfig(string savePath)
{
if (File.Exists(savePath))
File.Delete(savePath);
ConfigWrapper wrapper = new ConfigWrapper();
wrapper.FileSign = ScannerDefine.SettingFileSign;
wrapper.FileVersion = ScannerDefine.SettingFileVersion;
wrapper.Scanners = AssetArtScannerSettingData.Setting.Scanners;
string json = JsonUtility.ToJson(wrapper, true);
FileUtility.WriteAllText(savePath, json);
}
}
}

View File

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

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using UnityEngine;
using NUnit.Framework.Constraints;
namespace YooAsset.Editor
{
public class AssetArtScannerSetting : ScriptableObject
{
/// <summary>
/// 扫描器列表
/// </summary>
public List<AssetArtScanner> Scanners = new List<AssetArtScanner>();
/// <summary>
/// 开始扫描
/// </summary>
public ScannerResult BeginScan(string scannerGUID)
{
try
{
// 获取扫描器配置
var scanner = GetScanner(scannerGUID);
if (scanner == null)
throw new Exception($"Invalid scanner GUID : {scannerGUID}");
// 检测配置合法性
scanner.CheckConfigError();
// 开始扫描工作
ScanReport report = scanner.RunScanner();
// 检测报告合法性
report.CheckError();
// 保存扫描结果
string saveDirectory = scanner.SaveDirectory;
if (string.IsNullOrEmpty(saveDirectory))
saveDirectory = "Assets/";
string filePath = $"{saveDirectory}/{scanner.ScannerName}_{scanner.ScannerDesc}.json";
ScanReportConfig.ExportJsonConfig(filePath, report);
return new ScannerResult(filePath, report);
}
catch (Exception e)
{
return new ScannerResult(e.Message);
}
}
/// <summary>
/// 获取指定的扫描器
/// </summary>
public AssetArtScanner GetScanner(string scannerGUID)
{
foreach (var scanner in Scanners)
{
if (scanner.ScannerGUID == scannerGUID)
return scanner;
}
Debug.LogWarning($"Not found scanner : {scannerGUID}");
return null;
}
}
}

View File

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

View File

@@ -0,0 +1,161 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using UnityEngine;
using UnityEditor;
namespace YooAsset.Editor
{
public class AssetArtScannerSettingData
{
/// <summary>
/// 配置数据是否被修改
/// </summary>
public static bool IsDirty { private set; get; } = false;
static AssetArtScannerSettingData()
{
}
private static AssetArtScannerSetting _setting = null;
public static AssetArtScannerSetting Setting
{
get
{
if (_setting == null)
_setting = SettingLoader.LoadSettingData<AssetArtScannerSetting>();
return _setting;
}
}
/// <summary>
/// 存储配置文件
/// </summary>
public static void SaveFile()
{
if (Setting != null)
{
IsDirty = false;
EditorUtility.SetDirty(Setting);
AssetDatabase.SaveAssets();
Debug.Log($"{nameof(AssetArtScannerSetting)}.asset is saved!");
}
}
/// <summary>
/// 清空所有数据
/// </summary>
public static void ClearAll()
{
Setting.Scanners.Clear();
SaveFile();
}
/// <summary>
/// 扫描所有项
/// </summary>
public static void ScanAll()
{
foreach (var scanner in Setting.Scanners)
{
var scanResult = Setting.BeginScan(scanner.ScannerGUID);
if (scanResult.Succeed == false)
{
Debug.LogError($"{scanner.ScannerName} failed : {scanResult.ErrorInfo}");
}
}
}
/// <summary>
/// 扫描所有项
/// </summary>
public static void ScanAll(string keyword)
{
foreach (var scanner in Setting.Scanners)
{
if (string.IsNullOrEmpty(keyword) == false)
{
if (scanner.CheckKeyword(keyword) == false)
continue;
}
var scanResult = Setting.BeginScan(scanner.ScannerGUID);
if (scanResult.Succeed == false)
{
Debug.LogError($"{scanner.ScannerName} failed : {scanResult.ErrorInfo}");
}
}
}
/// <summary>
/// 扫描单项
/// </summary>
public static ScannerResult Scan(string scannerGUID)
{
var scanResult = Setting.BeginScan(scannerGUID);
if (scanResult.Succeed == false)
{
Debug.LogError(scanResult.ErrorInfo);
}
return scanResult;
}
// 扫描器编辑相关
public static AssetArtScanner CreateScanner(string name, string desc)
{
AssetArtScanner scanner = new AssetArtScanner();
scanner.ScannerGUID = System.Guid.NewGuid().ToString();
scanner.ScannerName = name;
scanner.ScannerDesc = desc;
Setting.Scanners.Add(scanner);
IsDirty = true;
return scanner;
}
public static void RemoveScanner(AssetArtScanner scanner)
{
if (Setting.Scanners.Remove(scanner))
{
IsDirty = true;
}
else
{
Debug.LogWarning($"Failed remove scanner : {scanner.ScannerName}");
}
}
public static void ModifyScanner(AssetArtScanner scanner)
{
if (scanner != null)
{
IsDirty = true;
}
}
// 资源收集编辑相关
public static void CreateCollector(AssetArtScanner scanner, AssetArtCollector collector)
{
scanner.Collectors.Add(collector);
IsDirty = true;
}
public static void RemoveCollector(AssetArtScanner scanner, AssetArtCollector collector)
{
if (scanner.Collectors.Remove(collector))
{
IsDirty = true;
}
else
{
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
}
}
public static void ModifyCollector(AssetArtScanner scanner, AssetArtCollector collector)
{
if (scanner != null && collector != null)
{
IsDirty = true;
}
}
}
}

View File

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

View File

@@ -0,0 +1,544 @@
#if UNITY_2019_4_OR_NEWER
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class AssetArtScannerWindow : EditorWindow
{
[MenuItem("YooAsset/AssetArt Scanner", false, 301)]
public static void OpenWindow()
{
AssetArtScannerWindow window = GetWindow<AssetArtScannerWindow>("AssetArt Scanner", true, WindowsDefine.DockedWindowTypes);
window.minSize = new Vector2(800, 600);
}
private Button _saveButton;
private ListView _scannerListView;
private ToolbarSearchField _scannerSearchField;
private VisualElement _scannerContentContainer;
private VisualElement _inspectorContainer;
private Label _schemaGuideTxt;
private TextField _scannerNameTxt;
private TextField _scannerDescTxt;
private ObjectField _scannerSchemaField;
private ObjectField _outputFolderField;
private ScrollView _collectorScrollView;
private int _lastModifyScannerIndex = 0;
public void CreateGUI()
{
Undo.undoRedoPerformed -= RefreshWindow;
Undo.undoRedoPerformed += RefreshWindow;
try
{
VisualElement root = this.rootVisualElement;
// 加载布局文件
var visualAsset = UxmlLoader.LoadWindowUXML<AssetArtScannerWindow>();
if (visualAsset == null)
return;
visualAsset.CloneTree(root);
// 导入导出按钮
var exportBtn = root.Q<Button>("ExportButton");
exportBtn.clicked += ExportBtn_clicked;
var importBtn = root.Q<Button>("ImportButton");
importBtn.clicked += ImportBtn_clicked;
// 配置保存按钮
_saveButton = root.Q<Button>("SaveButton");
_saveButton.clicked += SaveBtn_clicked;
// 扫描按钮
var scanAllBtn = root.Q<Button>("ScanAllButton");
scanAllBtn.clicked += ScanAllBtn_clicked;
var scanBtn = root.Q<Button>("ScanBtn");
scanBtn.clicked += ScanBtn_clicked;
// 扫描列表相关
_scannerListView = root.Q<ListView>("ScannerListView");
_scannerListView.makeItem = MakeScannerListViewItem;
_scannerListView.bindItem = BindScannerListViewItem;
#if UNITY_2022_3_OR_NEWER
_scannerListView.selectionChanged += ScannerListView_onSelectionChange;
#elif UNITY_2020_1_OR_NEWER
_scannerListView.onSelectionChange += ScannerListView_onSelectionChange;
#else
_scannerListView.onSelectionChanged += ScannerListView_onSelectionChange;
#endif
// 扫描列表过滤
_scannerSearchField = root.Q<ToolbarSearchField>("ScannerSearchField");
_scannerSearchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
// 扫描器添加删除按钮
var scannerAddContainer = root.Q("ScannerAddContainer");
{
var addBtn = scannerAddContainer.Q<Button>("AddBtn");
addBtn.clicked += AddScannerBtn_clicked;
var removeBtn = scannerAddContainer.Q<Button>("RemoveBtn");
removeBtn.clicked += RemoveScannerBtn_clicked;
}
// 扫描器容器
_scannerContentContainer = root.Q("ScannerContentContainer");
// 检视界面容器
_inspectorContainer = root.Q("InspectorContainer");
// 扫描器指南
_schemaGuideTxt = root.Q<Label>("SchemaUserGuide");
// 扫描器名称
_scannerNameTxt = root.Q<TextField>("ScannerName");
_scannerNameTxt.RegisterValueChangedCallback(evt =>
{
var selectScanner = _scannerListView.selectedItem as AssetArtScanner;
if (selectScanner != null)
{
selectScanner.ScannerName = evt.newValue;
AssetArtScannerSettingData.ModifyScanner(selectScanner);
FillScannerListViewData();
}
});
// 扫描器备注
_scannerDescTxt = root.Q<TextField>("ScannerDesc");
_scannerDescTxt.RegisterValueChangedCallback(evt =>
{
var selectScanner = _scannerListView.selectedItem as AssetArtScanner;
if (selectScanner != null)
{
selectScanner.ScannerDesc = evt.newValue;
AssetArtScannerSettingData.ModifyScanner(selectScanner);
FillScannerListViewData();
}
});
// 扫描模式
_scannerSchemaField = root.Q<ObjectField>("ScanSchema");
_scannerSchemaField.RegisterValueChangedCallback(evt =>
{
var selectScanner = _scannerListView.selectedItem as AssetArtScanner;
if (selectScanner != null)
{
string assetPath = AssetDatabase.GetAssetPath(evt.newValue);
selectScanner.ScannerSchema = AssetDatabase.AssetPathToGUID(assetPath);
AssetArtScannerSettingData.ModifyScanner(selectScanner);
}
});
// 存储目录
_outputFolderField = root.Q<ObjectField>("OutputFolder");
_outputFolderField.RegisterValueChangedCallback(evt =>
{
var selectScanner = _scannerListView.selectedItem as AssetArtScanner;
if (selectScanner != null)
{
if (evt.newValue == null)
{
selectScanner.SaveDirectory = string.Empty;
AssetArtScannerSettingData.ModifyScanner(selectScanner);
}
else
{
string assetPath = AssetDatabase.GetAssetPath(evt.newValue);
if (AssetDatabase.IsValidFolder(assetPath))
{
selectScanner.SaveDirectory = assetPath;
AssetArtScannerSettingData.ModifyScanner(selectScanner);
}
else
{
Debug.LogWarning($"Select asset object not folder ! {assetPath}");
}
}
}
});
// 收集列表相关
_collectorScrollView = root.Q<ScrollView>("CollectorScrollView");
_collectorScrollView.style.height = new Length(100, LengthUnit.Percent);
_collectorScrollView.viewDataKey = "scrollView";
// 收集器创建按钮
var collectorAddContainer = root.Q("CollectorAddContainer");
{
var addBtn = collectorAddContainer.Q<Button>("AddBtn");
addBtn.clicked += AddCollectorBtn_clicked;
}
// 刷新窗体
RefreshWindow();
}
catch (System.Exception e)
{
Debug.LogError(e.ToString());
}
}
public void OnDestroy()
{
// 注意:清空所有撤销操作
Undo.ClearAll();
if (AssetArtScannerSettingData.IsDirty)
AssetArtScannerSettingData.SaveFile();
}
public void Update()
{
if (_saveButton != null)
{
if (AssetArtScannerSettingData.IsDirty)
{
if (_saveButton.enabledSelf == false)
_saveButton.SetEnabled(true);
}
else
{
if (_saveButton.enabledSelf)
_saveButton.SetEnabled(false);
}
}
}
private void RefreshWindow()
{
_scannerContentContainer.visible = false;
FillScannerListViewData();
}
private void ExportBtn_clicked()
{
string resultPath = EditorTools.OpenFolderPanel("Export JSON", "Assets/");
if (resultPath != null)
{
AssetArtScannerConfig.ExportJsonConfig($"{resultPath}/AssetArtScannerConfig.json");
}
}
private void ImportBtn_clicked()
{
string resultPath = EditorTools.OpenFilePath("Import JSON", "Assets/", "json");
if (resultPath != null)
{
AssetArtScannerConfig.ImportJsonConfig(resultPath);
RefreshWindow();
}
}
private void SaveBtn_clicked()
{
AssetArtScannerSettingData.SaveFile();
}
private void ScanAllBtn_clicked()
{
if (EditorUtility.DisplayDialog("提示", $"开始全面扫描!", "Yes", "No"))
{
string searchKeyWord = _scannerSearchField.value;
AssetArtScannerSettingData.ScanAll(searchKeyWord);
AssetDatabase.Refresh();
}
else
{
Debug.LogWarning("全面扫描已经取消");
}
}
private void ScanBtn_clicked()
{
var selectScanner = _scannerListView.selectedItem as AssetArtScanner;
if (selectScanner == null)
return;
ScannerResult scannerResult = AssetArtScannerSettingData.Scan(selectScanner.ScannerGUID);
if (scannerResult.Succeed)
{
// 自动打开报告界面
scannerResult.OpenReportWindow();
AssetDatabase.Refresh();
}
}
private void OnSearchKeyWordChange(ChangeEvent<string> e)
{
_lastModifyScannerIndex = 0;
RefreshWindow();
}
// 分组列表相关
private void FillScannerListViewData()
{
_scannerListView.Clear();
_scannerListView.ClearSelection();
var filterItems = FilterScanners();
if (AssetArtScannerSettingData.Setting.Scanners.Count == filterItems.Count)
{
#if UNITY_2020_3_OR_NEWER
_scannerListView.reorderable = true;
#endif
_scannerListView.itemsSource = AssetArtScannerSettingData.Setting.Scanners;
_scannerListView.Rebuild();
}
else
{
#if UNITY_2020_3_OR_NEWER
_scannerListView.reorderable = false;
#endif
_scannerListView.itemsSource = filterItems;
_scannerListView.Rebuild();
}
}
private List<AssetArtScanner> FilterScanners()
{
string searchKeyWord = _scannerSearchField.value;
List<AssetArtScanner> result = new List<AssetArtScanner>(AssetArtScannerSettingData.Setting.Scanners.Count);
// 过滤列表
foreach (var scanner in AssetArtScannerSettingData.Setting.Scanners)
{
if (string.IsNullOrEmpty(searchKeyWord) == false)
{
if (scanner.CheckKeyword(searchKeyWord) == false)
continue;
}
result.Add(scanner);
}
return result;
}
private VisualElement MakeScannerListViewItem()
{
VisualElement element = new VisualElement();
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.flexGrow = 1f;
label.style.height = 20f;
element.Add(label);
}
return element;
}
private void BindScannerListViewItem(VisualElement element, int index)
{
List<AssetArtScanner> sourceList = _scannerListView.itemsSource as List<AssetArtScanner>;
var scanner = sourceList[index];
var textField1 = element.Q<Label>("Label1");
if (string.IsNullOrEmpty(scanner.ScannerDesc))
textField1.text = scanner.ScannerName;
else
textField1.text = $"{scanner.ScannerName} ({scanner.ScannerDesc})";
}
private void ScannerListView_onSelectionChange(IEnumerable<object> objs)
{
var selectScanner = _scannerListView.selectedItem as AssetArtScanner;
if (selectScanner == null)
{
_scannerContentContainer.visible = false;
return;
}
_scannerContentContainer.visible = true;
_lastModifyScannerIndex = _scannerListView.selectedIndex;
_scannerNameTxt.SetValueWithoutNotify(selectScanner.ScannerName);
_scannerDescTxt.SetValueWithoutNotify(selectScanner.ScannerDesc);
// 显示检视面板
var scanSchema = selectScanner.LoadSchema();
RefreshInspector(scanSchema);
// 设置Schema对象
if (scanSchema == null)
{
_scannerSchemaField.SetValueWithoutNotify(null);
_schemaGuideTxt.text = string.Empty;
}
else
{
_scannerSchemaField.SetValueWithoutNotify(scanSchema);
_schemaGuideTxt.text = scanSchema.GetUserGuide();
}
// 显示存储目录
DefaultAsset saveFolder = AssetDatabase.LoadAssetAtPath<DefaultAsset>(selectScanner.SaveDirectory);
if (saveFolder == null)
{
_outputFolderField.SetValueWithoutNotify(null);
}
else
{
_outputFolderField.SetValueWithoutNotify(saveFolder);
}
FillCollectorViewData();
}
private void AddScannerBtn_clicked()
{
Undo.RecordObject(AssetArtScannerSettingData.Setting, "YooAsset.AssetArtScannerWindow AddScanner");
AssetArtScannerSettingData.CreateScanner("Default Scanner", string.Empty);
FillScannerListViewData();
}
private void RemoveScannerBtn_clicked()
{
var selectScanner = _scannerListView.selectedItem as AssetArtScanner;
if (selectScanner == null)
return;
Undo.RecordObject(AssetArtScannerSettingData.Setting, "YooAsset.AssetArtScannerWindow RemoveScanner");
AssetArtScannerSettingData.RemoveScanner(selectScanner);
FillScannerListViewData();
}
// 收集列表相关
private void FillCollectorViewData()
{
var selectScanner = _scannerListView.selectedItem as AssetArtScanner;
if (selectScanner == null)
return;
// 填充数据
_collectorScrollView.Clear();
for (int i = 0; i < selectScanner.Collectors.Count; i++)
{
VisualElement element = MakeCollectorListViewItem();
BindCollectorListViewItem(element, i);
_collectorScrollView.Add(element);
}
}
private VisualElement MakeCollectorListViewItem()
{
VisualElement element = new VisualElement();
VisualElement elementTop = new VisualElement();
elementTop.style.flexDirection = FlexDirection.Row;
element.Add(elementTop);
VisualElement elementSpace = new VisualElement();
elementSpace.style.flexDirection = FlexDirection.Column;
element.Add(elementSpace);
// Top VisualElement
{
var button = new Button();
button.name = "Button1";
button.text = "-";
button.style.unityTextAlign = TextAnchor.MiddleCenter;
button.style.flexGrow = 0f;
elementTop.Add(button);
}
{
var objectField = new ObjectField();
objectField.name = "ObjectField1";
objectField.label = "Collector";
objectField.objectType = typeof(UnityEngine.Object);
objectField.style.unityTextAlign = TextAnchor.MiddleLeft;
objectField.style.flexGrow = 1f;
elementTop.Add(objectField);
var label = objectField.Q<Label>();
label.style.minWidth = 63;
}
// Space VisualElement
{
var label = new Label();
label.style.height = 10;
elementSpace.Add(label);
}
return element;
}
private void BindCollectorListViewItem(VisualElement element, int index)
{
var selectScanner = _scannerListView.selectedItem as AssetArtScanner;
if (selectScanner == null)
return;
var collector = selectScanner.Collectors[index];
var collectObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(collector.CollectPath);
if (collectObject != null)
collectObject.name = collector.CollectPath;
// Remove Button
var removeBtn = element.Q<Button>("Button1");
removeBtn.clicked += () =>
{
RemoveCollectorBtn_clicked(collector);
};
// Collector Path
var objectField1 = element.Q<ObjectField>("ObjectField1");
objectField1.SetValueWithoutNotify(collectObject);
objectField1.RegisterValueChangedCallback(evt =>
{
collector.CollectPath = AssetDatabase.GetAssetPath(evt.newValue);
objectField1.value.name = collector.CollectPath;
AssetArtScannerSettingData.ModifyCollector(selectScanner, collector);
});
}
private void AddCollectorBtn_clicked()
{
var selectSacnner = _scannerListView.selectedItem as AssetArtScanner;
if (selectSacnner == null)
return;
Undo.RecordObject(AssetArtScannerSettingData.Setting, "YooAsset.AssetArtScannerWindow AddCollector");
AssetArtCollector collector = new AssetArtCollector();
AssetArtScannerSettingData.CreateCollector(selectSacnner, collector);
FillCollectorViewData();
}
private void RemoveCollectorBtn_clicked(AssetArtCollector selectCollector)
{
var selectSacnner = _scannerListView.selectedItem as AssetArtScanner;
if (selectSacnner == null)
return;
if (selectCollector == null)
return;
Undo.RecordObject(AssetArtScannerSettingData.Setting, "YooAsset.AssetArtScannerWindow RemoveCollector");
AssetArtScannerSettingData.RemoveCollector(selectSacnner, selectCollector);
FillCollectorViewData();
}
// 属性面板相关
private void RefreshInspector(ScannerSchema scanSchema)
{
if (scanSchema == null)
{
UIElementsTools.SetElementVisible(_inspectorContainer, false);
return;
}
var inspector = scanSchema.CreateInspector();
if (inspector == null)
{
UIElementsTools.SetElementVisible(_inspectorContainer, false);
return;
}
if (inspector.Containner is VisualElement container)
{
UIElementsTools.SetElementVisible(_inspectorContainer, true);
_inspectorContainer.Clear();
_inspectorContainer.Add(container);
_inspectorContainer.style.width = inspector.Width;
_inspectorContainer.style.minWidth = inspector.MinWidth;
_inspectorContainer.style.maxWidth = inspector.MaxWidth;
}
else
{
Debug.LogWarning($"{nameof(ScannerSchema)} inspector container is invalid !");
UIElementsTools.SetElementVisible(_inspectorContainer, false);
}
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,33 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<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="Export" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="Import" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
<ui:Button text="Scan All" display-tooltip-when-elided="true" name="ScanAllButton" style="width: 80px; background-color: rgb(56, 147, 58);" />
</uie:Toolbar>
<ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;">
<ui:VisualElement name="ScannerListContainer" style="width: 250px; 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:Label text="Scanner List" display-tooltip-when-elided="true" name="ScannerListTitle" style="background-color: rgb(89, 89, 89); -unity-text-align: upper-center; -unity-font-style: bold; border-left-width: 3px; border-right-width: 3px; border-top-width: 3px; border-bottom-width: 3px; font-size: 12px;" />
<uie:ToolbarSearchField focusable="true" name="ScannerSearchField" style="width: 230px;" />
<ui:ListView focusable="true" name="ScannerListView" item-height="20" virtualization-method="DynamicHeight" reorder-mode="Animated" reorderable="true" style="flex-grow: 1;" />
<ui:VisualElement name="ScannerAddContainer" style="justify-content: center; flex-direction: row; flex-shrink: 0;">
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
</ui:VisualElement>
</ui:VisualElement>
<ui:VisualElement name="ScannerContentContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px; min-width: 400px;">
<ui:Label text="Scanner" display-tooltip-when-elided="true" name="ScannerContentTitle" style="-unity-text-align: upper-center; -unity-font-style: bold; font-size: 12px; border-top-width: 3px; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; background-color: rgb(89, 89, 89);" />
<ui:Label display-tooltip-when-elided="true" name="SchemaUserGuide" style="-unity-text-align: upper-center; -unity-font-style: bold; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px; font-size: 12px; height: 40px;" />
<ui:TextField picking-mode="Ignore" label="Scanner Name" name="ScannerName" />
<ui:TextField picking-mode="Ignore" label="Scanner Desc" name="ScannerDesc" />
<uie:ObjectField label="Scanner Schema" name="ScanSchema" type="YooAsset.Editor.ScannerSchema, YooAsset.Editor" allow-scene-objects="false" />
<uie:ObjectField label="Output Folder" name="OutputFolder" type="UnityEditor.DefaultAsset, UnityEditor.CoreModule" allow-scene-objects="false" />
<ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;">
<ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" />
<ui:Button text="Scan" display-tooltip-when-elided="true" name="ScanBtn" style="width: 60px;" />
</ui:VisualElement>
<ui:ScrollView name="CollectorScrollView" style="flex-grow: 1;" />
</ui:VisualElement>
<ui:VisualElement name="InspectorContainer" style="flex-grow: 1; border-top-width: 5px; border-right-width: 5px; border-bottom-width: 5px; border-left-width: 5px; background-color: rgb(67, 67, 67);" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 5bbb873a7bee2924a86c876b67bb2cb4
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -0,0 +1,26 @@

namespace YooAsset.Editor
{
public class ScannerDefine
{
/// <summary>
/// 报告文件签名
/// </summary>
public const string ReportFileSign = "596f6f4172745265706f7274";
/// <summary>
/// 配置文件签名
/// </summary>
public const string SettingFileSign = "596f6f41727453657474696e67";
/// <summary>
/// 报告文件的版本
/// </summary>
public const string ReportFileVersion = "1.0";
/// <summary>
/// 配置文件的版本
/// </summary>
public const string SettingFileVersion = "1.0";
}
}

View File

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

View File

@@ -0,0 +1,59 @@

namespace YooAsset.Editor
{
public class ScannerResult
{
/// <summary>
/// 生成的报告文件路径
/// </summary>
public string ReprotFilePath { private set; get; }
/// <summary>
/// 报告对象
/// </summary>
public ScanReport Report { private set; get; }
/// <summary>
/// 错误信息
/// </summary>
public string ErrorInfo { private set; get; }
/// <summary>
/// 是否成功
/// </summary>
public bool Succeed
{
get
{
if (string.IsNullOrEmpty(ErrorInfo))
return true;
else
return false;
}
}
public ScannerResult(string error)
{
ErrorInfo = error;
}
public ScannerResult(string filePath, ScanReport report)
{
ReprotFilePath = filePath;
Report = report;
ErrorInfo = string.Empty;
}
/// <summary>
/// 打开报告窗口
/// </summary>
public void OpenReportWindow()
{
if (Succeed)
{
var reproterWindow = AssetArtReporterWindow.OpenWindow();
reproterWindow.ImportSingleReprotFile(ReprotFilePath);
}
}
}
}

View File

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

View File

@@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset.Editor
{
public abstract class ScannerSchema : ScriptableObject
{
/// <summary>
/// 获取用户指南信息
/// </summary>
public abstract string GetUserGuide();
/// <summary>
/// 运行生成扫描报告
/// </summary>
public abstract ScanReport RunScanner(AssetArtScanner scanner);
/// <summary>
/// 修复扫描结果
/// </summary>
public abstract void FixResult(List<ReportElement> fixList);
/// <summary>
/// 创建检视面板
/// </summary>
public virtual SchemaInspector CreateInspector()
{
return null;
}
}
}

View File

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

View File

@@ -0,0 +1,45 @@

namespace YooAsset.Editor
{
public class SchemaInspector
{
/// <summary>
/// 检视界面的UI元素容器UIElements元素
/// </summary>
public object Containner { private set; get; }
/// <summary>
/// 检视界面宽度
/// </summary>
public int Width = 250;
/// <summary>
/// 检视界面最小宽度
/// </summary>
public int MinWidth = 250;
/// <summary>
/// 检视界面最大宽度
/// </summary>
public int MaxWidth = 250;
public SchemaInspector(object containner)
{
Containner = containner;
}
public SchemaInspector(object containner, int width)
{
Containner = containner;
Width = width;
MinWidth = width;
MaxWidth = width;
}
public SchemaInspector(object containner, int width, int minWidth, int maxWidth)
{
Containner = containner;
Width = width;
MinWidth = minWidth;
MaxWidth = maxWidth;
}
}
}

View File

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

View File

@@ -36,7 +36,7 @@ namespace YooAsset.Editor
BuildLogger.InitLogger(enableLog);
// 执行构建流程
Debug.Log($"Begin to build package : {buildParameters.PackageName} by {buildParameters.BuildPipeline}");
BuildLogger.Log($"Begin to build package : {buildParameters.PackageName} by {buildParameters.BuildPipeline}");
var buildResult = BuildRunner.Run(buildPipeline, _buildContext);
if (buildResult.Success)
{

View File

@@ -22,7 +22,7 @@ namespace YooAsset.Editor
/// </summary>
public static string GetStreamingAssetsRoot()
{
return YooAssetSettingsData.GetYooEditorBuildinRoot();
return YooAssetSettingsData.GetYooDefaultBuildinRoot();
}
}
}

View File

@@ -8,7 +8,7 @@ namespace YooAsset.Editor
/// <summary>
/// 模拟构建
/// </summary>
public static EditorSimulateBuildResult SimulateBuild(EditorSimulateBuildParam buildParam)
public static PackageInvokeBuildResult SimulateBuild(PackageInvokeBuildParam buildParam)
{
string packageName = buildParam.PackageName;
string buildPipelineName = buildParam.BuildPipelineName;
@@ -26,12 +26,13 @@ namespace YooAsset.Editor
buildParameters.FileNameStyle = EFileNameStyle.HashName;
buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None;
buildParameters.BuildinFileCopyParams = string.Empty;
buildParameters.UseAssetDependencyDB = true;
var pipeline = new EditorSimulateBuildPipeline();
BuildResult buildResult = pipeline.Run(buildParameters, false);
if (buildResult.Success)
{
var reulst = new EditorSimulateBuildResult();
var reulst = new PackageInvokeBuildResult();
reulst.PackageRootDirectory = buildResult.OutputPackageDirectory;
return reulst;
}

View File

@@ -56,17 +56,13 @@ namespace YooAsset.Editor
public string EncryptedFilePath { set; get; }
#endregion
#if UNITY_2020_3_OR_NEWER
private readonly HashSet<string> _assetPaths = new HashSet<string>(1000);
#else
private readonly HashSet<string> _assetPaths = new HashSet<string>();
#endif
private readonly Dictionary<string, BuildAssetInfo> _packAssetDic = new Dictionary<string, BuildAssetInfo>(100);
/// <summary>
/// 参与构建的资源列表
/// 注意:不包含零依赖资源和冗余资源
/// </summary>
public readonly List<BuildAssetInfo> MainAssets = new List<BuildAssetInfo>();
public readonly List<BuildAssetInfo> AllPackAssets = new List<BuildAssetInfo>(100);
/// <summary>
/// 资源包名称
@@ -90,51 +86,68 @@ namespace YooAsset.Editor
public void PackAsset(BuildAssetInfo buildAsset)
{
string assetPath = buildAsset.AssetInfo.AssetPath;
if (_assetPaths.Contains(assetPath))
if (_packAssetDic.ContainsKey(assetPath))
throw new System.Exception($"Should never get here ! Asset is existed : {assetPath}");
_assetPaths.Add(assetPath);
MainAssets.Add(buildAsset);
_packAssetDic.Add(assetPath, buildAsset);
AllPackAssets.Add(buildAsset);
}
/// <summary>
/// 是否包含指定资源
/// </summary>
public bool IsContainsAsset(string assetPath)
public bool IsContainsPackAsset(string assetPath)
{
return _assetPaths.Contains(assetPath);
return _packAssetDic.ContainsKey(assetPath);
}
/// <summary>
/// 获取构建的资源路径列表
/// </summary>
public string[] GetAllMainAssetPaths()
public string[] GetAllPackAssetPaths()
{
return MainAssets.Select(t => t.AssetInfo.AssetPath).ToArray();
return AllPackAssets.Select(t => t.AssetInfo.AssetPath).ToArray();
}
/// <summary>
/// 获取该资源包内的所有资源(包括零依赖资源和冗余资源)
/// 获取构建的主资源信息
/// </summary>
public List<string> GetAllBuiltinAssetPaths()
public BuildAssetInfo GetPackAssetInfo(string assetPath)
{
var packAssets = GetAllMainAssetPaths();
List<string> result = new List<string>(packAssets);
foreach (var buildAsset in MainAssets)
if (_packAssetDic.TryGetValue(assetPath, out BuildAssetInfo value))
{
if (buildAsset.AllDependAssetInfos == null)
continue;
foreach (var dependAssetInfo in buildAsset.AllDependAssetInfos)
return value;
}
else
{
throw new Exception($"Can not found pack asset info {assetPath} in bundle : {BundleName}");
}
}
/// <summary>
/// 获取资源包内部所有资产
/// </summary>
public List<AssetInfo> GetBundleContents()
{
Dictionary<string, AssetInfo> result = new Dictionary<string, AssetInfo>(AllPackAssets.Count);
foreach (var packAsset in AllPackAssets)
{
result.Add(packAsset.AssetInfo.AssetPath, packAsset.AssetInfo);
if (packAsset.AllDependAssetInfos != null)
{
// 注意:依赖资源里只添加零依赖资源和冗余资源
if (dependAssetInfo.HasBundleName() == false)
foreach (var dependAssetInfo in packAsset.AllDependAssetInfos)
{
if (result.Contains(dependAssetInfo.AssetInfo.AssetPath) == false)
result.Add(dependAssetInfo.AssetInfo.AssetPath);
// 注意:依赖资源里只添加零依赖资源和冗余资源
if (dependAssetInfo.HasBundleName() == false)
{
string dependAssetPath = dependAssetInfo.AssetInfo.AssetPath;
if (result.ContainsKey(dependAssetPath) == false)
result.Add(dependAssetPath, dependAssetInfo.AssetInfo);
}
}
}
}
return result;
return result.Values.ToList();
}
/// <summary>
@@ -146,7 +159,7 @@ namespace YooAsset.Editor
AssetBundleBuild build = new AssetBundleBuild();
build.assetBundleName = BundleName;
build.assetBundleVariant = string.Empty;
build.assetNames = GetAllMainAssetPaths();
build.assetNames = GetAllPackAssetPaths();
return build;
}
@@ -155,7 +168,7 @@ namespace YooAsset.Editor
/// </summary>
public BuildAssetInfo[] GetAllManifestAssetInfos()
{
return MainAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
return AllPackAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
}
/// <summary>

View File

@@ -17,7 +17,7 @@ namespace YooAsset.Editor
/// 未被依赖的资源列表
/// </summary>
public readonly List<ReportIndependAsset> IndependAssets = new List<ReportIndependAsset>(1000);
/// <summary>
/// 参与构建的资源总数
/// 说明:包括主动收集的资源以及其依赖的所有资源
@@ -96,14 +96,14 @@ namespace YooAsset.Editor
}
/// <summary>
/// 创建着色器信息类
/// 创建空的资源包
/// </summary>
public void CreateShadersBundleInfo(string shadersBundleName)
public void CreateEmptyBundleInfo(string bundleName)
{
if (IsContainsBundle(shadersBundleName) == false)
if (IsContainsBundle(bundleName) == false)
{
var shaderBundleInfo = new BuildBundleInfo(shadersBundleName);
_bundleInfoDic.Add(shadersBundleName, shaderBundleInfo);
var bundleInfo = new BuildBundleInfo(bundleName);
_bundleInfoDic.Add(bundleName, bundleInfo);
}
}
}

View File

@@ -58,7 +58,7 @@ namespace YooAsset.Editor
/// <summary>
/// 使用资源依赖缓存数据库
/// 说明:开启此项可以极大提高资源收集速度
/// 说明:开启此项可以极大提高资源收集速度
/// </summary>
public bool UseAssetDependencyDB = false;
@@ -67,6 +67,12 @@ namespace YooAsset.Editor
/// </summary>
public bool EnableSharePackRule = false;
/// <summary>
/// 对单独引用的共享资源进行独立打包
/// 说明:关闭该选项单独引用的共享资源将会构建到引用它的资源包内!
/// </summary>
public bool SingleReferencedPackAlone = true;
/// <summary>
/// 验证构建结果
/// </summary>
@@ -75,12 +81,12 @@ namespace YooAsset.Editor
/// <summary>
/// 资源包名称样式
/// </summary>
public EFileNameStyle FileNameStyle;
public EFileNameStyle FileNameStyle = EFileNameStyle.HashName;
/// <summary>
/// 内置文件的拷贝选项
/// </summary>
public EBuildinFileCopyOption BuildinFileCopyOption;
public EBuildinFileCopyOption BuildinFileCopyOption = EBuildinFileCopyOption.None;
/// <summary>
/// 内置文件的拷贝参数
@@ -116,16 +122,6 @@ namespace YooAsset.Editor
string message = BuildLogger.GetErrorMessage(ErrorCode.NoBuildTarget, "Please select the build target platform !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(PackageName))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageNameIsNullOrEmpty, "Package name is null or empty !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(PackageVersion))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageVersionIsNullOrEmpty, "Package version is null or empty !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(BuildOutputRoot))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildOutputRootIsNullOrEmpty, "Build output root is null or empty !");
@@ -136,6 +132,26 @@ namespace YooAsset.Editor
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildinFileRootIsNullOrEmpty, "Buildin file root is null or empty !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(BuildPipeline))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineIsNullOrEmpty, "Build pipeline is null or empty !");
throw new Exception(message);
}
if (BuildBundleType == (int)EBuildBundleType.Unknown)
{
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildBundleTypeIsUnknown, $"Build bundle type is unknown {BuildBundleType} !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(PackageName))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageNameIsNullOrEmpty, "Package name is null or empty !");
throw new Exception(message);
}
if (string.IsNullOrEmpty(PackageVersion))
{
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageVersionIsNullOrEmpty, "Package version is null or empty !");
throw new Exception(message);
}
// 设置默认备注信息
if (string.IsNullOrEmpty(PackageNote))

View File

@@ -43,17 +43,21 @@ namespace YooAsset.Editor
manifest.AssetList = CreatePackageAssetList(buildMapContext);
manifest.BundleList = CreatePackageBundleList(buildMapContext);
// 处理资源清单的ID数据
ProcessPacakgeIDs(manifest);
// 1. 处理资源清单的资源对象
ProcessPacakgeAsset(manifest);
// 处理资源包的依赖列表
// 2. 处理资源包的依赖列表
if (processBundleDepends)
ProcessBundleDepends(context, manifest);
// 处理资源包的标签集合
// 3. 处理资源包的标签集合
if (processBundleTags)
ProcessBundleTags(manifest);
// 4. 处理内置资源包
if (processBundleDepends)
ProcessBuiltinBundleDependency(context, manifest);
// 创建补丁清单文本文件
{
string fileName = YooAssetSettingsData.GetManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion);
@@ -64,17 +68,13 @@ namespace YooAsset.Editor
// 创建补丁清单二进制文件
string packageHash;
string packagePath;
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string filePath = $"{packageOutputDirectory}/{fileName}";
ManifestTools.SerializeToBinary(filePath, manifest);
packageHash = HashUtility.FileMD5(filePath);
BuildLogger.Log($"Create package manifest file: {filePath}");
ManifestContext manifestContext = new ManifestContext();
byte[] bytesData = FileUtility.ReadAllBytes(filePath);
manifestContext.Manifest = ManifestTools.DeserializeFromBinary(bytesData);
context.SetContextObject(manifestContext);
packagePath = $"{packageOutputDirectory}/{fileName}";
ManifestTools.SerializeToBinary(packagePath, manifest);
packageHash = HashUtility.FileCRC32(packagePath);
BuildLogger.Log($"Create package manifest file: {packagePath}");
}
// 创建补丁清单哈希文件
@@ -92,6 +92,14 @@ namespace YooAsset.Editor
FileUtility.WriteAllText(filePath, buildParameters.PackageVersion);
BuildLogger.Log($"Create package manifest version file: {filePath}");
}
// 填充上下文
{
ManifestContext manifestContext = new ManifestContext();
byte[] bytesData = FileUtility.ReadAllBytes(packagePath);
manifestContext.Manifest = ManifestTools.DeserializeFromBinary(bytesData);
context.SetContextObject(manifestContext);
}
}
/// <summary>
@@ -137,7 +145,7 @@ namespace YooAsset.Editor
packageAsset.AssetPath = assetInfo.AssetInfo.AssetPath;
packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetInfo.AssetGUID : string.Empty;
packageAsset.AssetTags = assetInfo.AssetTags.ToArray();
packageAsset.BundleNameInEditor = assetInfo.BundleName;
packageAsset.TempDataInEditor = assetInfo;
result.Add(packageAsset);
}
}
@@ -165,9 +173,9 @@ namespace YooAsset.Editor
}
/// <summary>
/// 处理资源清单的ID数据
/// 处理资源清单的资源对象列表
/// </summary>
private void ProcessPacakgeIDs(PackageManifest manifest)
private void ProcessPacakgeAsset(PackageManifest manifest)
{
// 注意:优先缓存资源包索引
for (int index = 0; index < manifest.BundleList.Count; index++)
@@ -176,10 +184,19 @@ namespace YooAsset.Editor
_cachedBundleIndexIDs.Add(bundleName, index);
}
// 记录资源对象所属的资源包ID
foreach (var packageAsset in manifest.AssetList)
{
string bundleName = packageAsset.BundleNameInEditor;
packageAsset.BundleID = GetCachedBundleIndexID(bundleName);
var assetInfo = packageAsset.TempDataInEditor as BuildAssetInfo;
packageAsset.BundleID = GetCachedBundleIndexID(assetInfo.BundleName);
}
// 记录资源对象依赖的资源包ID集合
// 注意:依赖关系非引擎构建结果里查询!
foreach (var packageAsset in manifest.AssetList)
{
var mainAssetInfo = packageAsset.TempDataInEditor as BuildAssetInfo;
packageAsset.DependBundleIDs = GetAssetDependBundleIDs(mainAssetInfo);
}
}
@@ -192,15 +209,18 @@ namespace YooAsset.Editor
foreach (var packageBundle in manifest.BundleList)
{
int mainBundleID = GetCachedBundleIndexID(packageBundle.BundleName);
var depends = GetBundleDepends(context, packageBundle.BundleName);
List<int> dependIDs = new List<int>(depends.Length);
foreach (var dependBundleName in depends)
string[] dependNames = GetBundleDepends(context, packageBundle.BundleName);
List<int> dependIDs = new List<int>(dependNames.Length);
foreach (var dependName in dependNames)
{
int bundleID = GetCachedBundleIndexID(dependBundleName);
if (bundleID != mainBundleID)
dependIDs.Add(bundleID);
int dependBundleID = GetCachedBundleIndexID(dependName);
if (dependBundleID != mainBundleID)
dependIDs.Add(dependBundleID);
}
packageBundle.DependIDs = dependIDs.ToArray();
// 排序并填充数据
dependIDs.Sort();
packageBundle.DependBundleIDs = dependIDs.ToArray();
}
}
@@ -209,23 +229,27 @@ namespace YooAsset.Editor
/// </summary>
private void ProcessBundleTags(PackageManifest manifest)
{
foreach (var packageBundle in manifest.BundleList)
{
packageBundle.Tags = Array.Empty<string>();
}
// 将主资源的标签信息传染给其依赖的资源包集合
foreach (var packageAsset in manifest.AssetList)
{
var assetTags = packageAsset.AssetTags;
int bundleID = packageAsset.BundleID;
CacheBundleTags(bundleID, assetTags);
var packageBundle = manifest.BundleList[bundleID];
if (packageBundle.DependIDs != null)
if (packageAsset.DependBundleIDs != null)
{
foreach (var dependBundleID in packageBundle.DependIDs)
foreach (var dependBundleID in packageAsset.DependBundleIDs)
{
CacheBundleTags(dependBundleID, assetTags);
}
}
}
// 将缓存的资源标签赋值给资源包
for (int index = 0; index < manifest.BundleList.Count; index++)
{
var packageBundle = manifest.BundleList[index];
@@ -264,5 +288,94 @@ namespace YooAsset.Editor
}
return value;
}
/// <summary>
/// 是否包含该资源包的索引ID
/// </summary>
private bool ContainsCachedBundleIndexID(string bundleName)
{
return _cachedBundleIndexIDs.ContainsKey(bundleName);
}
#region YOOASSET_LEGACY_DEPENDENCY
private void ProcessBuiltinBundleDependency(BuildContext context, PackageManifest manifest)
{
// 注意:如果是可编程构建管线,需要补充内置资源包
// 注意:该步骤依赖前面的操作!
var buildResultContext = context.TryGetContextObject<TaskBuilding_SBP.BuildResultContext>();
if (buildResultContext != null)
{
// 注意:初始化资源清单建立引用关系
ManifestTools.InitManifest(manifest);
ProcessBuiltinBundleReference(context, manifest, buildResultContext.BuiltinShadersBundleName);
ProcessBuiltinBundleReference(context, manifest, buildResultContext.MonoScriptsBundleName);
}
}
private void ProcessBuiltinBundleReference(BuildContext context, PackageManifest manifest, string builtinBundleName)
{
if (string.IsNullOrEmpty(builtinBundleName))
return;
// 查询内置资源包是否存在
if (ContainsCachedBundleIndexID(builtinBundleName) == false)
return;
// 获取内置资源包
int builtinBundleID = GetCachedBundleIndexID(builtinBundleName);
var builtinPackageBundle = manifest.BundleList[builtinBundleID];
// 更新依赖资源包ID集合
HashSet<int> cacheBundleIDs = new HashSet<int>(builtinPackageBundle.ReferenceBundleIDs);
HashSet<string> tempTags = new HashSet<string>();
foreach (var packageAsset in manifest.AssetList)
{
if (cacheBundleIDs.Contains(packageAsset.BundleID))
{
if (packageAsset.DependBundleIDs.Contains(builtinBundleID) == false)
{
var tempBundleIDs = new List<int>(packageAsset.DependBundleIDs);
tempBundleIDs.Add(builtinBundleID);
packageAsset.DependBundleIDs = tempBundleIDs.ToArray();
}
foreach (var tag in packageAsset.AssetTags)
{
if (tempTags.Contains(tag) == false)
tempTags.Add(tag);
}
}
}
// 更新内置资源包的标签集合
foreach (var tag in builtinPackageBundle.Tags)
{
if (tempTags.Contains(tag) == false)
tempTags.Add(tag);
}
builtinPackageBundle.Tags = tempTags.ToArray();
}
private int[] GetAssetDependBundleIDs(BuildAssetInfo mainAssetInfo)
{
HashSet<int> result = new HashSet<int>();
int mainBundleID = GetCachedBundleIndexID(mainAssetInfo.BundleName);
foreach (var dependAssetInfo in mainAssetInfo.AllDependAssetInfos)
{
if (dependAssetInfo.HasBundleName())
{
int bundleID = GetCachedBundleIndexID(dependAssetInfo.BundleName);
if (mainBundleID != bundleID)
{
if (result.Contains(bundleID) == false)
result.Add(bundleID);
}
}
}
// 排序并返回数据
List<int> listResult = new List<int>(result);
listResult.Sort();
return listResult.ToArray();
}
#endregion
}
}

View File

@@ -18,16 +18,13 @@ namespace YooAsset.Editor
// 概述信息
{
#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.YooVersion = EditorTools.GetPackageManagerYooVersion();
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
buildReport.Summary.BuildDate = DateTime.Now.ToString();
buildReport.Summary.BuildSeconds = BuildRunner.TotalSeconds;
buildReport.Summary.BuildTarget = buildParameters.BuildTarget;
buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline;
buildReport.Summary.BuildBundleType = buildParameters.BuildBundleType;
buildReport.Summary.BuildPackageName = buildParameters.PackageName;
buildReport.Summary.BuildPackageVersion = buildParameters.PackageVersion;
buildReport.Summary.BuildPackageNote = buildParameters.PackageNote;
@@ -37,36 +34,34 @@ namespace YooAsset.Editor
buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable;
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
buildReport.Summary.IgnoreRuleName = buildMapContext.Command.IgnoreRule.GetType().FullName;
buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
buildReport.Summary.IgnoreRuleName = buildMapContext.Command.IgnoreRule.GetType().FullName;
// 构建参数
buildReport.Summary.ClearBuildCacheFiles = buildParameters.ClearBuildCacheFiles;
buildReport.Summary.UseAssetDependencyDB = buildParameters.UseAssetDependencyDB;
buildReport.Summary.EnableSharePackRule = buildParameters.EnableSharePackRule;
buildReport.Summary.SingleReferencedPackAlone = buildParameters.SingleReferencedPackAlone;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.EncryptionClassName = buildParameters.EncryptionServices == null ? "null" : buildParameters.EncryptionServices.GetType().FullName;
if (buildParameters.BuildPipeline == nameof(BuiltinBuildPipeline))
if (buildParameters is BuiltinBuildParameters)
{
var builtinBuildParameters = buildParameters as BuiltinBuildParameters;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.CompressOption = builtinBuildParameters.CompressOption;
buildReport.Summary.DisableWriteTypeTree = builtinBuildParameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = builtinBuildParameters.IgnoreTypeTreeChanges;
}
else if (buildParameters.BuildPipeline == nameof(ScriptableBuildPipeline))
else if (buildParameters is ScriptableBuildParameters)
{
var scriptableBuildParameters = buildParameters as ScriptableBuildParameters;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.CompressOption = scriptableBuildParameters.CompressOption;
buildReport.Summary.DisableWriteTypeTree = scriptableBuildParameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = scriptableBuildParameters.IgnoreTypeTreeChanges;
}
else
{
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.CompressOption = ECompressOption.Uncompressed;
buildReport.Summary.DisableWriteTypeTree = false;
buildReport.Summary.IgnoreTypeTreeChanges = false;
buildReport.Summary.WriteLinkXML = scriptableBuildParameters.WriteLinkXML;
buildReport.Summary.CacheServerHost = scriptableBuildParameters.CacheServerHost;
buildReport.Summary.CacheServerPort = scriptableBuildParameters.CacheServerPort;
buildReport.Summary.BuiltinShadersBundleName = scriptableBuildParameters.BuiltinShadersBundleName;
buildReport.Summary.MonoScriptsBundleName = scriptableBuildParameters.MonoScriptsBundleName;
}
// 构建结果
@@ -90,7 +85,8 @@ namespace YooAsset.Editor
reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(packageAsset.AssetPath);
reportAssetInfo.MainBundleName = mainBundle.BundleName;
reportAssetInfo.MainBundleSize = mainBundle.FileSize;
reportAssetInfo.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, packageAsset.AssetPath);
reportAssetInfo.DependAssets = GetAssetDependAssets(buildMapContext, mainBundle.BundleName, packageAsset.AssetPath);
reportAssetInfo.DependBundles = GetAssetDependBundles(manifest, packageAsset);
buildReport.AssetInfos.Add(reportAssetInfo);
}
@@ -106,8 +102,9 @@ namespace YooAsset.Editor
reportBundleInfo.FileSize = packageBundle.FileSize;
reportBundleInfo.Encrypted = packageBundle.Encrypted;
reportBundleInfo.Tags = packageBundle.Tags;
reportBundleInfo.DependBundles = GetDependBundles(manifest, packageBundle);
reportBundleInfo.AllBuiltinAssets = GetAllBuiltinAssets(buildMapContext, packageBundle.BundleName);
reportBundleInfo.DependBundles = GetBundleDependBundles(manifest, packageBundle);
reportBundleInfo.ReferenceBundles = GetBundleReferenceBundles(manifest, packageBundle);
reportBundleInfo.BundleContents = GetBundleContents(buildMapContext, packageBundle.BundleName);
buildReport.BundleInfos.Add(reportBundleInfo);
}
@@ -115,19 +112,35 @@ namespace YooAsset.Editor
buildReport.IndependAssets = new List<ReportIndependAsset>(buildMapContext.IndependAssets);
// 序列化文件
string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string fileName = YooAssetSettingsData.GetBuildReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string filePath = $"{packageOutputDirectory}/{fileName}";
BuildReport.Serialize(filePath, buildReport);
BuildLogger.Log($"Create build report file: {filePath}");
}
/// <summary>
/// 获取资源对象依赖的所有资源
/// 获取资源对象依赖的其它所有资源
/// </summary>
private List<string> GetDependBundles(PackageManifest manifest, PackageBundle packageBundle)
private List<AssetInfo> GetAssetDependAssets(BuildMapContext buildMapContext, string bundleName, string assetPath)
{
List<string> dependBundles = new List<string>(packageBundle.DependIDs.Length);
foreach (int index in packageBundle.DependIDs)
List<AssetInfo> result = new List<AssetInfo>();
var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
var assetInfo = bundleInfo.GetPackAssetInfo(assetPath);
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
{
result.Add(dependAssetInfo.AssetInfo);
}
result.Sort();
return result;
}
/// <summary>
/// 获取资源对象依赖的资源包集合
/// </summary>
private List<string> GetAssetDependBundles(PackageManifest manifest, PackageAsset packageAsset)
{
List<string> dependBundles = new List<string>(packageAsset.DependBundleIDs.Length);
foreach (int index in packageAsset.DependBundleIDs)
{
string dependBundleName = manifest.BundleList[index].BundleName;
dependBundles.Add(dependBundleName);
@@ -137,42 +150,42 @@ namespace YooAsset.Editor
}
/// <summary>
/// 获取资源对象依赖的其它所有资源
/// 获取资源依赖的资源包集合
/// </summary>
private List<string> GetDependAssets(BuildMapContext buildMapContext, string bundleName, string assetPath)
private List<string> GetBundleDependBundles(PackageManifest manifest, PackageBundle packageBundle)
{
List<string> result = new List<string>();
var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
List<string> dependBundles = new List<string>(packageBundle.DependBundleIDs.Length);
foreach (int index in packageBundle.DependBundleIDs)
{
BuildAssetInfo findAssetInfo = null;
foreach (var buildAsset in bundleInfo.MainAssets)
{
if (buildAsset.AssetInfo.AssetPath == assetPath)
{
findAssetInfo = buildAsset;
break;
}
}
if (findAssetInfo == null)
{
throw new Exception($"Should never get here ! Not found asset {assetPath} in bunlde {bundleName}");
}
foreach (var dependAssetInfo in findAssetInfo.AllDependAssetInfos)
{
result.Add(dependAssetInfo.AssetInfo.AssetPath);
}
string dependBundleName = manifest.BundleList[index].BundleName;
dependBundles.Add(dependBundleName);
}
result.Sort();
return result;
dependBundles.Sort();
return dependBundles;
}
/// <summary>
/// 获取该资源包内的所有资源
/// 获取引用该资源包的资源包集合
/// </summary>
private List<string> GetAllBuiltinAssets(BuildMapContext buildMapContext, string bundleName)
private List<string> GetBundleReferenceBundles(PackageManifest manifest, PackageBundle packageBundle)
{
List<string> referenceBundles = new List<string>(packageBundle.ReferenceBundleIDs.Count);
foreach (int index in packageBundle.ReferenceBundleIDs)
{
string dependBundleName = manifest.BundleList[index].BundleName;
referenceBundles.Add(dependBundleName);
}
referenceBundles.Sort();
return referenceBundles;
}
/// <summary>
/// 获取资源包内部所有资产
/// </summary>
private List<AssetInfo> GetBundleContents(BuildMapContext buildMapContext, string bundleName)
{
var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
List<string> result = bundleInfo.GetAllBuiltinAssetPaths();
List<AssetInfo> result = bundleInfo.GetBundleContents();
result.Sort();
return result;
}

View File

@@ -21,7 +21,7 @@ namespace YooAsset.Editor
// 1. 获取所有收集器收集的资源
bool useAssetDependencyDB = buildParameters.UseAssetDependencyDB;
var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(simulateBuild, useAssetDependencyDB, packageName);
var collectResult = AssetBundleCollectorSettingData.Setting.BeginCollect(packageName, simulateBuild, useAssetDependencyDB);
List<CollectAssetInfo> allCollectAssets = collectResult.CollectAssets;
// 2. 剔除未被引用的依赖项资源
@@ -109,15 +109,10 @@ namespace YooAsset.Editor
{
if (buildAssetInfo.HasBundleName() == false)
{
PackRuleResult packRuleResult = GetShareBundleName(buildAssetInfo);
if (packRuleResult.IsValid())
{
string shareBundleName = packRuleResult.GetShareBundleName(collectResult.Command.PackageName, collectResult.Command.UniqueBundleName);
buildAssetInfo.SetBundleName(shareBundleName);
}
ProcessingPackShareBundle(buildParameters, collectResult.Command, buildAssetInfo);
}
}
PostProcessPackShareBundle();
PostProcessPackShareBundle(buildParameters, collectResult.Command, allBuildAssetInfos);
}
// 8. 记录关键信息
@@ -209,21 +204,38 @@ namespace YooAsset.Editor
}
/// <summary>
/// 共享资源打包后置处理
/// 共享资源打包机制
/// </summary>
protected virtual void PostProcessPackShareBundle()
protected virtual void ProcessingPackShareBundle(BuildParameters buildParameters, CollectCommand command, BuildAssetInfo buildAssetInfo)
{
}
PackRuleResult packRuleResult = GetShareBundleName(buildAssetInfo);
if (packRuleResult.IsValid() == false)
return;
/// <summary>
/// 获取共享资源包名称
/// </summary>
protected virtual PackRuleResult GetShareBundleName(BuildAssetInfo buildAssetInfo)
// 处理单个引用的共享资源
if (buildAssetInfo.GetReferenceBundleCount() <= 1)
{
if (buildParameters.SingleReferencedPackAlone == false)
return;
}
// 设置共享资源包名
string shareBundleName = packRuleResult.GetShareBundleName(command.PackageName, command.UniqueBundleName);
buildAssetInfo.SetBundleName(shareBundleName);
}
private PackRuleResult GetShareBundleName(BuildAssetInfo buildAssetInfo)
{
string bundleName = Path.GetDirectoryName(buildAssetInfo.AssetInfo.AssetPath);
PackRuleResult result = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension);
return result;
}
/// <summary>
/// 共享资源打包后置处理
/// </summary>
protected virtual void PostProcessPackShareBundle(BuildParameters buildParameters, CollectCommand command, Dictionary<string, BuildAssetInfo> allBuildAssetInfos)
{
}
#endregion
}
}

View File

@@ -45,7 +45,7 @@ namespace YooAsset.Editor
{
long tempSize = 0;
var assetPaths = bundleInfo.GetAllMainAssetPaths();
var assetPaths = bundleInfo.GetAllPackAssetPaths();
foreach (var assetPath in assetPaths)
{
long size = FileUtility.GetFileSize(assetPath);

View File

@@ -23,7 +23,7 @@ namespace YooAsset.Editor
foreach (var bundleInfo in buildMapContext.Collection)
{
string dest = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
foreach (var buildAsset in bundleInfo.MainAssets)
foreach (var buildAsset in bundleInfo.AllPackAssets)
{
EditorTools.CopyFile(buildAsset.AssetInfo.AssetPath, dest, true);
}

View File

@@ -27,7 +27,7 @@ namespace YooAsset.Editor
// 注意:原生文件资源包只能包含一个原生文件
foreach (var bundleInfo in buildMapContext.Collection)
{
if (bundleInfo.MainAssets.Count != 1)
if (bundleInfo.AllPackAssets.Count != 1)
{
string message = BuildLogger.GetErrorMessage(ErrorCode.NotSupportMultipleRawAsset, $"The bundle does not support multiple raw asset : {bundleInfo.BundleName}");
throw new Exception(message);

View File

@@ -13,6 +13,8 @@ namespace YooAsset.Editor
public class BuildResultContext : IContextObject
{
public IBundleBuildResults Results;
public string BuiltinShadersBundleName;
public string MonoScriptsBundleName;
}
void IBuildTask.Run(BuildContext context)
@@ -27,7 +29,9 @@ namespace YooAsset.Editor
// 开始构建
IBundleBuildResults buildResults;
var buildParameters = scriptableBuildParameters.GetBundleBuildParameters();
var taskList = SBPBuildTasks.Create(buildMapContext.Command.ShadersBundleName, null);
string builtinShadersBundleName = scriptableBuildParameters.BuiltinShadersBundleName;
string monoScriptsBundleName = scriptableBuildParameters.MonoScriptsBundleName;
var taskList = SBPBuildTasks.Create(builtinShadersBundleName, monoScriptsBundleName);
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
if (exitCode < 0)
{
@@ -35,18 +39,24 @@ namespace YooAsset.Editor
throw new Exception(message);
}
// 创建着色器信息
// 说明:解决因为着色器资源包导致验证失败。
// 说明:解决因为特殊资源包导致验证失败。
// 例如:当项目里没有着色器,如果有依赖内置着色器就会验证失败。
string shadersBundleName = buildMapContext.Command.ShadersBundleName;
if (buildResults.BundleInfos.ContainsKey(shadersBundleName))
if (string.IsNullOrEmpty(builtinShadersBundleName) == false)
{
buildMapContext.CreateShadersBundleInfo(shadersBundleName);
if (buildResults.BundleInfos.ContainsKey(builtinShadersBundleName))
buildMapContext.CreateEmptyBundleInfo(builtinShadersBundleName);
}
if (string.IsNullOrEmpty(monoScriptsBundleName) == false)
{
if (buildResults.BundleInfos.ContainsKey(monoScriptsBundleName))
buildMapContext.CreateEmptyBundleInfo(monoScriptsBundleName);
}
BuildLogger.Log("UnityEngine build success!");
BuildResultContext buildResultContext = new BuildResultContext();
buildResultContext.Results = buildResults;
buildResultContext.BuiltinShadersBundleName = builtinShadersBundleName;
buildResultContext.MonoScriptsBundleName = monoScriptsBundleName;
context.SetContextObject(buildResultContext);
}
}

View File

@@ -9,7 +9,7 @@ namespace UnityEditor.Build.Pipeline.Tasks
{
public static class SBPBuildTasks
{
public static IList<IBuildTask> Create(string builtInShaderBundleName, string unityMonoScriptsBundleName)
public static IList<IBuildTask> Create(string builtInShaderBundleName, string monoScriptsBundleName)
{
var buildTasks = new List<IBuildTask>();
@@ -30,8 +30,8 @@ namespace UnityEditor.Build.Pipeline.Tasks
buildTasks.Add(new StripUnusedSpriteSources());
if (string.IsNullOrEmpty(builtInShaderBundleName) == false)
buildTasks.Add(new CreateBuiltInShadersBundle(builtInShaderBundleName));
if (string.IsNullOrEmpty(unityMonoScriptsBundleName) == false)
buildTasks.Add(new CreateMonoScriptBundle(unityMonoScriptsBundleName));
if (string.IsNullOrEmpty(monoScriptsBundleName) == false)
buildTasks.Add(new CreateMonoScriptBundle(monoScriptsBundleName));
buildTasks.Add(new PostDependencyCallback());
// Packing

View File

@@ -41,6 +41,17 @@ namespace YooAsset.Editor
public int CacheServerPort;
/// <summary>
/// 内置着色器资源包名称
/// </summary>
public string BuiltinShadersBundleName;
/// <summary>
/// Mono脚本资源包名称
/// </summary>
public string MonoScriptsBundleName;
/// <summary>
/// 获取可编程构建管线的构建参数
/// </summary>

View File

@@ -9,7 +9,7 @@ namespace YooAsset.Editor
private readonly Dictionary<System.Type, IContextObject> _contextObjects = new Dictionary<System.Type, IContextObject>();
/// <summary>
/// 清空所有情景对象
/// 清空所有上下文对象
/// </summary>
public void ClearAllContext()
{
@@ -17,7 +17,7 @@ namespace YooAsset.Editor
}
/// <summary>
/// 设置情景对象
/// 设置上下文对象
/// </summary>
public void SetContextObject(IContextObject contextObject)
{
@@ -32,7 +32,7 @@ namespace YooAsset.Editor
}
/// <summary>
/// 获取情景对象
/// 获取上下文对象
/// </summary>
public T GetContextObject<T>() where T : IContextObject
{
@@ -46,5 +46,21 @@ namespace YooAsset.Editor
throw new Exception($"Not found context object : {type}");
}
}
/// <summary>
/// 获取上下文对象
/// </summary>
public T TryGetContextObject<T>() where T : IContextObject
{
var type = typeof(T);
if (_contextObjects.TryGetValue(type, out IContextObject contextObject))
{
return (T)contextObject;
}
else
{
return default;
}
}
}
}

View File

@@ -12,6 +12,8 @@ namespace YooAsset.Editor
BuildOutputRootIsNullOrEmpty = 113,
BuildinFileRootIsNullOrEmpty = 114,
PackageOutputDirectoryExists = 115,
BuildPipelineIsNullOrEmpty = 116,
BuildBundleTypeIsUnknown = 117,
RecommendScriptBuildPipeline = 130,
// TaskGetBuildMap

View File

@@ -28,6 +28,7 @@ namespace YooAsset.Editor
var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline);
var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline);
var useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline);
var builtinShaderBundleName = GetBuiltinShaderBundleName();
ScriptableBuildParameters buildParameters = new ScriptableBuildParameters();
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
@@ -45,6 +46,7 @@ namespace YooAsset.Editor
buildParameters.CompressOption = compressOption;
buildParameters.ClearBuildCacheFiles = clearBuildCache;
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
buildParameters.BuiltinShadersBundleName = builtinShaderBundleName;
buildParameters.EncryptionServices = CreateEncryptionInstance();
ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline();
@@ -52,6 +54,17 @@ namespace YooAsset.Editor
if (buildResult.Success)
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
}
/// <summary>
/// 内置着色器资源包名称
/// 注意:和自动收集的着色器资源包名保持一致!
/// </summary>
private string GetBuiltinShaderBundleName()
{
var uniqueBundleName = AssetBundleCollectorSettingData.Setting.UniqueBundleName;
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
return packRuleResult.GetBundleName(PackageName, uniqueBundleName);
}
}
}
#endif

View File

@@ -98,9 +98,9 @@ namespace YooAsset.Editor
}
/// <summary>
/// 获取打包收集的资源文件
/// 获取收集的资源列表
/// </summary>
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
public List<CollectAssetInfo> GetCollectAssets(CollectCommand command)
{
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
@@ -138,7 +138,7 @@ namespace YooAsset.Editor
}
}
// 返回列表
// 返回结果
return result.Values.ToList();
}

View File

@@ -86,10 +86,16 @@ namespace YooAsset.Editor
return package.GetAllTags();
}
/// <summary>
/// 获取包裹收集的资源文件
/// </summary>
[Obsolete("This method will be removed in a future ! Use BeginCollect instead.", true)]
public CollectResult GetPackageAssets(bool simulateBuild, bool useAssetDependencyDB, string packageName)
{
return BeginCollect(packageName, simulateBuild, useAssetDependencyDB);
}
/// <summary>
/// 收集指定包裹的资源文件
/// </summary>
public CollectResult BeginCollect(string packageName, bool simulateBuild, bool useAssetDependencyDB)
{
if (string.IsNullOrEmpty(packageName))
throw new Exception("Build package name is null or empty !");
@@ -100,16 +106,18 @@ namespace YooAsset.Editor
// 创建资源收集命令
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(package.IgnoreRuleName);
CollectCommand command = new CollectCommand(simulateBuild, useAssetDependencyDB, packageName,
package.EnableAddressable,
package.LocationToLower,
package.IncludeAssetGUID,
package.AutoCollectShaders,
UniqueBundleName, ignoreRule);
var command = new CollectCommand(packageName, ignoreRule);
command.SimulateBuild = simulateBuild;
command.UniqueBundleName = UniqueBundleName;
command.UseAssetDependencyDB = useAssetDependencyDB;
command.EnableAddressable = package.EnableAddressable;
command.LocationToLower = package.LocationToLower;
command.IncludeAssetGUID = package.IncludeAssetGUID;
command.AutoCollectShaders = package.AutoCollectShaders;
// 获取收集的资源集合
CollectResult collectResult = new CollectResult(command);
collectResult.SetCollectAssets(package.GetAllCollectAssets(command));
// 开始收集工作
var collectAssets = package.GetCollectAssets(command);
var collectResult = new CollectResult(command, collectAssets);
return collectResult;
}

View File

@@ -201,7 +201,6 @@ namespace YooAsset.Editor
public static void ClearAll()
{
Setting.ClearAll();
SaveFile();
}
public static List<RuleDisplayName> GetActiveRuleNames()

View File

@@ -164,25 +164,25 @@ namespace YooAsset.Editor
RefreshWindow();
}
});
// 忽略规则
_ignoreRulePopupField = new PopupField<RuleDisplayName>(_ignoreRuleList, 0);
_ignoreRulePopupField.label = "File Ignore Rule";
_ignoreRulePopupField.name = "IgnoreRulePopupField";
_ignoreRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
_ignoreRulePopupField.style.width = 300;
_ignoreRulePopupField.formatListItemCallback = FormatListItemCallback;
_ignoreRulePopupField.formatSelectedValueCallback = FormatSelectedValueCallback;
_ignoreRulePopupField.RegisterValueChangedCallback(evt =>
{
_ignoreRulePopupField = new PopupField<RuleDisplayName>(_ignoreRuleList, 0);
_ignoreRulePopupField.label = "File Ignore Rule";
_ignoreRulePopupField.name = "IgnoreRulePopupField";
_ignoreRulePopupField.style.unityTextAlign = TextAnchor.MiddleLeft;
_ignoreRulePopupField.style.width = 300;
_ignoreRulePopupField.formatListItemCallback = FormatListItemCallback;
_ignoreRulePopupField.formatSelectedValueCallback = FormatSelectedValueCallback;
_ignoreRulePopupField.RegisterValueChangedCallback(evt =>
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage != null)
{
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
if (selectPackage != null)
{
selectPackage.IgnoreRuleName = evt.newValue.ClassName;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
}
});
_setting2Container.Add(_ignoreRulePopupField);
}
selectPackage.IgnoreRuleName = evt.newValue.ClassName;
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
}
});
_setting2Container.Add(_ignoreRulePopupField);
// 配置修复按钮
var fixBtn = root.Q<Button>("FixButton");
@@ -205,7 +205,9 @@ namespace YooAsset.Editor
_packageListView = root.Q<ListView>("PackageListView");
_packageListView.makeItem = MakePackageListViewItem;
_packageListView.bindItem = BindPackageListViewItem;
#if UNITY_2020_1_OR_NEWER
#if UNITY_2022_3_OR_NEWER
_packageListView.selectionChanged += PackageListView_onSelectionChange;
#elif UNITY_2020_1_OR_NEWER
_packageListView.onSelectionChange += PackageListView_onSelectionChange;
#else
_packageListView.onSelectionChanged += PackageListView_onSelectionChange;
@@ -250,7 +252,9 @@ namespace YooAsset.Editor
_groupListView = root.Q<ListView>("GroupListView");
_groupListView.makeItem = MakeGroupListViewItem;
_groupListView.bindItem = BindGroupListViewItem;
#if UNITY_2020_1_OR_NEWER
#if UNITY_2022_3_OR_NEWER
_groupListView.selectionChanged += GroupListView_onSelectionChange;
#elif UNITY_2020_1_OR_NEWER
_groupListView.onSelectionChange += GroupListView_onSelectionChange;
#else
_groupListView.onSelectionChanged += GroupListView_onSelectionChange;
@@ -991,14 +995,16 @@ namespace YooAsset.Editor
try
{
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(_ignoreRulePopupField.value.ClassName);
CollectCommand command = new CollectCommand(true, false,
_packageNameTxt.value,
_enableAddressableToogle.value,
_locationToLowerToogle.value,
_includeAssetGUIDToogle.value,
_autoCollectShadersToogle.value,
_uniqueBundleNameToogle.value,
ignoreRule);
string packageName = _packageNameTxt.value;
var command = new CollectCommand(packageName, ignoreRule);
command.SimulateBuild = true;
command.UniqueBundleName = _uniqueBundleNameToogle.value;
command.UseAssetDependencyDB = true;
command.EnableAddressable = _enableAddressableToogle.value;
command.LocationToLower = _locationToLowerToogle.value;
command.IncludeAssetGUID = _includeAssetGUIDToogle.value;
command.AutoCollectShaders = _autoCollectShadersToogle.value;
collector.CheckConfigError();
collectAssetInfos = collector.GetAllCollectAssets(command, group);
}

View File

@@ -28,7 +28,7 @@
<ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;">
<ui:VisualElement name="PackageContainer" 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:Label text="Packages" display-tooltip-when-elided="true" name="PackageTitle" style="background-color: rgb(89, 89, 89); -unity-text-align: upper-center; -unity-font-style: bold; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px; font-size: 12px;" />
<ui:ListView focusable="true" name="PackageListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:ListView focusable="true" name="PackageListView" item-height="20" virtualization-method="DynamicHeight" reorderable="true" reorder-mode="Animated" style="flex-grow: 1;" />
<ui:VisualElement name="PackageAddContainer" 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="AddBtn" />
@@ -36,9 +36,9 @@
</ui:VisualElement>
<ui:VisualElement name="GroupContainer" 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:Label text="Groups" display-tooltip-when-elided="true" name="GroupTitle" style="background-color: rgb(89, 89, 89); -unity-text-align: upper-center; -unity-font-style: bold; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px; font-size: 12px;" />
<ui:TextField picking-mode="Ignore" label="Package Name" value="filler text" name="PackageName" style="flex-direction: column;" />
<ui:TextField picking-mode="Ignore" label="Package Desc" value="filler text" name="PackageDesc" style="flex-direction: column;" />
<ui:ListView focusable="true" name="GroupListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:TextField picking-mode="Ignore" label="Package Name" name="PackageName" style="flex-direction: column;" />
<ui:TextField picking-mode="Ignore" label="Package Desc" name="PackageDesc" style="flex-direction: column;" />
<ui:ListView focusable="true" name="GroupListView" item-height="20" virtualization-method="DynamicHeight" reorderable="true" reorder-mode="Animated" style="flex-grow: 1;" />
<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="AddBtn" />

View File

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

View File

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

View File

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

View File

@@ -3,75 +3,51 @@ namespace YooAsset.Editor
{
public class CollectCommand
{
/// <summary>
/// 模拟构建模式
/// </summary>
public bool SimulateBuild { private set; get; }
/// <summary>
/// 使用资源依赖数据库
/// </summary>
public bool UseAssetDependencyDB { private set; get; }
/// <summary>
/// 包裹名称
/// </summary>
public string PackageName { private set; get; }
/// <summary>
/// 启用可寻址资源定位
/// </summary>
public bool EnableAddressable { private set; get; }
/// <summary>
/// 资源定位地址大小写不敏感
/// </summary>
public bool LocationToLower { private set; get; }
/// <summary>
/// 包含资源GUID数据
/// </summary>
public bool IncludeAssetGUID { private set; get; }
/// <summary>
/// 自动收集所有着色器
/// </summary>
public bool AutoCollectShaders { private set; get; }
/// <summary>
/// 资源包名唯一化
/// </summary>
public bool UniqueBundleName { private set; get; }
/// <summary>
/// 着色器统一全名称
/// </summary>
public string ShadersBundleName { private set; get; }
/// <summary>
/// 忽略规则实例
/// </summary>
public IIgnoreRule IgnoreRule { private set; get; }
public CollectCommand(bool simulateBuild, bool useAssetDependencyDB, string packageName,
bool enableAddressable, bool locationToLower, bool includeAssetGUID,
bool autoCollectShaders, bool uniqueBundleName, IIgnoreRule ignoreRule)
{
SimulateBuild = simulateBuild;
UseAssetDependencyDB = useAssetDependencyDB;
PackageName = packageName;
EnableAddressable = enableAddressable;
LocationToLower = locationToLower;
IncludeAssetGUID = includeAssetGUID;
AutoCollectShaders = autoCollectShaders;
UniqueBundleName = uniqueBundleName;
IgnoreRule = ignoreRule;
/// <summary>
/// 模拟构建模式
/// </summary>
public bool SimulateBuild { set; get; }
// 着色器统一全名称
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
ShadersBundleName = packRuleResult.GetBundleName(packageName, uniqueBundleName);
}
/// <summary>
/// 资源包名唯一化
/// </summary>
public bool UniqueBundleName { set; get; }
/// <summary>
/// 使用资源依赖数据库
/// </summary>
public bool UseAssetDependencyDB { set; get; }
/// <summary>
/// 启用可寻址资源定位
/// </summary>
public bool EnableAddressable { set; get; }
/// <summary>
/// 资源定位地址大小写不敏感
/// </summary>
public bool LocationToLower { set; get; }
/// <summary>
/// 包含资源GUID数据
/// </summary>
public bool IncludeAssetGUID { set; get; }
/// <summary>
/// 自动收集所有着色器
/// </summary>
public bool AutoCollectShaders { set; get; }
private AssetDependencyCache _assetDependency;
public AssetDependencyCache AssetDependency
@@ -83,5 +59,11 @@ namespace YooAsset.Editor
return _assetDependency;
}
}
public CollectCommand(string packageName, IIgnoreRule ignoreRule)
{
PackageName = packageName;
IgnoreRule = ignoreRule;
}
}
}

View File

@@ -15,12 +15,9 @@ namespace YooAsset.Editor
/// </summary>
public List<CollectAssetInfo> CollectAssets { private set; get; }
public CollectResult(CollectCommand command)
public CollectResult(CollectCommand command, List<CollectAssetInfo> collectAssets)
{
Command = command;
}
public void SetCollectAssets(List<CollectAssetInfo> collectAssets)
{
CollectAssets = collectAssets;
}
}

View File

@@ -147,6 +147,22 @@ namespace YooAsset.Editor
}
}
/// <summary>
/// 打包视频文件
/// </summary>
[DisplayName("打包视频文件")]
public class PackVideoFile : IPackRule
{
PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data)
{
string bundleName = data.AssetPath;
string fileExtension = Path.GetExtension(data.AssetPath);
fileExtension = fileExtension.Remove(0, 1);
PackRuleResult result = new PackRuleResult(bundleName, fileExtension);
return result;
}
}
/// <summary>
/// 打包着色器
/// </summary>

View File

@@ -38,21 +38,31 @@ namespace YooAsset.Editor
/// 资源包视图
/// </summary>
BundleView,
/// <summary>
/// 异步操作视图
/// </summary>
OperationView,
}
private readonly Dictionary<int, RemotePlayerSession> _playerSessions = new Dictionary<int, RemotePlayerSession>();
private Label _playerName;
private ToolbarButton _playerName;
private ToolbarMenu _viewModeMenu;
private SliderInt _frameSlider;
private DebuggerAssetListViewer _assetListViewer;
private DebuggerBundleListViewer _bundleListViewer;
private DebuggerOperationListViewer _operationListViewer;
private EViewMode _viewMode;
private string _searchKeyWord;
private DebugReport _currentReport;
private RemotePlayerSession _currentPlayerSession;
private double _lastRepaintTime = 0;
private int _nextRepaintIndex = -1;
private int _lastRepaintIndex = 0;
private int _rangeIndex = 0;
@@ -78,13 +88,14 @@ namespace YooAsset.Editor
exportBtn.clicked += ExportBtn_clicked;
// 用户列表菜单
_playerName = root.Q<Label>("PlayerName");
_playerName = root.Q<ToolbarButton>("PlayerName");
_playerName.text = "Editor player";
// 视口模式菜单
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.AssetView);
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.BundleView);
_viewModeMenu.menu.AppendAction(EViewMode.OperationView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.OperationView);
_viewModeMenu.text = EViewMode.AssetView.ToString();
// 搜索栏
@@ -111,6 +122,9 @@ namespace YooAsset.Editor
var frameClear = root.Q<ToolbarButton>("FrameClear");
frameClear.clicked += OnFrameClear_clicked;
var recorderToggle = root.Q<ToggleRecord>("FrameRecord");
recorderToggle.RegisterValueChangedCallback(OnRecordToggleValueChange);
}
// 加载视图
@@ -121,6 +135,10 @@ namespace YooAsset.Editor
_bundleListViewer = new DebuggerBundleListViewer();
_bundleListViewer.InitViewer();
// 加载视图
_operationListViewer = new DebuggerOperationListViewer();
_operationListViewer.InitViewer();
// 显示视图
_viewMode = EViewMode.AssetView;
_assetListViewer.AttachParent(root);
@@ -129,8 +147,9 @@ namespace YooAsset.Editor
EditorConnection.instance.Initialize();
EditorConnection.instance.RegisterConnection(OnHandleConnectionEvent);
EditorConnection.instance.RegisterDisconnection(OnHandleDisconnectionEvent);
EditorConnection.instance.Register(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
RemoteDebuggerInRuntime.EditorHandleDebugReportCallback = OnHandleDebugReport;
EditorConnection.instance.Register(RemoteDebuggerDefine.kMsgPlayerSendToEditor, OnHandlePlayerMessage);
RemoteEditorConnection.Instance.Initialize();
RemoteEditorConnection.Instance.Register(RemoteDebuggerDefine.kMsgPlayerSendToEditor, OnHandlePlayerMessage);
}
catch (Exception e)
{
@@ -142,9 +161,23 @@ namespace YooAsset.Editor
// 远程调试
EditorConnection.instance.UnregisterConnection(OnHandleConnectionEvent);
EditorConnection.instance.UnregisterDisconnection(OnHandleDisconnectionEvent);
EditorConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
EditorConnection.instance.Unregister(RemoteDebuggerDefine.kMsgPlayerSendToEditor, OnHandlePlayerMessage);
RemoteEditorConnection.Instance.Unregister(RemoteDebuggerDefine.kMsgPlayerSendToEditor);
_playerSessions.Clear();
}
public void Update()
{
// 每间隔1秒绘制一次页面
if (EditorApplication.timeSinceStartup - _lastRepaintTime > 1f)
{
_lastRepaintTime = EditorApplication.timeSinceStartup;
if (_nextRepaintIndex >= 0)
{
RepaintFrame(_nextRepaintIndex);
_nextRepaintIndex = -1;
}
}
}
private void OnHandleConnectionEvent(int playerId)
{
@@ -158,24 +191,27 @@ namespace YooAsset.Editor
}
private void OnHandlePlayerMessage(MessageEventArgs args)
{
int playerId = args.playerId;
var debugReport = DebugReport.Deserialize(args.data);
OnHandleDebugReport(args.playerId, debugReport);
}
private void OnHandleDebugReport(int playerId, DebugReport debugReport)
{
Debug.Log($"Handle player {playerId} debug report !");
if (debugReport.DebuggerVersion != RemoteDebuggerDefine.DebuggerVersion)
{
Debug.LogWarning($"Debugger versions are inconsistent : {debugReport.DebuggerVersion} != {RemoteDebuggerDefine.DebuggerVersion}");
return;
}
//Debug.Log($"Handle player {playerId} debug report !");
_currentPlayerSession = GetOrCreatePlayerSession(playerId);
_currentPlayerSession.AddDebugReport(debugReport);
_frameSlider.highValue = _currentPlayerSession.MaxRangeValue;
_frameSlider.value = _currentPlayerSession.MaxRangeValue;
UpdateFrameView(_currentPlayerSession);
_nextRepaintIndex = _currentPlayerSession.MaxRangeValue;
}
private void OnFrameSliderChange(int sliderValue)
{
if (_currentPlayerSession != null)
{
_rangeIndex = _currentPlayerSession.ClampRangeIndex(sliderValue); ;
UpdateFrameView(_currentPlayerSession, _rangeIndex);
RepaintFrame(_rangeIndex);
}
}
private void OnFrameLast_clicked()
@@ -184,7 +220,7 @@ namespace YooAsset.Editor
{
_rangeIndex = _currentPlayerSession.ClampRangeIndex(_rangeIndex - 1);
_frameSlider.value = _rangeIndex;
UpdateFrameView(_currentPlayerSession, _rangeIndex);
RepaintFrame(_rangeIndex);
}
}
private void OnFrameNext_clicked()
@@ -193,56 +229,37 @@ namespace YooAsset.Editor
{
_rangeIndex = _currentPlayerSession.ClampRangeIndex(_rangeIndex + 1);
_frameSlider.value = _rangeIndex;
UpdateFrameView(_currentPlayerSession, _rangeIndex);
RepaintFrame(_rangeIndex);
}
}
private void OnFrameClear_clicked()
{
_nextRepaintIndex = -1;
_lastRepaintIndex = 0;
_rangeIndex = 0;
_frameSlider.label = $"Frame:";
_frameSlider.value = 0;
_frameSlider.lowValue = 0;
_frameSlider.highValue = 0;
_assetListViewer.ClearView();
_bundleListViewer.ClearView();
_operationListViewer.ClearView();
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)
private void OnRecordToggleValueChange(ChangeEvent<bool> evt)
{
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);
}
// 发送采集数据的命令
RemoteCommand command = new RemoteCommand();
command.CommandType = (int)ERemoteCommand.SampleAuto;
command.CommandParam = evt.newValue ? "open" : "close";
byte[] data = RemoteCommand.Serialize(command);
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
RemoteEditorConnection.Instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
}
private void SampleBtn_onClick()
@@ -252,8 +269,8 @@ namespace YooAsset.Editor
command.CommandType = (int)ERemoteCommand.SampleOnce;
command.CommandParam = string.Empty;
byte[] data = RemoteCommand.Serialize(command);
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgSendEditorToPlayer, data);
RemoteDebuggerInRuntime.EditorRequestDebugReport();
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
RemoteEditorConnection.Instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
}
private void ExportBtn_clicked()
{
@@ -272,7 +289,7 @@ namespace YooAsset.Editor
packageData.ProviderInfos.Sort();
foreach (var providerInfo in packageData.ProviderInfos)
{
providerInfo.DependBundleInfos.Sort();
providerInfo.DependBundles.Sort();
}
}
@@ -286,8 +303,9 @@ namespace YooAsset.Editor
_searchKeyWord = e.newValue;
if (_currentReport != null)
{
_assetListViewer.FillViewData(_currentReport, _searchKeyWord);
_bundleListViewer.FillViewData(_currentReport, _searchKeyWord);
_assetListViewer.RebuildView(_searchKeyWord);
_bundleListViewer.RebuildView(_searchKeyWord);
_operationListViewer.RebuildView(_searchKeyWord);
}
}
private void OnViewModeMenuChange(DropdownMenuAction action)
@@ -303,16 +321,27 @@ namespace YooAsset.Editor
{
_assetListViewer.AttachParent(root);
_bundleListViewer.DetachParent();
_operationListViewer.DetachParent();
}
else if (viewMode == EViewMode.BundleView)
{
_assetListViewer.DetachParent();
_bundleListViewer.AttachParent(root);
_operationListViewer.DetachParent();
}
else if (viewMode == EViewMode.OperationView)
{
_assetListViewer.DetachParent();
_bundleListViewer.DetachParent();
_operationListViewer.AttachParent(root);
}
else
{
throw new NotImplementedException(viewMode.ToString());
}
// 重新绘制该帧数据
RepaintFrame(_lastRepaintIndex);
}
}
private DropdownMenuAction.Status OnViewModeMenuStatusUpdate(DropdownMenuAction action)
@@ -323,6 +352,63 @@ namespace YooAsset.Editor
else
return DropdownMenuAction.Status.Normal;
}
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 RepaintFrame(int repaintIndex)
{
if (_currentPlayerSession == null)
{
_assetListViewer.ClearView();
_bundleListViewer.ClearView();
_operationListViewer.ClearView();
return;
}
var debugReport = _currentPlayerSession.GetDebugReport(repaintIndex);
if (debugReport != null)
{
_lastRepaintIndex = repaintIndex;
_currentReport = debugReport;
_frameSlider.label = $"Frame: {debugReport.FrameCount}";
_frameSlider.highValue = _currentPlayerSession.MaxRangeValue;
_frameSlider.value = repaintIndex;
if (_viewMode == EViewMode.AssetView)
{
_assetListViewer.FillViewData(debugReport);
_bundleListViewer.ClearView();
_operationListViewer.ClearView();
}
else if (_viewMode == EViewMode.BundleView)
{
_assetListViewer.ClearView();
_bundleListViewer.FillViewData(debugReport);
_operationListViewer.ClearView();
}
else if (_viewMode == EViewMode.OperationView)
{
_assetListViewer.ClearView();
_bundleListViewer.ClearView();
_operationListViewer.FillViewData(debugReport);
}
else
{
throw new System.NotImplementedException(_viewMode.ToString());
}
}
}
}
}
#endif

View File

@@ -1,7 +1,7 @@
<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="TopToolbar" style="display: flex;">
<ui:Label text="Player" display-tooltip-when-elided="true" name="PlayerName" style="width: 200px; -unity-text-align: lower-left; padding-left: 5px;" />
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" />
<uie:ToolbarButton text="IP" parse-escape-sequences="true" display-tooltip-when-elided="true" name="PlayerName" style="width: 200px;" />
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 150px; flex-grow: 0;" />
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
<uie:ToolbarButton text="Refresh" 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="Export" display-tooltip-when-elided="true" name="ExportButton" 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;" />
@@ -11,5 +11,6 @@
<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" />
<YooAsset.Editor.ToggleRecord name="FrameRecord" style="width: 20px;" />
</uie:Toolbar>
</ui:UXML>

View File

@@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace YooAsset.Editor
{
internal class RemotePlayerSession
{
private readonly List<DebugReport> _reportList = new List<DebugReport>();
private readonly Queue<DebugReport> _reports = new Queue<DebugReport>();
/// <summary>
/// 用户ID
@@ -29,7 +30,7 @@ namespace YooAsset.Editor
{
get
{
int index = _reportList.Count - 1;
int index = _reports.Count - 1;
if (index < 0)
index = 0;
return index;
@@ -37,7 +38,7 @@ namespace YooAsset.Editor
}
public RemotePlayerSession(int playerId, int maxReportCount = 1000)
public RemotePlayerSession(int playerId, int maxReportCount = 500)
{
PlayerId = playerId;
MaxReportCount = maxReportCount;
@@ -48,7 +49,7 @@ namespace YooAsset.Editor
/// </summary>
public void ClearDebugReport()
{
_reportList.Clear();
_reports.Clear();
}
/// <summary>
@@ -59,9 +60,9 @@ namespace YooAsset.Editor
if (report == null)
Debug.LogWarning("Invalid debug report data !");
if (_reportList.Count >= MaxReportCount)
_reportList.RemoveAt(0);
_reportList.Add(report);
if (_reports.Count >= MaxReportCount)
_reports.Dequeue();
_reports.Enqueue(report);
}
/// <summary>
@@ -69,11 +70,11 @@ namespace YooAsset.Editor
/// </summary>
public DebugReport GetDebugReport(int rangeIndex)
{
if (_reportList.Count == 0)
if (_reports.Count == 0)
return null;
if (rangeIndex < 0 || rangeIndex >= _reportList.Count)
if (rangeIndex < 0 || rangeIndex >= _reports.Count)
return null;
return _reportList[rangeIndex];
return _reports.ElementAt(rangeIndex);
}
/// <summary>

View File

@@ -11,12 +11,24 @@ namespace YooAsset.Editor
{
internal class DebuggerAssetListViewer
{
private class ProviderTableData : DefaultTableData
{
public DebugPackageData PackageData;
public DebugProviderInfo ProviderInfo;
}
private class DependTableData : DefaultTableData
{
public DebugBundleInfo BundleInfo;
}
private VisualTreeAsset _visualAsset;
private TemplateContainer _root;
private ListView _assetListView;
private ListView _dependListView;
private DebugReport _debugReport;
private TableViewer _providerTableView;
private TableViewer _dependTableView;
private List<ITableData> _sourceDatas;
/// <summary>
/// 初始化页面
@@ -32,23 +44,287 @@ namespace YooAsset.Editor
_root.style.flexGrow = 1f;
// 资源列表
_assetListView = _root.Q<ListView>("TopListView");
_assetListView.makeItem = MakeAssetListViewItem;
_assetListView.bindItem = BindAssetListViewItem;
#if UNITY_2020_1_OR_NEWER
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
#else
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
#endif
_providerTableView = _root.Q<TableViewer>("TopTableView");
_providerTableView.SelectionChangedEvent = OnProviderTableViewSelectionChanged;
CreateAssetTableViewColumns();
// 依赖列表
_dependListView = _root.Q<ListView>("BottomListView");
_dependListView.makeItem = MakeDependListViewItem;
_dependListView.bindItem = BindDependListViewItem;
_dependTableView = _root.Q<TableViewer>("BottomTableView");
CreateDependTableViewColumns();
#if UNITY_2020_3_OR_NEWER
SplitView.Adjuster(_root);
#endif
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
}
private void CreateAssetTableViewColumns()
{
// PackageName
{
var columnStyle = new ColumnStyle(200);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("PackageName", "Package Name", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_providerTableView.AddColumn(column);
}
// AssetPath
{
var columnStyle = new ColumnStyle(600, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("AssetPath", "Asset Path", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_providerTableView.AddColumn(column);
}
// SpawnScene
{
var columnStyle = new ColumnStyle(150);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("SpawnScene", "Spawn Scene", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_providerTableView.AddColumn(column);
}
// BeginTime
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("BeginTime", "Begin Time", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_providerTableView.AddColumn(column);
}
// LoadingTime
{
var columnStyle = new ColumnStyle(130);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
columnStyle.Units = "ms";
var column = new TableColumn("LoadingTime", "Loading Time", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_providerTableView.AddColumn(column);
}
// RefCount
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("RefCount", "Ref Count", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_providerTableView.AddColumn(column);
}
// Status
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("Status", "Status", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
StyleColor textColor;
var providerTableData = data as ProviderTableData;
if (providerTableData.ProviderInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = new StyleColor(Color.white);
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
infoLabel.style.color = textColor;
};
_providerTableView.AddColumn(column);
}
}
private void CreateDependTableViewColumns()
{
//DependBundles
{
var columnStyle = new ColumnStyle(600, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("DependBundles", "Depend Bundles", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_dependTableView.AddColumn(column);
}
// RefCount
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("RefCount", "Ref Count", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_dependTableView.AddColumn(column);
}
// Status
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("Status", "Status", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
StyleColor textColor;
var dependTableData = data as DependTableData;
if (dependTableData.BundleInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = new StyleColor(Color.white);
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
infoLabel.style.color = textColor;
};
_dependTableView.AddColumn(column);
}
}
/// <summary>
/// 填充页面数据
/// </summary>
public void FillViewData(DebugReport debugReport)
{
// 清空旧数据
_providerTableView.ClearAll(false, true);
_dependTableView.ClearAll(false, true);
// 填充数据源
_sourceDatas = new List<ITableData>(1000);
foreach (var packageData in debugReport.PackageDatas)
{
foreach (var providerInfo in packageData.ProviderInfos)
{
var rowData = new ProviderTableData();
rowData.PackageData = packageData;
rowData.ProviderInfo = providerInfo;
rowData.AddAssetPathCell("PackageName", packageData.PackageName);
rowData.AddStringValueCell("AssetPath", providerInfo.AssetPath);
rowData.AddStringValueCell("SpawnScene", providerInfo.SpawnScene);
rowData.AddStringValueCell("BeginTime", providerInfo.BeginTime);
rowData.AddLongValueCell("LoadingTime", providerInfo.LoadingTime);
rowData.AddLongValueCell("RefCount", providerInfo.RefCount);
rowData.AddStringValueCell("Status", providerInfo.Status.ToString());
_sourceDatas.Add(rowData);
}
}
_providerTableView.itemsSource = _sourceDatas;
// 重建视图
RebuildView(null);
}
/// <summary>
@@ -56,46 +332,25 @@ namespace YooAsset.Editor
/// </summary>
public void ClearView()
{
_debugReport = null;
_assetListView.Clear();
_assetListView.ClearSelection();
_assetListView.itemsSource.Clear();
_assetListView.Rebuild();
_providerTableView.ClearAll(false, true);
_providerTableView.RebuildView();
_dependTableView.ClearAll(false, true);
_dependTableView.RebuildView();
}
/// <summary>
/// 填充页面数据
/// 重建视图
/// </summary>
public void FillViewData(DebugReport debugReport, string searchKeyWord)
public void RebuildView(string searchKeyWord)
{
_debugReport = debugReport;
_assetListView.Clear();
_assetListView.ClearSelection();
_assetListView.itemsSource = FilterViewItems(debugReport, searchKeyWord);
_assetListView.Rebuild();
}
private List<DebugProviderInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
{
List<DebugProviderInfo> result = new List<DebugProviderInfo>(1000);
foreach (var packageData in debugReport.PackageDatas)
{
var tempList = new List<DebugProviderInfo>(packageData.ProviderInfos.Count);
foreach (var providerInfo in packageData.ProviderInfos)
{
if (string.IsNullOrEmpty(searchKeyWord) == false)
{
if (providerInfo.AssetPath.Contains(searchKeyWord) == false)
continue;
}
// 搜索匹配
if (_sourceDatas != null)
DefaultSearchSystem.Search(_sourceDatas, searchKeyWord);
providerInfo.PackageName = packageData.PackageName;
tempList.Add(providerInfo);
}
tempList.Sort();
result.AddRange(tempList);
}
return result;
// 重建视图
_providerTableView.RebuildView();
_dependTableView.RebuildView();
}
/// <summary>
@@ -114,194 +369,26 @@ namespace YooAsset.Editor
_root.RemoveFromHierarchy();
}
// 顶部列表相关
private VisualElement MakeAssetListViewItem()
private void OnProviderTableViewSelectionChanged(ITableData data)
{
VisualElement element = new VisualElement();
element.style.flexDirection = FlexDirection.Row;
var providerTableData = data as ProviderTableData;
DebugPackageData packageData = providerTableData.PackageData;
DebugProviderInfo providerInfo = providerTableData.ProviderInfo;
// 填充依赖数据
var sourceDatas = new List<ITableData>(providerInfo.DependBundles.Count);
foreach (var bundleName in providerInfo.DependBundles)
{
var label = new Label();
label.name = "Label0";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
var dependBundleInfo = packageData.GetBundleInfo(bundleName);
var rowData = new DependTableData();
rowData.BundleInfo = dependBundleInfo;
rowData.AddStringValueCell("DependBundles", dependBundleInfo.BundleName);
rowData.AddLongValueCell("RefCount", dependBundleInfo.RefCount);
rowData.AddStringValueCell("Status", dependBundleInfo.Status.ToString());
sourceDatas.Add(rowData);
}
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
}
{
var label = new Label();
label.name = "Label2";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
{
var label = new Label();
label.name = "Label3";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
{
var label = new Label();
label.name = "Label4";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
{
var label = new Label();
label.name = "Label5";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}
{
var label = new Label();
label.name = "Label6";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 120;
element.Add(label);
}
return element;
}
private void BindAssetListViewItem(VisualElement element, int index)
{
var sourceData = _assetListView.itemsSource as List<DebugProviderInfo>;
var providerInfo = sourceData[index];
// Package Name
var label0 = element.Q<Label>("Label0");
label0.text = providerInfo.PackageName;
// Asset Path
var label1 = element.Q<Label>("Label1");
label1.text = providerInfo.AssetPath;
// Spawn Scene
var label2 = element.Q<Label>("Label2");
label2.text = providerInfo.SpawnScene;
// Spawn Time
var label3 = element.Q<Label>("Label3");
label3.text = providerInfo.SpawnTime;
// Loading Time
var label4 = element.Q<Label>("Label4");
label4.text = providerInfo.LoadingTime.ToString();
// Ref Count
var label5 = element.Q<Label>("Label5");
label5.text = providerInfo.RefCount.ToString();
// Status
StyleColor textColor;
if (providerInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = label1.style.color;
var label6 = element.Q<Label>("Label6");
label6.text = providerInfo.Status.ToString();
label6.style.color = textColor;
}
private void AssetListView_onSelectionChange(IEnumerable<object> objs)
{
foreach (var item in objs)
{
DebugProviderInfo providerInfo = item as DebugProviderInfo;
FillDependListView(providerInfo);
}
}
// 底部列表相关
private VisualElement MakeDependListViewItem()
{
VisualElement element = new VisualElement();
element.style.flexDirection = FlexDirection.Row;
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
}
{
var label = new Label();
label.name = "Label3";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}
{
var label = new Label();
label.name = "Label4";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 120;
element.Add(label);
}
return element;
}
private void BindDependListViewItem(VisualElement element, int index)
{
List<DebugBundleInfo> bundles = _dependListView.itemsSource as List<DebugBundleInfo>;
DebugBundleInfo bundleInfo = bundles[index];
// Bundle Name
var label1 = element.Q<Label>("Label1");
label1.text = bundleInfo.BundleName;
// Ref Count
var label3 = element.Q<Label>("Label3");
label3.text = bundleInfo.RefCount.ToString();
// Status
var label4 = element.Q<Label>("Label4");
label4.text = bundleInfo.Status.ToString();
}
private void FillDependListView(DebugProviderInfo selectedProviderInfo)
{
_dependListView.Clear();
_dependListView.ClearSelection();
_dependListView.itemsSource = selectedProviderInfo.DependBundleInfos;
_dependListView.Rebuild();
_dependTableView.itemsSource = sourceDatas;
_dependTableView.RebuildView();
}
}
}

View File

@@ -1,22 +1,8 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Package Name" display-tooltip-when-elided="true" name="TopBar0" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Asset Path" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Spawn Scene" display-tooltip-when-elided="true" name="TopBar2" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Spawn Time" display-tooltip-when-elided="true" name="TopBar3" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Loading Time (ms)" display-tooltip-when-elided="true" name="TopBar4" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar5" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar6" style="width: 120px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<YooAsset.Editor.TableViewer name="TopTableView" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Depend Bundles" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="BottomBar4" style="width: 120px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex; flex-grow: 1;">
<YooAsset.Editor.TableViewer name="BottomTableView" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -11,12 +11,28 @@ namespace YooAsset.Editor
{
internal class DebuggerBundleListViewer
{
private class BundleTableData : DefaultTableData
{
public DebugPackageData PackageData;
public DebugBundleInfo BundleInfo;
}
private class UsingTableData : DefaultTableData
{
public DebugProviderInfo ProviderInfo;
}
private class ReferenceTableData : DefaultTableData
{
public DebugBundleInfo BundleInfo;
}
private VisualTreeAsset _visualAsset;
private TemplateContainer _root;
private ListView _bundleListView;
private ListView _usingListView;
private DebugReport _debugReport;
private TableViewer _bundleTableView;
private TableViewer _usingTableView;
private TableViewer _referenceTableView;
private List<ITableData> _sourceDatas;
/// <summary>
/// 初始化页面
@@ -32,23 +48,342 @@ namespace YooAsset.Editor
_root.style.flexGrow = 1f;
// 资源包列表
_bundleListView = _root.Q<ListView>("TopListView");
_bundleListView.makeItem = MakeBundleListViewItem;
_bundleListView.bindItem = BindBundleListViewItem;
#if UNITY_2020_1_OR_NEWER
_bundleListView.onSelectionChange += BundleListView_onSelectionChange;
#else
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
#endif
_bundleTableView = _root.Q<TableViewer>("BundleTableView");
_bundleTableView.SelectionChangedEvent = OnBundleTableViewSelectionChanged;
CreateBundleTableViewColumns();
// 使用列表
_usingListView = _root.Q<ListView>("BottomListView");
_usingListView.makeItem = MakeIncludeListViewItem;
_usingListView.bindItem = BindIncludeListViewItem;
_usingTableView = _root.Q<TableViewer>("UsingTableView");
CreateUsingTableViewColumns();
#if UNITY_2020_3_OR_NEWER
SplitView.Adjuster(_root);
#endif
// 引用列表
_referenceTableView = _root.Q<TableViewer>("ReferenceTableView");
CreateReferenceTableViewColumns();
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
UIElementsTools.SplitVerticalPanel(bottomGroup, _usingTableView, _referenceTableView);
}
private void CreateBundleTableViewColumns()
{
// PackageName
{
var columnStyle = new ColumnStyle(200);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("PackageName", "Package Name", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_bundleTableView.AddColumn(column);
}
// BundleName
{
var columnStyle = new ColumnStyle(600, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("BundleName", "Bundle Name", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_bundleTableView.AddColumn(column);
}
// RefCount
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("RefCount", "Ref Count", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_bundleTableView.AddColumn(column);
}
// Status
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("Status", "Status", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
StyleColor textColor;
var bundleTableData = data as BundleTableData;
if (bundleTableData.BundleInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = new StyleColor(Color.white);
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
infoLabel.style.color = textColor;
};
_bundleTableView.AddColumn(column);
}
}
private void CreateUsingTableViewColumns()
{
// UsingAssets
{
var columnStyle = new ColumnStyle(600, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("UsingAssets", "Using Assets", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_usingTableView.AddColumn(column);
}
// SpawnScene
{
var columnStyle = new ColumnStyle(150);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("SpawnScene", "Spawn Scene", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_usingTableView.AddColumn(column);
}
// BeginTime
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("BeginTime", "Begin Time", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_usingTableView.AddColumn(column);
}
// RefCount
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("RefCount", "Ref Count", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_usingTableView.AddColumn(column);
}
// Status
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("Status", "Status", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
StyleColor textColor;
var usingTableData = data as UsingTableData;
if (usingTableData.ProviderInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = new StyleColor(Color.white);
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
infoLabel.style.color = textColor;
};
_usingTableView.AddColumn(column);
}
}
private void CreateReferenceTableViewColumns()
{
// BundleName
{
var columnStyle = new ColumnStyle(600, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("ReferenceBundle", "Reference Bundle", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_referenceTableView.AddColumn(column);
}
// RefCount
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("RefCount", "Ref Count", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_referenceTableView.AddColumn(column);
}
// Status
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("Status", "Status", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
StyleColor textColor;
var feferenceTableData = data as ReferenceTableData;
if (feferenceTableData.BundleInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = new StyleColor(Color.white);
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
infoLabel.style.color = textColor;
};
_referenceTableView.AddColumn(column);
}
}
/// <summary>
/// 填充页面数据
/// </summary>
public void FillViewData(DebugReport debugReport)
{
// 清空旧数据
_bundleTableView.ClearAll(false, true);
_usingTableView.ClearAll(false, true);
_referenceTableView.ClearAll(false, true);
// 填充数据源
_sourceDatas = new List<ITableData>(1000);
foreach (var packageData in debugReport.PackageDatas)
{
foreach (var bundleInfo in packageData.BundleInfos)
{
var rowData = new BundleTableData();
rowData.PackageData = packageData;
rowData.BundleInfo = bundleInfo;
rowData.AddAssetPathCell("PackageName", packageData.PackageName);
rowData.AddStringValueCell("BundleName", bundleInfo.BundleName);
rowData.AddLongValueCell("RefCount", bundleInfo.RefCount);
rowData.AddStringValueCell("Status", bundleInfo.Status.ToString());
_sourceDatas.Add(rowData);
}
}
_bundleTableView.itemsSource = _sourceDatas;
// 重建视图
RebuildView(null);
}
/// <summary>
@@ -56,53 +391,29 @@ namespace YooAsset.Editor
/// </summary>
public void ClearView()
{
_debugReport = null;
_bundleListView.Clear();
_bundleListView.ClearSelection();
_bundleListView.itemsSource.Clear();
_bundleListView.Rebuild();
_bundleTableView.ClearAll(false, true);
_bundleTableView.RebuildView();
_usingTableView.ClearAll(false, true);
_usingTableView.RebuildView();
_referenceTableView.ClearAll(false, true);
_referenceTableView.RebuildView();
}
/// <summary>
/// 填充页面数据
/// 重建视图
/// </summary>
public void FillViewData(DebugReport debugReport, string searchKeyWord)
public void RebuildView(string searchKeyWord)
{
_debugReport = debugReport;
_bundleListView.Clear();
_bundleListView.ClearSelection();
_bundleListView.itemsSource = FilterViewItems(debugReport, searchKeyWord);
_bundleListView.Rebuild();
}
private List<DebugBundleInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
{
List<DebugBundleInfo> result = new List<DebugBundleInfo>(1000);
foreach (var pakcageData in debugReport.PackageDatas)
{
Dictionary<string, DebugBundleInfo> tempDic = new Dictionary<string, DebugBundleInfo>(1000);
foreach (var providerInfo in pakcageData.ProviderInfos)
{
foreach (var bundleInfo in providerInfo.DependBundleInfos)
{
if (string.IsNullOrEmpty(searchKeyWord) == false)
{
if (bundleInfo.BundleName.Contains(searchKeyWord) == false)
continue;
}
// 搜索匹配
if(_sourceDatas != null)
DefaultSearchSystem.Search(_sourceDatas, searchKeyWord);
if (tempDic.ContainsKey(bundleInfo.BundleName) == false)
{
bundleInfo.PackageName = pakcageData.PackageName;
tempDic.Add(bundleInfo.BundleName, bundleInfo);
}
}
}
var tempList = tempDic.Values.ToList();
tempList.Sort();
result.AddRange(tempList);
}
return result;
// 重建视图
_bundleTableView.RebuildView();
_usingTableView.RebuildView();
_referenceTableView.RebuildView();
}
/// <summary>
@@ -121,199 +432,53 @@ namespace YooAsset.Editor
_root.RemoveFromHierarchy();
}
// 顶部列表相关
private VisualElement MakeBundleListViewItem()
private void OnBundleTableViewSelectionChanged(ITableData data)
{
VisualElement element = new VisualElement();
element.style.flexDirection = FlexDirection.Row;
var bundleTableData = data as BundleTableData;
var packageData = bundleTableData.PackageData;
var selectBundleInfo = bundleTableData.BundleInfo;
// 填充UsingTableView
{
var label = new Label();
label.name = "Label0";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
}
{
var label = new Label();
label.name = "Label3";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}
{
var label = new Label();
label.name = "Label4";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 120;
element.Add(label);
}
return element;
}
private void BindBundleListViewItem(VisualElement element, int index)
{
var sourceData = _bundleListView.itemsSource as List<DebugBundleInfo>;
var bundleInfo = sourceData[index];
// Package Name
var label0 = element.Q<Label>("Label0");
label0.text = bundleInfo.PackageName;
// Bundle Name
var label1 = element.Q<Label>("Label1");
label1.text = bundleInfo.BundleName;
// Ref Count
var label3 = element.Q<Label>("Label3");
label3.text = bundleInfo.RefCount.ToString();
// Status
StyleColor textColor;
if (bundleInfo.Status == EOperationStatus.Failed)
textColor = new StyleColor(Color.yellow);
else
textColor = label1.style.color;
var label4 = element.Q<Label>("Label4");
label4.text = bundleInfo.Status.ToString();
label4.style.color = textColor;
}
private void BundleListView_onSelectionChange(IEnumerable<object> objs)
{
foreach (var item in objs)
{
DebugBundleInfo bundleInfo = item as DebugBundleInfo;
FillUsingListView(bundleInfo);
}
}
// 底部列表相关
private VisualElement MakeIncludeListViewItem()
{
VisualElement element = new VisualElement();
element.style.flexDirection = FlexDirection.Row;
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
}
{
var label = new Label();
label.name = "Label2";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
{
var label = new Label();
label.name = "Label3";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
{
var label = new Label();
label.name = "Label4";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}
{
var label = new Label();
label.name = "Label5";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 120;
element.Add(label);
}
return element;
}
private void BindIncludeListViewItem(VisualElement element, int index)
{
List<DebugProviderInfo> providers = _usingListView.itemsSource as List<DebugProviderInfo>;
DebugProviderInfo providerInfo = providers[index];
// Asset Path
var label1 = element.Q<Label>("Label1");
label1.text = providerInfo.AssetPath;
// Spawn Scene
var label2 = element.Q<Label>("Label2");
label2.text = providerInfo.SpawnScene;
// Spawn Time
var label3 = element.Q<Label>("Label3");
label3.text = providerInfo.SpawnTime;
// Ref Count
var label4 = element.Q<Label>("Label4");
label4.text = providerInfo.RefCount.ToString();
// Status
var label5 = element.Q<Label>("Label5");
label5.text = providerInfo.Status.ToString();
}
private void FillUsingListView(DebugBundleInfo selectedBundleInfo)
{
List<DebugProviderInfo> source = new List<DebugProviderInfo>();
foreach (var packageData in _debugReport.PackageDatas)
{
if (packageData.PackageName == selectedBundleInfo.PackageName)
var sourceDatas = new List<ITableData>(1000);
foreach (var providerInfo in packageData.ProviderInfos)
{
foreach (var providerInfo in packageData.ProviderInfos)
foreach (var dependBundleName in providerInfo.DependBundles)
{
foreach (var bundleInfo in providerInfo.DependBundleInfos)
if (dependBundleName == selectBundleInfo.BundleName)
{
if (bundleInfo.BundleName == selectedBundleInfo.BundleName)
{
source.Add(providerInfo);
continue;
}
var rowData = new UsingTableData();
rowData.ProviderInfo = providerInfo;
rowData.AddStringValueCell("UsingAssets", providerInfo.AssetPath);
rowData.AddStringValueCell("SpawnScene", providerInfo.SpawnScene);
rowData.AddStringValueCell("BeginTime", providerInfo.BeginTime);
rowData.AddLongValueCell("RefCount", providerInfo.RefCount);
rowData.AddStringValueCell("Status", providerInfo.Status);
sourceDatas.Add(rowData);
break;
}
}
}
_usingTableView.itemsSource = sourceDatas;
_usingTableView.RebuildView();
}
_usingListView.Clear();
_usingListView.ClearSelection();
_usingListView.itemsSource = source;
_usingListView.Rebuild();
// 填充ReferenceTableView
{
var sourceDatas = new List<ITableData>(1000);
foreach (string referenceBundleName in selectBundleInfo.ReferenceBundles)
{
var bundleInfo = packageData.GetBundleInfo(referenceBundleName);
var rowData = new ReferenceTableData();
rowData.BundleInfo = bundleInfo;
rowData.AddStringValueCell("BundleName", bundleInfo.BundleName);
rowData.AddLongValueCell("RefCount", bundleInfo.RefCount);
rowData.AddStringValueCell("Status", bundleInfo.Status.ToString());
sourceDatas.Add(rowData);
}
_referenceTableView.itemsSource = sourceDatas;
_referenceTableView.RebuildView();
}
}
}
}

View File

@@ -1,21 +1,9 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Package Name" display-tooltip-when-elided="true" name="TopBar0" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar3" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar4" style="width: 120px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<YooAsset.Editor.TableViewer name="BundleTableView" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Using Assets" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Spawn Scene" display-tooltip-when-elided="true" name="BottomBar2" style="width: 150px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Spawn Time" display-tooltip-when-elided="true" name="BottomBar3" style="width: 150px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="BottomBar4" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="BottomBar5" style="width: 120px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:VisualElement name="BottomGroup" style="height: 400px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<YooAsset.Editor.TableViewer name="UsingTableView" />
<YooAsset.Editor.TableViewer name="ReferenceTableView" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,509 @@
#if UNITY_2019_4_OR_NEWER
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
internal class DebuggerOperationListViewer
{
private class OperationTableData : DefaultTableData
{
public DebugPackageData PackageData;
public DebugOperationInfo OperationInfo;
}
private VisualTreeAsset _visualAsset;
private TemplateContainer _root;
private TableViewer _operationTableView;
private Toolbar _bottomToolbar;
private TreeViewer _childTreeView;
private List<ITableData> _sourceDatas;
/// <summary>
/// 初始化页面
/// </summary>
public void InitViewer()
{
// 加载布局文件
_visualAsset = UxmlLoader.LoadWindowUXML<DebuggerOperationListViewer>();
if (_visualAsset == null)
return;
_root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f;
// 任务列表
_operationTableView = _root.Q<TableViewer>("TopTableView");
_operationTableView.SelectionChangedEvent = OnOperationTableViewSelectionChanged;
CreateOperationTableViewColumns();
// 底部标题栏
_bottomToolbar = _root.Q<Toolbar>("BottomToolbar");
CreateBottomToolbarHeaders();
// 子列表
_childTreeView = _root.Q<TreeViewer>("BottomTreeView");
_childTreeView.makeItem = MakeTreeViewItem;
_childTreeView.bindItem = BindTreeViewItem;
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
}
private void CreateOperationTableViewColumns()
{
// PackageName
{
var columnStyle = new ColumnStyle(200);
columnStyle.Searchable = true;
columnStyle.Sortable = true;
var column = new TableColumn("PackageName", "Package Name", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// OperationName
{
var columnStyle = new ColumnStyle(300, 300, 600);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("OperationName", "Operation Name", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// Priority
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("Priority", "Priority", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// Progress
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = false;
var column = new TableColumn("Progress", "Progress", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// BeginTime
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("BeginTime", "Begin Time", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// ProcessTime
{
var columnStyle = new ColumnStyle(130);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
columnStyle.Units = "ms";
var column = new TableColumn("ProcessTime", "Process Time", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
// Status
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("Status", "Status", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
StyleColor textColor;
var operationTableData = data as OperationTableData;
if (operationTableData.OperationInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = new StyleColor(Color.white);
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
infoLabel.style.color = textColor;
};
_operationTableView.AddColumn(column);
}
// Desc
{
var columnStyle = new ColumnStyle(500, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
var column = new TableColumn("Desc", "Desc", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
}
private void CreateBottomToolbarHeaders()
{
// OperationName
{
ToolbarButton button = new ToolbarButton();
button.text = "OperationName";
button.style.flexGrow = 0;
button.style.width = 315;
_bottomToolbar.Add(button);
}
// Progress
{
ToolbarButton button = new ToolbarButton();
button.text = "Progress";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// BeginTime
{
ToolbarButton button = new ToolbarButton();
button.text = "BeginTime";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// ProcessTime
{
ToolbarButton button = new ToolbarButton();
button.text = "ProcessTime (ms)";
button.style.flexGrow = 0;
button.style.width = 130;
_bottomToolbar.Add(button);
}
// Status
{
ToolbarButton button = new ToolbarButton();
button.text = "Status";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// Desc
{
ToolbarButton button = new ToolbarButton();
button.text = "Desc";
button.style.flexGrow = 0;
button.style.width = 500;
_bottomToolbar.Add(button);
}
}
/// <summary>
/// 填充页面数据
/// </summary>
public void FillViewData(DebugReport debugReport)
{
// 清空旧数据
_operationTableView.ClearAll(false, true);
_childTreeView.ClearAll();
_childTreeView.RebuildView();
// 填充数据源
_sourceDatas = new List<ITableData>(1000);
foreach (var packageData in debugReport.PackageDatas)
{
foreach (var operationInfo in packageData.OperationInfos)
{
var rowData = new OperationTableData();
rowData.PackageData = packageData;
rowData.OperationInfo = operationInfo;
rowData.AddStringValueCell("PackageName", packageData.PackageName);
rowData.AddStringValueCell("OperationName", operationInfo.OperationName);
rowData.AddLongValueCell("Priority", operationInfo.Priority);
rowData.AddDoubleValueCell("Progress", operationInfo.Progress);
rowData.AddStringValueCell("BeginTime", operationInfo.BeginTime);
rowData.AddLongValueCell("LoadingTime", operationInfo.ProcessTime);
rowData.AddStringValueCell("Status", operationInfo.Status.ToString());
rowData.AddStringValueCell("Desc", operationInfo.OperationDesc);
_sourceDatas.Add(rowData);
}
}
_operationTableView.itemsSource = _sourceDatas;
// 重建视图
RebuildView(null);
}
/// <summary>
/// 清空页面
/// </summary>
public void ClearView()
{
_operationTableView.ClearAll(false, true);
_operationTableView.RebuildView();
_childTreeView.ClearAll();
_childTreeView.RebuildView();
}
/// <summary>
/// 重建视图
/// </summary>
public void RebuildView(string searchKeyWord)
{
// 搜索匹配
if(_sourceDatas != null)
DefaultSearchSystem.Search(_sourceDatas, searchKeyWord);
// 重建视图
_operationTableView.RebuildView();
_childTreeView.RebuildView();
}
/// <summary>
/// 挂接到父类页面上
/// </summary>
public void AttachParent(VisualElement parent)
{
parent.Add(_root);
}
/// <summary>
/// 从父类页面脱离开
/// </summary>
public void DetachParent()
{
_root.RemoveFromHierarchy();
}
private void OnOperationTableViewSelectionChanged(ITableData data)
{
var operationTableData = data as OperationTableData;
DebugPackageData packageData = operationTableData.PackageData;
DebugOperationInfo operationInfo = operationTableData.OperationInfo;
TreeNode rootNode = new TreeNode(operationInfo);
FillTreeData(operationInfo, rootNode);
_childTreeView.ClearAll();
_childTreeView.SetRootItem(rootNode);
_childTreeView.RebuildView();
}
private void MakeTreeViewItem(VisualElement container)
{
// OperationName
{
Label label = new Label();
label.name = "OperationName";
label.style.flexGrow = 0f;
label.style.width = 300;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
// Progress
{
var label = new Label();
label.name = "Progress";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
// BeginTime
{
var label = new Label();
label.name = "BeginTime";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
// ProcessTime
{
var label = new Label();
label.name = "ProcessTime";
label.style.flexGrow = 0f;
label.style.width = 130;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
// Status
{
var label = new Label();
label.name = "Status";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
// Desc
{
Label label = new Label();
label.name = "Desc";
label.style.flexGrow = 1f;
label.style.width = 500;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
}
}
private void BindTreeViewItem(VisualElement container, object userData)
{
var operationInfo = (DebugOperationInfo)userData;
// OperationName
{
var label = container.Q<Label>("OperationName");
label.text = operationInfo.OperationName;
}
// Progress
{
var label = container.Q<Label>("Progress");
label.text = operationInfo.Progress.ToString();
}
// BeginTime
{
var label = container.Q<Label>("BeginTime");
label.text = operationInfo.BeginTime;
}
// ProcessTime
{
var label = container.Q<Label>("ProcessTime");
label.text = operationInfo.ProcessTime.ToString();
}
// Status
{
StyleColor textColor;
if (operationInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = new StyleColor(Color.white);
var label = container.Q<Label>("Status");
label.text = operationInfo.Status;
label.style.color = textColor;
}
// Desc
{
var label = container.Q<Label>("Desc");
label.text = operationInfo.OperationDesc;
}
}
private void FillTreeData(DebugOperationInfo parentOperation, TreeNode rootNode)
{
foreach (var childOperation in parentOperation.Childs)
{
var childNode = new TreeNode(childOperation);
rootNode.AddChild(childNode);
FillTreeData(childOperation, childNode);
}
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,9 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
<YooAsset.Editor.TableViewer name="TopTableView" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="flex-grow: 1;">
<uie:Toolbar name="BottomToolbar" />
<YooAsset.Editor.TreeViewer name="BottomTreeView" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 7147c7108cba1bb4dba3a2cfc758ad43
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -112,16 +112,16 @@ namespace YooAsset.Editor
string jsonData = FileUtility.ReadAllText(_reportFilePath);
_buildReport = BuildReport.Deserialize(jsonData);
_summaryViewer.FillViewData(_buildReport);
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
_assetListViewer.FillViewData(_buildReport, _reportFilePath);
_bundleListViewer.FillViewData(_buildReport, _reportFilePath);
}
private void OnSearchKeyWordChange(ChangeEvent<string> e)
{
_searchKeyWord = e.newValue;
if (_buildReport != null)
{
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
_assetListViewer.RebuildView(_searchKeyWord);
_bundleListViewer.RebuildView(_searchKeyWord);
}
}
private void ViewModeMenuAction0(DropdownMenuAction action)

View File

@@ -39,8 +39,14 @@ namespace YooAsset.Editor
public long MainBundleSize;
/// <summary>
/// 依赖的资源路径列表
/// 依赖的资源集合
/// </summary>
public List<string> DependAssets = new List<string>();
public List<AssetInfo> DependAssets = new List<AssetInfo>();
/// <summary>
/// 依赖的资源包集合
/// 说明:框架层收集查询结果
/// </summary>
public List<string> DependBundles = new List<string>();
}
}

View File

@@ -44,14 +44,21 @@ namespace YooAsset.Editor
public string[] Tags;
/// <summary>
/// 资源包的依赖集合
/// 依赖的资源包集合
/// 说明:引擎层构建查询结果
/// </summary>
public List<string> DependBundles;
public List<string> DependBundles = new List<string>();
/// <summary>
/// 该资源包内包含的所有资源
/// 引用该资源包的资源包集合
/// 说明:谁依赖该资源包
/// </summary>
public List<string> AllBuiltinAssets = new List<string>();
public List<string> ReferenceBundles = new List<string>();
/// <summary>
/// 资源包内部所有资产
/// </summary>
public List<AssetInfo> BundleContents = new List<AssetInfo>();
/// <summary>
/// 获取资源分类标签的字符串

View File

@@ -38,6 +38,11 @@ namespace YooAsset.Editor
/// </summary>
public string BuildPipeline;
/// <summary>
/// 构建的资源包类型
/// </summary>
public int BuildBundleType;
/// <summary>
/// 构建包裹名称
/// </summary>
@@ -65,11 +70,19 @@ namespace YooAsset.Editor
public bool ClearBuildCacheFiles;
public bool UseAssetDependencyDB;
public bool EnableSharePackRule;
public bool SingleReferencedPackAlone;
public string EncryptionClassName;
public EFileNameStyle FileNameStyle;
// 引擎参数
public ECompressOption CompressOption;
public bool DisableWriteTypeTree;
public bool IgnoreTypeTreeChanges;
public bool WriteLinkXML = true;
public string CacheServerHost;
public int CacheServerPort;
public string BuiltinShadersBundleName;
public string MonoScriptsBundleName;
// 构建结果
public int AssetFileTotalCount;

View File

@@ -6,30 +6,30 @@ using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
using System.IO;
namespace YooAsset.Editor
{
internal class ReporterAssetListViewer
{
private enum ESortMode
private class AssetTableData : DefaultTableData
{
AssetPath,
BundleName
public ReportAssetInfo AssetInfo;
}
private class DependTableData : DefaultTableData
{
public ReportBundleInfo BundleInfo;
}
private VisualTreeAsset _visualAsset;
private TemplateContainer _root;
private ToolbarButton _topBar1;
private ToolbarButton _topBar2;
private ToolbarButton _bottomBar1;
private ListView _assetListView;
private ListView _dependListView;
private TableViewer _assetTableView;
private TableViewer _dependTableView;
private BuildReport _buildReport;
private string _searchKeyWord;
private ESortMode _sortMode = ESortMode.AssetPath;
private bool _descendingSort = false;
private string _reportFilePath;
private List<ITableData> _sourceDatas;
/// <summary>
@@ -45,111 +45,175 @@ namespace YooAsset.Editor
_root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f;
// 顶部按钮栏
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
_topBar1.clicked += TopBar1_clicked;
_topBar2.clicked += TopBar2_clicked;
// 底部按钮栏
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
// 资源列表
_assetListView = _root.Q<ListView>("TopListView");
_assetListView.makeItem = MakeAssetListViewItem;
_assetListView.bindItem = BindAssetListViewItem;
#if UNITY_2020_1_OR_NEWER
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
#else
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
#endif
_assetTableView = _root.Q<TableViewer>("TopTableView");
_assetTableView.SelectionChangedEvent = OnAssetTableViewSelectionChanged;
_assetTableView.ClickTableDataEvent = OnClickAssetTableView;
CreateAssetTableViewColumns();
// 依赖列表
_dependListView = _root.Q<ListView>("BottomListView");
_dependListView.makeItem = MakeDependListViewItem;
_dependListView.bindItem = BindDependListViewItem;
_dependTableView = _root.Q<TableViewer>("BottomTableView");
_dependTableView.ClickTableDataEvent = OnClickBundleTableView;
CreateDependTableViewColumns();
#if UNITY_2020_3_OR_NEWER
SplitView.Adjuster(_root);
#endif
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
}
private void CreateAssetTableViewColumns()
{
// AssetPath
{
var columnStyle = new ColumnStyle(600, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("AssetPath", "Asset Path", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_assetTableView.AddColumn(column);
}
//MainBundle
{
var columnStyle = new ColumnStyle(600, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
var column = new TableColumn("MainBundle", "Main Bundle", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_assetTableView.AddColumn(column);
}
}
private void CreateDependTableViewColumns()
{
// DependBundles
{
var columnStyle = new ColumnStyle(600, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("DependBundles", "Depend Bundles", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_dependTableView.AddColumn(column);
}
// FileSize
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("FileSize", "File Size", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
long fileSize = (long)cell.CellValue;
infoLabel.text = EditorUtility.FormatBytes(fileSize);
};
_dependTableView.AddColumn(column);
}
// FileHash
{
var columnStyle = new ColumnStyle(250);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = false;
var column = new TableColumn("FileHash", "File Hash", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_dependTableView.AddColumn(column);
}
}
/// <summary>
/// 填充页面数据
/// </summary>
public void FillViewData(BuildReport buildReport, string searchKeyWord)
public void FillViewData(BuildReport buildReport, string reprotFilePath)
{
_buildReport = buildReport;
_searchKeyWord = searchKeyWord;
RefreshView();
}
private void RefreshView()
{
_assetListView.Clear();
_assetListView.ClearSelection();
_assetListView.itemsSource = FilterAndSortViewItems();
_assetListView.Rebuild();
RefreshSortingSymbol();
}
private List<ReportAssetInfo> FilterAndSortViewItems()
{
List<ReportAssetInfo> result = new List<ReportAssetInfo>(_buildReport.AssetInfos.Count);
_reportFilePath = reprotFilePath;
// 过滤列表
// 清空旧数据
_assetTableView.ClearAll(false, true);
_dependTableView.ClearAll(false, true);
// 填充数据源
_sourceDatas = new List<ITableData>(_buildReport.AssetInfos.Count);
foreach (var assetInfo in _buildReport.AssetInfos)
{
if (string.IsNullOrEmpty(_searchKeyWord) == false)
{
if (assetInfo.AssetPath.Contains(_searchKeyWord) == false)
continue;
}
result.Add(assetInfo);
var rowData = new AssetTableData();
rowData.AssetInfo = assetInfo;
rowData.AddAssetPathCell("AssetPath", assetInfo.AssetPath);
rowData.AddStringValueCell("MainBundle", assetInfo.MainBundleName);
_sourceDatas.Add(rowData);
}
_assetTableView.itemsSource = _sourceDatas;
// 排序列表
if (_sortMode == ESortMode.AssetPath)
{
if (_descendingSort)
return result.OrderByDescending(a => a.AssetPath).ToList();
else
return result.OrderBy(a => a.AssetPath).ToList();
}
else if (_sortMode == ESortMode.BundleName)
{
if (_descendingSort)
return result.OrderByDescending(a => a.MainBundleName).ToList();
else
return result.OrderBy(a => a.MainBundleName).ToList();
}
else
{
throw new System.NotImplementedException();
}
// 重建视图
RebuildView(null);
}
private void RefreshSortingSymbol()
{
// 刷新符号
_topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count})";
_topBar2.text = "Main Bundle";
if (_sortMode == ESortMode.AssetPath)
{
if (_descendingSort)
_topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count}) ↓";
else
_topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count}) ↑";
}
else if (_sortMode == ESortMode.BundleName)
{
if (_descendingSort)
_topBar2.text = "Main Bundle ↓";
else
_topBar2.text = "Main Bundle ↑";
}
else
{
throw new System.NotImplementedException();
}
/// <summary>
/// 重建视图
/// </summary>
public void RebuildView(string searchKeyWord)
{
// 搜索匹配
DefaultSearchSystem.Search(_sourceDatas, searchKeyWord);
// 重建视图
_assetTableView.RebuildView();
}
/// <summary>
@@ -168,157 +232,61 @@ namespace YooAsset.Editor
_root.RemoveFromHierarchy();
}
// 资源列表相关
private VisualElement MakeAssetListViewItem()
private void OnAssetTableViewSelectionChanged(ITableData data)
{
VisualElement element = new VisualElement();
element.style.flexDirection = FlexDirection.Row;
var assetTableData = data as AssetTableData;
ReportAssetInfo assetInfo = assetTableData.AssetInfo;
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
}
{
var label = new Label();
label.name = "Label2";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
return element;
}
private void BindAssetListViewItem(VisualElement element, int index)
{
var sourceData = _assetListView.itemsSource as List<ReportAssetInfo>;
var assetInfo = sourceData[index];
var bundleInfo = _buildReport.GetBundleInfo(assetInfo.MainBundleName);
// Asset Path
var label1 = element.Q<Label>("Label1");
label1.text = assetInfo.AssetPath;
// Main Bundle
var label2 = element.Q<Label>("Label2");
label2.text = bundleInfo.BundleName;
}
private void AssetListView_onSelectionChange(IEnumerable<object> objs)
{
foreach (var item in objs)
{
ReportAssetInfo assetInfo = item as ReportAssetInfo;
FillDependListView(assetInfo);
}
}
private void TopBar1_clicked()
{
if (_sortMode != ESortMode.AssetPath)
{
_sortMode = ESortMode.AssetPath;
_descendingSort = false;
RefreshView();
}
else
{
_descendingSort = !_descendingSort;
RefreshView();
}
}
private void TopBar2_clicked()
{
if (_sortMode != ESortMode.BundleName)
{
_sortMode = ESortMode.BundleName;
_descendingSort = false;
RefreshView();
}
else
{
_descendingSort = !_descendingSort;
RefreshView();
}
}
// 依赖列表相关
private void FillDependListView(ReportAssetInfo assetInfo)
{
List<ReportBundleInfo> bundles = new List<ReportBundleInfo>();
// 填充依赖数据
var mainBundle = _buildReport.GetBundleInfo(assetInfo.MainBundleName);
bundles.Add(mainBundle);
var sourceDatas = new List<ITableData>(mainBundle.DependBundles.Count);
foreach (string dependBundleName in mainBundle.DependBundles)
{
var dependBundle = _buildReport.GetBundleInfo(dependBundleName);
bundles.Add(dependBundle);
var rowData = new DependTableData();
rowData.BundleInfo = dependBundle;
rowData.AddStringValueCell("DependBundles", dependBundle.BundleName);
rowData.AddLongValueCell("FileSize", dependBundle.FileSize);
rowData.AddStringValueCell("FileHash", dependBundle.FileHash);
sourceDatas.Add(rowData);
}
_dependListView.Clear();
_dependListView.ClearSelection();
_dependListView.itemsSource = bundles;
_dependListView.Rebuild();
_bottomBar1.text = $"Depend Bundles ({bundles.Count})";
_dependTableView.itemsSource = sourceDatas;
_dependTableView.RebuildView();
}
private VisualElement MakeDependListViewItem()
private void OnClickAssetTableView(PointerDownEvent evt, ITableData data)
{
VisualElement element = new VisualElement();
element.style.flexDirection = FlexDirection.Row;
// 鼠标双击后检视
if (evt.clickCount != 2)
return;
foreach (var cell in data.Cells)
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
if (cell is AssetPathCell assetPathCell)
{
if (assetPathCell.PingAssetObject())
break;
}
}
{
var label = new Label();
label.name = "Label2";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}
{
var label = new Label();
label.name = "Label3";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
}
return element;
}
private void BindDependListViewItem(VisualElement element, int index)
private void OnClickBundleTableView(PointerDownEvent evt, ITableData data)
{
List<ReportBundleInfo> bundles = _dependListView.itemsSource as List<ReportBundleInfo>;
ReportBundleInfo bundleInfo = bundles[index];
// 鼠标双击后检视
if (evt.clickCount != 2)
return;
// Bundle Name
var label1 = element.Q<Label>("Label1");
label1.text = bundleInfo.BundleName;
var dependTableData = data as DependTableData;
if (dependTableData.BundleInfo.Encrypted)
return;
// Size
var label2 = element.Q<Label>("Label2");
label2.text = EditorUtility.FormatBytes(bundleInfo.FileSize);
// Hash
var label3 = element.Q<Label>("Label3");
label3.text = bundleInfo.FileHash;
if (_buildReport.Summary.BuildBundleType == (int)EBuildBundleType.AssetBundle)
{
string rootDirectory = Path.GetDirectoryName(_reportFilePath);
string filePath = $"{rootDirectory}/{dependTableData.BundleInfo.FileName}";
if (File.Exists(filePath))
Selection.activeObject = AssetBundleRecorder.GetAssetBundle(filePath);
else
Selection.activeObject = null;
}
}
}
}

View File

@@ -1,17 +1,8 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Asset Path" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Main Bundle" display-tooltip-when-elided="true" name="TopBar2" style="width: 145px; -unity-text-align: middle-left; flex-grow: 1;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1; flex-basis: 60px;" />
<YooAsset.Editor.TableViewer name="TopTableView" style="flex-grow: 1;" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Depend Bundles" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="File Size" display-tooltip-when-elided="true" name="BottomBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="File Hash" display-tooltip-when-elided="true" name="BottomBar3" style="width: 280px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex; flex-grow: 1;">
<YooAsset.Editor.TableViewer name="BottomTableView" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -12,29 +12,25 @@ namespace YooAsset.Editor
{
internal class ReporterBundleListViewer
{
private enum ESortMode
private class BundleTableData : DefaultTableData
{
BundleName,
BundleSize,
BundleTags
public ReportBundleInfo BundleInfo;
}
private class IncludeTableData : DefaultTableData
{
public ReportAssetInfo AssetInfo;
}
private VisualTreeAsset _visualAsset;
private TemplateContainer _root;
private ToolbarButton _topBar1;
private ToolbarButton _topBar2;
private ToolbarButton _topBar3;
private ToolbarButton _topBar5;
private ToolbarButton _bottomBar1;
private ListView _bundleListView;
private ListView _includeListView;
private TableViewer _bundleTableView;
private TableViewer _includeTableView;
private BuildReport _buildReport;
private string _reportFilePath;
private string _searchKeyWord;
private ESortMode _sortMode = ESortMode.BundleName;
private bool _descendingSort = false;
private List<ITableData> _sourceDatas;
/// <summary>
/// 初始化页面
@@ -49,132 +45,243 @@ namespace YooAsset.Editor
_root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f;
// 顶部按钮栏
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
_topBar3 = _root.Q<ToolbarButton>("TopBar3");
_topBar5 = _root.Q<ToolbarButton>("TopBar5");
_topBar1.clicked += TopBar1_clicked;
_topBar2.clicked += TopBar2_clicked;
_topBar3.clicked += TopBar3_clicked;
_topBar5.clicked += TopBar4_clicked;
// 底部按钮栏
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
// 资源包列表
_bundleListView = _root.Q<ListView>("TopListView");
_bundleListView.makeItem = MakeBundleListViewItem;
_bundleListView.bindItem = BindBundleListViewItem;
#if UNITY_2020_1_OR_NEWER
_bundleListView.onSelectionChange += BundleListView_onSelectionChange;
#else
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
#endif
_bundleTableView = _root.Q<TableViewer>("TopTableView");
_bundleTableView.ClickTableDataEvent = OnClickBundleTableView;
_bundleTableView.SelectionChangedEvent = OnBundleTableViewSelectionChanged;
CreateBundleTableViewColumns();
// 包含列表
_includeListView = _root.Q<ListView>("BottomListView");
_includeListView.makeItem = MakeIncludeListViewItem;
_includeListView.bindItem = BindIncludeListViewItem;
_includeTableView = _root.Q<TableViewer>("BottomTableView");
_includeTableView.ClickTableDataEvent = OnClickIncludeTableView;
CreateIncludeTableViewColumns();
#if UNITY_2020_3_OR_NEWER
SplitView.Adjuster(_root);
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
#endif
}
private void CreateBundleTableViewColumns()
{
//BundleName
{
var columnStyle = new ColumnStyle(600, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("BundleName", "Bundle Name", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_bundleTableView.AddColumn(column);
}
// FileSize
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
var column = new TableColumn("FileSize", "File Size", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
long fileSize = (long)cell.CellValue;
infoLabel.text = EditorUtility.FormatBytes(fileSize);
};
_bundleTableView.AddColumn(column);
}
// FileHash
{
var columnStyle = new ColumnStyle(250);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = false;
var column = new TableColumn("FileHash", "File Hash", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_bundleTableView.AddColumn(column);
}
//Encrypted
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("Encrypted", "Encrypted", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
bool encrypted = (bool)cell.CellValue;
infoLabel.text = encrypted.ToString();
};
_bundleTableView.AddColumn(column);
}
//Tags
{
var columnStyle = new ColumnStyle(150, 100, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
var column = new TableColumn("Tags", "Tags", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_bundleTableView.AddColumn(column);
}
}
private void CreateIncludeTableViewColumns()
{
//IncludeAssets
{
var columnStyle = new ColumnStyle(600, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("IncludeAssets", "Include Assets", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_includeTableView.AddColumn(column);
}
//AssetSource
{
var columnStyle = new ColumnStyle(100);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = false;
var column = new TableColumn("AssetSource", "Asset Source", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_includeTableView.AddColumn(column);
}
//AssetGUID
{
var columnStyle = new ColumnStyle(250);
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = false;
var column = new TableColumn("AssetGUID", "Asset GUID", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_includeTableView.AddColumn(column);
}
}
/// <summary>
/// 填充页面数据
/// </summary>
public void FillViewData(BuildReport buildReport, string reprotFilePath, string searchKeyWord)
public void FillViewData(BuildReport buildReport, string reprotFilePath)
{
_buildReport = buildReport;
_reportFilePath = reprotFilePath;
_searchKeyWord = searchKeyWord;
RefreshView();
}
private void RefreshView()
{
_bundleListView.Clear();
_bundleListView.ClearSelection();
_bundleListView.itemsSource = FilterAndSortViewItems();
_bundleListView.Rebuild();
RefreshSortingSymbol();
}
private List<ReportBundleInfo> FilterAndSortViewItems()
{
List<ReportBundleInfo> result = new List<ReportBundleInfo>(_buildReport.BundleInfos.Count);
// 过滤列表
// 清空旧数据
_bundleTableView.ClearAll(false, true);
_includeTableView.ClearAll(false, true);
// 填充数据源
_sourceDatas = new List<ITableData>(_buildReport.BundleInfos.Count);
foreach (var bundleInfo in _buildReport.BundleInfos)
{
if (string.IsNullOrEmpty(_searchKeyWord) == false)
{
if (bundleInfo.BundleName.Contains(_searchKeyWord) == false)
continue;
}
result.Add(bundleInfo);
var rowData = new BundleTableData();
rowData.BundleInfo = bundleInfo;
rowData.AddStringValueCell("BundleName", bundleInfo.BundleName);
rowData.AddLongValueCell("FileSize", bundleInfo.FileSize);
rowData.AddStringValueCell("FileHash", bundleInfo.FileHash);
rowData.AddBoolValueCell("Encrypted", bundleInfo.Encrypted);
rowData.AddStringValueCell("Tags", string.Join(";", bundleInfo.Tags));
_sourceDatas.Add(rowData);
}
_bundleTableView.itemsSource = _sourceDatas;
// 排序列表
if (_sortMode == ESortMode.BundleName)
{
if (_descendingSort)
return result.OrderByDescending(a => a.BundleName).ToList();
else
return result.OrderBy(a => a.BundleName).ToList();
}
else if (_sortMode == ESortMode.BundleSize)
{
if (_descendingSort)
return result.OrderByDescending(a => a.FileSize).ToList();
else
return result.OrderBy(a => a.FileSize).ToList();
}
else if (_sortMode == ESortMode.BundleTags)
{
if (_descendingSort)
return result.OrderByDescending(a => a.GetTagsString()).ToList();
else
return result.OrderBy(a => a.GetTagsString()).ToList();
}
else
{
throw new System.NotImplementedException();
}
// 重建视图
RebuildView(null);
}
private void RefreshSortingSymbol()
{
// 刷新符号
_topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count})";
_topBar2.text = "Size";
_topBar3.text = "Hash";
_topBar5.text = "Tags";
if (_sortMode == ESortMode.BundleName)
{
if (_descendingSort)
_topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count}) ↓";
else
_topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count}) ↑";
}
else if (_sortMode == ESortMode.BundleSize)
{
if (_descendingSort)
_topBar2.text = "Size ↓";
else
_topBar2.text = "Size ↑";
}
else if (_sortMode == ESortMode.BundleTags)
{
if (_descendingSort)
_topBar5.text = "Tags ↓";
else
_topBar5.text = "Tags ↑";
}
else
{
throw new System.NotImplementedException();
}
/// <summary>
/// 重建视图
/// </summary>
public void RebuildView(string searchKeyWord)
{
// 搜索匹配
DefaultSearchSystem.Search(_sourceDatas, searchKeyWord);
// 重建视图
_bundleTableView.RebuildView();
}
/// <summary>
@@ -193,241 +300,78 @@ namespace YooAsset.Editor
_root.RemoveFromHierarchy();
}
// 顶部列表相关
private VisualElement MakeBundleListViewItem()
private void OnBundleTableViewSelectionChanged(ITableData data)
{
VisualElement element = new VisualElement();
element.style.flexDirection = FlexDirection.Row;
var bundleTableData = data as BundleTableData;
var bundleInfo = bundleTableData.BundleInfo;
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
}
{
var label = new Label();
label.name = "Label2";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}
{
var label = new Label();
label.name = "Label3";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
}
{
var label = new Label();
label.name = "Label5";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
{
var label = new Label();
label.name = "Label6";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 80;
element.Add(label);
}
return element;
}
private void BindBundleListViewItem(VisualElement element, int index)
{
var sourceData = _bundleListView.itemsSource as List<ReportBundleInfo>;
var bundleInfo = sourceData[index];
// Bundle Name
var label1 = element.Q<Label>("Label1");
label1.text = bundleInfo.BundleName;
// Size
var label2 = element.Q<Label>("Label2");
label2.text = EditorUtility.FormatBytes(bundleInfo.FileSize);
// Hash
var label3 = element.Q<Label>("Label3");
label3.text = bundleInfo.FileHash;
// Encrypted
var label5 = element.Q<Label>("Label5");
label5.text = bundleInfo.Encrypted.ToString();
// Tags
var label6 = element.Q<Label>("Label6");
label6.text = bundleInfo.GetTagsString();
}
private void BundleListView_onSelectionChange(IEnumerable<object> objs)
{
foreach (var item in objs)
{
ReportBundleInfo bundleInfo = item as ReportBundleInfo;
FillIncludeListView(bundleInfo);
ShowAssetBundleInspector(bundleInfo);
break;
}
}
private void ShowAssetBundleInspector(ReportBundleInfo bundleInfo)
{
if (_buildReport.Summary.BuildPipeline == nameof(EBuildPipeline.RawFileBuildPipeline))
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()
{
if (_sortMode != ESortMode.BundleName)
{
_sortMode = ESortMode.BundleName;
_descendingSort = false;
RefreshView();
}
else
{
_descendingSort = !_descendingSort;
RefreshView();
}
}
private void TopBar2_clicked()
{
if (_sortMode != ESortMode.BundleSize)
{
_sortMode = ESortMode.BundleSize;
_descendingSort = false;
RefreshView();
}
else
{
_descendingSort = !_descendingSort;
RefreshView();
}
}
private void TopBar3_clicked()
{
}
private void TopBar4_clicked()
{
if (_sortMode != ESortMode.BundleTags)
{
_sortMode = ESortMode.BundleTags;
_descendingSort = false;
RefreshView();
}
else
{
_descendingSort = !_descendingSort;
RefreshView();
}
}
// 底部列表相关
private void FillIncludeListView(ReportBundleInfo bundleInfo)
{
List<ReportAssetInfo> containsList = new List<ReportAssetInfo>();
HashSet<string> mainAssetDic = new HashSet<string>();
// 填充包含数据
var sourceDatas = new List<ITableData>();
var mainAssetDic = new HashSet<string>();
foreach (var assetInfo in _buildReport.AssetInfos)
{
if (assetInfo.MainBundleName == bundleInfo.BundleName)
{
mainAssetDic.Add(assetInfo.AssetPath);
containsList.Add(assetInfo);
var rowData = new IncludeTableData();
rowData.AssetInfo = assetInfo;
rowData.AddAssetPathCell("IncludeAssets", assetInfo.AssetPath);
rowData.AddStringValueCell("AssetSource", "MainAsset");
rowData.AddStringValueCell("AssetGUID", assetInfo.AssetGUID);
sourceDatas.Add(rowData);
}
}
foreach (string assetPath in bundleInfo.AllBuiltinAssets)
foreach (var assetInfo in bundleInfo.BundleContents)
{
if (mainAssetDic.Contains(assetPath) == false)
if (mainAssetDic.Contains(assetInfo.AssetPath) == false)
{
var assetInfo = new ReportAssetInfo();
assetInfo.AssetPath = assetPath;
assetInfo.AssetGUID = "--";
containsList.Add(assetInfo);
var rowData = new IncludeTableData();
rowData.AssetInfo = null;
rowData.AddAssetPathCell("IncludeAssets", assetInfo.AssetPath);
rowData.AddStringValueCell("AssetSource", "BuiltinAsset");
rowData.AddStringValueCell("AssetGUID", assetInfo.AssetGUID);
sourceDatas.Add(rowData);
}
}
_includeListView.Clear();
_includeListView.ClearSelection();
_includeListView.itemsSource = containsList;
_includeListView.Rebuild();
_bottomBar1.text = $"Include Assets ({containsList.Count})";
_includeTableView.itemsSource = sourceDatas;
_includeTableView.RebuildView();
}
private VisualElement MakeIncludeListViewItem()
private void OnClickBundleTableView(PointerDownEvent evt, ITableData data)
{
VisualElement element = new VisualElement();
element.style.flexDirection = FlexDirection.Row;
// 鼠标双击后检视
if (evt.clickCount != 2)
return;
var bundleTableData = data as BundleTableData;
if (bundleTableData.BundleInfo.Encrypted)
return;
if (_buildReport.Summary.BuildBundleType == (int)EBuildBundleType.AssetBundle)
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
string rootDirectory = Path.GetDirectoryName(_reportFilePath);
string filePath = $"{rootDirectory}/{bundleTableData.BundleInfo.FileName}";
if (File.Exists(filePath))
Selection.activeObject = AssetBundleRecorder.GetAssetBundle(filePath);
else
Selection.activeObject = null;
}
{
var label = new Label();
label.name = "Label3";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}
{
var label = new Label();
label.name = "Label2";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 280;
element.Add(label);
}
return element;
}
private void BindIncludeListViewItem(VisualElement element, int index)
private void OnClickIncludeTableView(PointerDownEvent evt, ITableData data)
{
List<ReportAssetInfo> containsList = _includeListView.itemsSource as List<ReportAssetInfo>;
ReportAssetInfo assetInfo = containsList[index];
// 鼠标双击后检视
if (evt.clickCount != 2)
return;
// Asset Path
var label1 = element.Q<Label>("Label1");
label1.text = assetInfo.AssetPath;
// Asset Source
var label3 = element.Q<Label>("Label3");
label3.text = assetInfo.AssetGUID != "--" ? "Main Asset" : "Builtin Asset";
// GUID
var label2 = element.Q<Label>("Label2");
label2.text = assetInfo.AssetGUID;
foreach (var cell in data.Cells)
{
if (cell is AssetPathCell assetPathCell)
{
if (assetPathCell.PingAssetObject())
break;
}
}
}
}
}

View File

@@ -1,20 +1,8 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="File Size" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="File Hash" display-tooltip-when-elided="true" name="TopBar3" style="width: 280px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Encrypted" display-tooltip-when-elided="true" name="TopBar4" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Tags" display-tooltip-when-elided="true" name="TopBar5" style="width: 80px; -unity-text-align: middle-left; flex-grow: 1;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1; flex-basis: 60px;" />
<YooAsset.Editor.TableViewer name="TopTableView" style="flex-grow: 1;" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Include Assets" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Asset Source" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="GUID" display-tooltip-when-elided="true" name="BottomBar2" style="width: 280px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex; flex-grow: 1;">
<YooAsset.Editor.TableViewer name="BottomTableView" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -11,24 +11,9 @@ namespace YooAsset.Editor
{
internal class ReporterSummaryViewer
{
private class ItemWrapper
{
public string Title { private set; get; }
public string Value { private set; get; }
public ItemWrapper(string title, string value)
{
Title = title;
Value = value;
}
}
private VisualTreeAsset _visualAsset;
private TemplateContainer _root;
private ListView _listView;
private readonly List<ItemWrapper> _items = new List<ItemWrapper>();
private ScrollView _scrollView;
/// <summary>
/// 初始化页面
@@ -44,9 +29,7 @@ namespace YooAsset.Editor
_root.style.flexGrow = 1f;
// 概述列表
_listView = _root.Q<ListView>("ListView");
_listView.makeItem = MakeListViewItem;
_listView.bindItem = BindListViewItem;
_scrollView = _root.Q<ScrollView>("ScrollView");
}
/// <summary>
@@ -54,51 +37,49 @@ namespace YooAsset.Editor
/// </summary>
public void FillViewData(BuildReport buildReport)
{
_items.Clear();
_scrollView.Clear();
_items.Add(new ItemWrapper("YooAsset Version", buildReport.Summary.YooVersion));
_items.Add(new ItemWrapper("UnityEngine Version", buildReport.Summary.UnityVersion));
_items.Add(new ItemWrapper("Build Date", buildReport.Summary.BuildDate));
_items.Add(new ItemWrapper("Build Seconds", ConvertTime(buildReport.Summary.BuildSeconds)));
_items.Add(new ItemWrapper("Build Target", $"{buildReport.Summary.BuildTarget}"));
_items.Add(new ItemWrapper("Build Pipeline", $"{buildReport.Summary.BuildPipeline}"));
_items.Add(new ItemWrapper("Package Name", buildReport.Summary.BuildPackageName));
_items.Add(new ItemWrapper("Package Version", buildReport.Summary.BuildPackageVersion));
_items.Add(new ItemWrapper("Package Note", buildReport.Summary.BuildPackageNote));
BindListViewHeader("Build Infos");
BindListViewItem("YooAsset Version", buildReport.Summary.YooVersion);
BindListViewItem("UnityEngine Version", buildReport.Summary.UnityVersion);
BindListViewItem("Build Date", buildReport.Summary.BuildDate);
BindListViewItem("Build Seconds", ConvertTime(buildReport.Summary.BuildSeconds));
BindListViewItem("Build Target", $"{buildReport.Summary.BuildTarget}");
BindListViewItem("Build Pipeline", $"{buildReport.Summary.BuildPipeline}");
BindListViewItem("Build Bundle Type", buildReport.Summary.BuildBundleType.ToString());
BindListViewItem("Package Name", buildReport.Summary.BuildPackageName);
BindListViewItem("Package Version", buildReport.Summary.BuildPackageVersion);
BindListViewItem("Package Note", buildReport.Summary.BuildPackageNote);
BindListViewItem(string.Empty, string.Empty);
_items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("Collect Settings", string.Empty));
_items.Add(new ItemWrapper("Unique Bundle Name", $"{buildReport.Summary.UniqueBundleName}"));
_items.Add(new ItemWrapper("Enable Addressable", $"{buildReport.Summary.EnableAddressable}"));
_items.Add(new ItemWrapper("Location To Lower", $"{buildReport.Summary.LocationToLower}"));
_items.Add(new ItemWrapper("Include Asset GUID", $"{buildReport.Summary.IncludeAssetGUID}"));
_items.Add(new ItemWrapper("Auto Collect Shaders", $"{buildReport.Summary.AutoCollectShaders}"));
_items.Add(new ItemWrapper("Ignore Rule Name", $"{buildReport.Summary.IgnoreRuleName}"));
BindListViewHeader("Collect Settings");
BindListViewItem("Unique Bundle Name", $"{buildReport.Summary.UniqueBundleName}");
BindListViewItem("Enable Addressable", $"{buildReport.Summary.EnableAddressable}");
BindListViewItem("Location To Lower", $"{buildReport.Summary.LocationToLower}");
BindListViewItem("Include Asset GUID", $"{buildReport.Summary.IncludeAssetGUID}");
BindListViewItem("Auto Collect Shaders", $"{buildReport.Summary.AutoCollectShaders}");
BindListViewItem("Ignore Rule Name", $"{buildReport.Summary.IgnoreRuleName}");
BindListViewItem(string.Empty, string.Empty);
_items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("Build Params", string.Empty));
_items.Add(new ItemWrapper("Clear Build Cache Files", $"{buildReport.Summary.ClearBuildCacheFiles}"));
_items.Add(new ItemWrapper("Use Asset Dependency DB", $"{buildReport.Summary.UseAssetDependencyDB}"));
_items.Add(new ItemWrapper("Enable Share Pack Rule", $"{buildReport.Summary.EnableSharePackRule}"));
_items.Add(new ItemWrapper("Encryption Class Name", buildReport.Summary.EncryptionClassName));
_items.Add(new ItemWrapper("FileNameStyle", $"{buildReport.Summary.FileNameStyle}"));
_items.Add(new ItemWrapper("CompressOption", $"{buildReport.Summary.CompressOption}"));
_items.Add(new ItemWrapper("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}"));
_items.Add(new ItemWrapper("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}"));
BindListViewHeader("Build Params");
BindListViewItem("Clear Build Cache Files", $"{buildReport.Summary.ClearBuildCacheFiles}");
BindListViewItem("Use Asset Dependency DB", $"{buildReport.Summary.UseAssetDependencyDB}");
BindListViewItem("Enable Share Pack Rule", $"{buildReport.Summary.EnableSharePackRule}");
BindListViewItem("Single Referenced Pack Alone", $"{buildReport.Summary.SingleReferencedPackAlone}");
BindListViewItem("Encryption Class Name", buildReport.Summary.EncryptionClassName);
BindListViewItem("FileNameStyle", $"{buildReport.Summary.FileNameStyle}");
BindListViewItem("CompressOption", $"{buildReport.Summary.CompressOption}");
BindListViewItem("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}");
BindListViewItem("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}");
BindListViewItem(string.Empty, string.Empty);
_items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("Build Results", string.Empty));
_items.Add(new ItemWrapper("Asset File Total Count", $"{buildReport.Summary.AssetFileTotalCount}"));
_items.Add(new ItemWrapper("Main Asset Total Count", $"{buildReport.Summary.MainAssetTotalCount}"));
_items.Add(new ItemWrapper("All Bundle Total Count", $"{buildReport.Summary.AllBundleTotalCount}"));
_items.Add(new ItemWrapper("All Bundle Total Size", ConvertSize(buildReport.Summary.AllBundleTotalSize)));
_items.Add(new ItemWrapper("Encrypted Bundle Total Count", $"{buildReport.Summary.EncryptedBundleTotalCount}"));
_items.Add(new ItemWrapper("Encrypted Bundle Total Size", ConvertSize(buildReport.Summary.EncryptedBundleTotalSize)));
_listView.Clear();
_listView.ClearSelection();
_listView.itemsSource = _items;
_listView.Rebuild();
BindListViewHeader("Build Results");
BindListViewItem("Asset File Total Count", $"{buildReport.Summary.AssetFileTotalCount}");
BindListViewItem("Main Asset Total Count", $"{buildReport.Summary.MainAssetTotalCount}");
BindListViewItem("All Bundle Total Count", $"{buildReport.Summary.AllBundleTotalCount}");
BindListViewItem("All Bundle Total Size", ConvertSize(buildReport.Summary.AllBundleTotalSize));
BindListViewItem("Encrypted Bundle Total Count", $"{buildReport.Summary.EncryptedBundleTotalCount}");
BindListViewItem("Encrypted Bundle Total Size", ConvertSize(buildReport.Summary.EncryptedBundleTotalSize));
}
/// <summary>
@@ -118,45 +99,60 @@ namespace YooAsset.Editor
}
// 列表相关
private void BindListViewHeader(string titile)
{
Toolbar toolbar = new Toolbar();
_scrollView.Add(toolbar);
ToolbarButton titleButton = new ToolbarButton();
titleButton.text = titile;
titleButton.style.unityTextAlign = TextAnchor.MiddleCenter;
titleButton.style.width = 200;
toolbar.Add(titleButton);
ToolbarButton valueButton = new ToolbarButton();
valueButton.style.unityTextAlign = TextAnchor.MiddleCenter;
valueButton.style.width = 150;
valueButton.style.flexShrink = 1;
valueButton.style.flexGrow = 1;
valueButton.SetEnabled(false);
toolbar.Add(valueButton);
}
private void BindListViewItem(string name, string value)
{
VisualElement element = MakeListViewItem();
_scrollView.Add(element);
// Title
var titleLabel = element.Q<Label>("TitleLabel");
titleLabel.text = name;
// Value
var valueLabel = element.Q<Label>("ValueLabel");
valueLabel.text = value;
}
private VisualElement MakeListViewItem()
{
VisualElement element = new VisualElement();
element.style.flexDirection = FlexDirection.Row;
{
var label = new Label();
label.name = "Label1";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 200;
element.Add(label);
}
var titleLabel = new Label();
titleLabel.name = "TitleLabel";
titleLabel.style.unityTextAlign = TextAnchor.MiddleLeft;
titleLabel.style.marginLeft = 3f;
titleLabel.style.width = 200;
element.Add(titleLabel);
{
var label = new Label();
label.name = "Label2";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
var valueLabel = new Label();
valueLabel.name = "ValueLabel";
valueLabel.style.unityTextAlign = TextAnchor.MiddleLeft;
valueLabel.style.marginLeft = 3f;
valueLabel.style.flexGrow = 1f;
valueLabel.style.width = 150;
element.Add(valueLabel);
return element;
}
private void BindListViewItem(VisualElement element, int index)
{
var itemWrapper = _items[index];
// Title
var label1 = element.Q<Label>("Label1");
label1.text = itemWrapper.Title;
// Value
var label2 = element.Q<Label>("Label2");
label2.text = itemWrapper.Value;
}
private string ConvertTime(int time)
{

View File

@@ -1,9 +1,5 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Info" display-tooltip-when-elided="true" name="TopBar1" style="width: 200px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Param" display-tooltip-when-elided="true" name="TopBar2" style="width: 150px; -unity-text-align: middle-left; flex-grow: 1;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="ListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
<ui:ScrollView name="ScrollView" horizontal-scroller-visibility="Hidden" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace YooAsset.Editor
{
[Serializable]
public class AssetInfo
public class AssetInfo : IComparable<AssetInfo>
{
private string _fileExtension = null;
@@ -37,6 +37,7 @@ namespace YooAsset.Editor
}
}
public AssetInfo(string assetPath)
{
AssetPath = assetPath;
@@ -60,5 +61,10 @@ namespace YooAsset.Editor
else
return false;
}
public int CompareTo(AssetInfo other)
{
return this.AssetPath.CompareTo(other.AssetPath);
}
}
}

View File

@@ -129,6 +129,21 @@ namespace YooAsset.Editor
}
#endregion
#region PackageManager
public static string GetPackageManagerYooVersion()
{
#if UNITY_2019_4_OR_NEWER
UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(YooAssets).Assembly);
if (packageInfo != null)
return packageInfo.version;
else
return string.Empty;
#else
return string.Empty;
#endif
}
#endregion
#region EditorUtility
/// <summary>
/// 搜集资源
@@ -559,7 +574,7 @@ namespace YooAsset.Editor
{
return path.Replace('\\', '/').Replace("\\", "/"); //替换为Linux路径格式
}
/// <summary>
/// 移除路径里的后缀名
/// </summary>

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8cae5a51fced527429445b140b8a0843
guid: 5f915322e2be56345a9d145800f7a0e0
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -0,0 +1,627 @@
#if UNITY_2021_3_OR_NEWER
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class ReorderableListView : VisualElement
{
public new class UxmlFactory : UxmlFactory<ReorderableListView, UxmlTraits>
{
}
/// <summary>
/// 制作元素委托
/// </summary>
/// <returns></returns>
public delegate VisualElement MakeElementDelegate();
/// <summary>
/// 绑定元素委托
/// </summary>
public delegate void BindElementDelegqate(VisualElement element, int index);
private Foldout _foldout;
private ListView _listView;
private Label _headerLabel;
private Button _addButton;
private Button _removeButton;
private string _headerName = nameof(ReorderableListView);
/// <summary>
/// 源数据
/// </summary>
public IList SourceData
{
set
{
if (value is ArrayList)
throw new Exception($"{nameof(SourceData)} not support {nameof(ArrayList)}");
_listView.Clear();
_listView.ClearSelection();
_listView.itemsSource = value;
_listView.Rebuild();
RefreshFoldoutName();
RefreshRemoveButton();
}
get
{
return _listView.itemsSource;
}
}
/// <summary>
/// 元素固定高度
/// </summary>
public float ElementHeight
{
set
{
_listView.fixedItemHeight = value;
_listView.Rebuild();
}
get
{
return _listView.fixedItemHeight;
}
}
/// <summary>
/// 增加按钮显隐
/// </summary>
public bool DisplayAdd
{
set
{
UIElementsTools.SetElementVisible(_addButton, value);
}
get
{
return _addButton.style.visibility == Visibility.Visible;
}
}
/// <summary>
/// 移除按钮显隐
/// </summary>
public bool DisplayRemove
{
set
{
UIElementsTools.SetElementVisible(_removeButton, value);
}
get
{
return _removeButton.style.visibility == Visibility.Visible;
}
}
/// <summary>
/// 标题名称
/// </summary>
public string HeaderName
{
set
{
_headerName = value;
RefreshFoldoutName();
}
get
{
return _headerName;
}
}
/// <summary>
/// 制作元素的回调
/// </summary>
public MakeElementDelegate MakeElementCallback;
/// <summary>
/// 绑定元素的回调
/// </summary>
public BindElementDelegqate BindElementCallback;
public ReorderableListView()
{
CreateView(true);
}
public ReorderableListView(bool foldout)
{
CreateView(foldout);
}
private void CreateView(bool foldout)
{
this.style.flexGrow = 1;
this.style.flexShrink = 1;
// 折叠栏
if (foldout)
{
_foldout = new Foldout();
_foldout.style.flexGrow = 1f;
_foldout.style.flexShrink = 1f;
_foldout.text = $"{nameof(ReorderableListView)}";
}
else
{
_headerLabel = new Label();
}
// 列表视图
_listView = new ListView();
_listView.style.flexGrow = 1;
_listView.style.flexShrink = 1;
_listView.reorderable = true;
_listView.reorderMode = ListViewReorderMode.Animated;
_listView.makeItem = MakeListViewElement;
_listView.bindItem = BindListViewElement;
#if UNITY_2022_3_OR_NEWER
_listView.selectionChanged += OnSelectionChanged;
#elif UNITY_2020_1_OR_NEWER
_listView.onSelectionChange += OnSelectionChanged;
#else
_listView.onSelectionChanged += OnSelectionChanged;
#endif
// 按钮组
var buttonContainer = new VisualElement();
buttonContainer.style.flexDirection = FlexDirection.RowReverse;
// 移除按钮
_removeButton = new Button();
_removeButton.text = " - ";
_removeButton.clicked += OnClickRemoveButton;
_removeButton.SetEnabled(false);
buttonContainer.Add(_removeButton);
// 增加按钮
_addButton = new Button();
_addButton.text = " + ";
_addButton.clicked += OnClickAddButton;
buttonContainer.Add(_addButton);
// 组织页面
if (foldout)
{
_foldout.Add(_listView);
_foldout.Add(buttonContainer);
this.Add(_foldout);
}
else
{
this.Add(_headerLabel);
this.Add(_listView);
this.Add(buttonContainer);
}
}
private void OnClickAddButton()
{
if (_listView.itemsSource != null)
{
object defaultValue = GetElementDefaultValue();
_listView.itemsSource.Add(defaultValue);
_listView.Rebuild();
RefreshFoldoutName();
RefreshRemoveButton();
}
else
{
Debug.LogWarning("The source data is null !");
}
}
private void OnClickRemoveButton()
{
if (_listView.itemsSource != null)
{
if (_listView.selectedIndex >= 0)
{
_listView.itemsSource.RemoveAt(_listView.selectedIndex);
_listView.Rebuild();
RefreshFoldoutName();
RefreshRemoveButton();
}
}
else
{
Debug.LogWarning("The source data is null !");
}
}
private void OnSelectionChanged(IEnumerable<object> objs)
{
RefreshRemoveButton();
}
/// <summary>
/// 生成元素
/// </summary>
private VisualElement MakeListViewElement()
{
if (MakeElementCallback != null)
{
return MakeElementCallback.Invoke();
}
Type elementType = GetElementType();
if (elementType == typeof(string))
{
TextField textField = new TextField();
textField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)textField.userData;
_listView.itemsSource[itemIndex] = textField.value;
});
return textField;
}
else if (elementType == typeof(int))
{
IntegerField intField = new IntegerField();
intField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)intField.userData;
_listView.itemsSource[itemIndex] = intField.value;
});
return intField;
}
else if (elementType == typeof(long))
{
LongField longField = new LongField();
longField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)longField.userData;
_listView.itemsSource[itemIndex] = longField.value;
});
return longField;
}
else if (elementType == typeof(float))
{
FloatField floatField = new FloatField();
floatField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)floatField.userData;
_listView.itemsSource[itemIndex] = floatField.value;
});
return floatField;
}
else if (elementType == typeof(double))
{
DoubleField doubleField = new DoubleField();
doubleField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)doubleField.userData;
_listView.itemsSource[itemIndex] = doubleField.value;
});
return doubleField;
}
else if (elementType == typeof(bool))
{
Toggle toggle = new Toggle();
toggle.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)toggle.userData;
_listView.itemsSource[itemIndex] = toggle.value;
});
return toggle;
}
else if (elementType == typeof(Hash128))
{
Hash128Field hash128Field = new Hash128Field();
hash128Field.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)hash128Field.userData;
_listView.itemsSource[itemIndex] = hash128Field.value;
});
return hash128Field;
}
else if (elementType == typeof(Vector2))
{
Vector2Field vector2Field = new Vector2Field();
vector2Field.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)vector2Field.userData;
_listView.itemsSource[itemIndex] = vector2Field.value;
});
return vector2Field;
}
else if (elementType == typeof(Vector3))
{
Vector3Field vector3Field = new Vector3Field();
vector3Field.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)vector3Field.userData;
_listView.itemsSource[itemIndex] = vector3Field.value;
});
return vector3Field;
}
else if (elementType == typeof(Vector4))
{
Vector4Field vector4Field = new Vector4Field();
vector4Field.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)vector4Field.userData;
_listView.itemsSource[itemIndex] = vector4Field.value;
});
return vector4Field;
}
else if (elementType == typeof(Rect))
{
RectField rectField = new RectField();
rectField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)rectField.userData;
_listView.itemsSource[itemIndex] = rectField.value;
});
return rectField;
}
else if (elementType == typeof(Bounds))
{
BoundsField boundsField = new BoundsField();
boundsField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)boundsField.userData;
_listView.itemsSource[itemIndex] = boundsField.value;
});
return boundsField;
}
else if (elementType == typeof(Color))
{
ColorField colorField = new ColorField();
colorField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)colorField.userData;
_listView.itemsSource[itemIndex] = colorField.value;
});
return colorField;
}
else if (elementType == typeof(Gradient))
{
GradientField gradientField = new GradientField();
gradientField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)gradientField.userData;
_listView.itemsSource[itemIndex] = gradientField.value;
});
return gradientField;
}
else if (elementType == typeof(AnimationCurve))
{
CurveField curveField = new CurveField();
curveField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)curveField.userData;
_listView.itemsSource[itemIndex] = curveField.value;
});
return curveField;
}
else if (elementType == typeof(UnityEngine.Object))
{
ObjectField objectField = new ObjectField();
objectField.objectType = typeof(UnityEngine.Object);
objectField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)objectField.userData;
_listView.itemsSource[itemIndex] = objectField.value;
});
return objectField;
}
else if (elementType.IsEnum)
{
EnumField enumField = new EnumField();
enumField.RegisterValueChangedCallback(evt =>
{
int itemIndex = (int)enumField.userData;
_listView.itemsSource[itemIndex] = enumField.value;
});
return enumField;
}
else
{
Label label = new Label();
label.text = $"Not support element type : {elementType.Name}";
return label;
}
}
/// <summary>
/// 绑定元素
/// </summary>
private void BindListViewElement(VisualElement listViewElement, int index)
{
if (BindElementCallback != null)
{
BindElementCallback.Invoke(listViewElement, index);
return;
}
var elementValue = _listView.itemsSource[index];
string elementName = GetElementName(index);
Type elementType = GetElementType();
if (elementType == typeof(string))
{
TextField textField = listViewElement as TextField;
textField.userData = index;
textField.label = elementName;
textField.SetValueWithoutNotify(elementValue as string);
}
else if (elementType == typeof(int))
{
IntegerField intField = listViewElement as IntegerField;
intField.userData = index;
intField.label = elementName;
intField.SetValueWithoutNotify((int)elementValue);
}
else if (elementType == typeof(long))
{
LongField longField = listViewElement as LongField;
longField.userData = index;
longField.label = elementName;
longField.SetValueWithoutNotify((long)elementValue);
}
else if (elementType == typeof(float))
{
FloatField floatField = listViewElement as FloatField;
floatField.userData = index;
floatField.label = elementName;
floatField.SetValueWithoutNotify((float)elementValue);
}
else if (elementType == typeof(double))
{
DoubleField doubleField = listViewElement as DoubleField;
doubleField.userData = index;
doubleField.label = elementName;
doubleField.SetValueWithoutNotify((double)elementValue);
}
else if (elementType == typeof(bool))
{
Toggle toggle = listViewElement as Toggle;
toggle.userData = index;
toggle.label = elementName;
toggle.SetValueWithoutNotify((bool)elementValue);
}
else if (elementType == typeof(Hash128))
{
Hash128Field hash128Field = listViewElement as Hash128Field;
hash128Field.userData = index;
hash128Field.label = elementName;
hash128Field.SetValueWithoutNotify((Hash128)elementValue);
}
else if (elementType == typeof(Vector2))
{
Vector2Field vector2Field = listViewElement as Vector2Field;
vector2Field.userData = index;
vector2Field.label = elementName;
vector2Field.SetValueWithoutNotify((Vector2)elementValue);
}
else if (elementType == typeof(Vector3))
{
Vector3Field vector3Field = listViewElement as Vector3Field;
vector3Field.userData = index;
vector3Field.label = elementName;
vector3Field.SetValueWithoutNotify((Vector3)elementValue);
}
else if (elementType == typeof(Vector4))
{
Vector4Field vector4Field = listViewElement as Vector4Field;
vector4Field.userData = index;
vector4Field.label = elementName;
vector4Field.SetValueWithoutNotify((Vector4)elementValue);
}
else if (elementType == typeof(Rect))
{
RectField rectField = listViewElement as RectField;
rectField.userData = index;
rectField.label = elementName;
rectField.SetValueWithoutNotify((Rect)elementValue);
}
else if (elementType == typeof(Bounds))
{
BoundsField boundsField = listViewElement as BoundsField;
boundsField.userData = index;
boundsField.label = elementName;
boundsField.SetValueWithoutNotify((Bounds)elementValue);
}
else if (elementType == typeof(Color))
{
ColorField colorField = listViewElement as ColorField;
colorField.userData = index;
colorField.label = elementName;
colorField.SetValueWithoutNotify((Color)elementValue);
}
else if (elementType == typeof(Gradient))
{
GradientField gradientField = listViewElement as GradientField;
gradientField.userData = index;
gradientField.label = elementName;
gradientField.SetValueWithoutNotify((Gradient)elementValue);
}
else if (elementType == typeof(AnimationCurve))
{
CurveField curveField = listViewElement as CurveField;
curveField.userData = index;
curveField.label = elementName;
curveField.SetValueWithoutNotify((AnimationCurve)elementValue);
}
else if (elementType == typeof(UnityEngine.Object))
{
ObjectField objectField = listViewElement as ObjectField;
objectField.userData = index;
objectField.label = elementName;
objectField.SetValueWithoutNotify(elementValue as UnityEngine.Object);
}
else if (elementType.IsEnum)
{
EnumField enumField = listViewElement as EnumField;
enumField.userData = index;
enumField.label = elementName;
enumField.Init((Enum)elementValue);
enumField.SetValueWithoutNotify((Enum)elementValue);
}
else
{
}
}
private Type GetElementType()
{
Type elementType = _listView.itemsSource.GetType().GetGenericArguments()[0];
return elementType;
}
private object GetElementDefaultValue()
{
Type type = GetElementType();
if (type.IsValueType)
{
return Activator.CreateInstance(type);
}
return null;
}
private string GetElementName(int index)
{
return $"Element {index}";
}
private void RefreshRemoveButton()
{
if (_listView.itemsSource == null)
{
_removeButton.SetEnabled(false);
return;
}
// 注意:数据列表移除元素的时候有可能会越界!
if (_listView.selectedIndex >= _listView.itemsSource.Count)
_listView.ClearSelection();
if (_listView.selectedIndex >= 0)
_removeButton.SetEnabled(true);
else
_removeButton.SetEnabled(false);
}
private void RefreshFoldoutName()
{
if (_listView.itemsSource == null)
{
if (_foldout != null)
_foldout.text = _headerName;
if (_headerLabel != null)
_headerLabel.text = _headerName;
}
else
{
if (_foldout != null)
_foldout.text = _headerName + $" ({_listView.itemsSource.Count}) ";
if (_headerLabel != null)
_headerLabel.text = _headerName + $" ({_listView.itemsSource.Count}) ";
}
}
}
}
#endif

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