mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-21 16:00:32 +00:00
Compare commits
125 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76929cc015 | ||
|
|
cde0f4bcd8 | ||
|
|
8dc0560537 | ||
|
|
a054740de6 | ||
|
|
029b850d6b | ||
|
|
8260653eae | ||
|
|
bd7b9b5c44 | ||
|
|
8f33a391f8 | ||
|
|
2f9d3a9f11 | ||
|
|
316294f449 | ||
|
|
09fac3bd64 | ||
|
|
2da81212b4 | ||
|
|
4cad587609 | ||
|
|
67eeae31c7 | ||
|
|
ae465a47a9 | ||
|
|
23b59f6ad6 | ||
|
|
09e3483e0a | ||
|
|
b3f4e9ae6e | ||
|
|
79efe6237d | ||
|
|
bf0f479234 | ||
|
|
ece1dab28b | ||
|
|
b913b5c20c | ||
|
|
366cf3c792 | ||
|
|
21ccd4d29f | ||
|
|
b8ba4219cd | ||
|
|
43da6847ba | ||
|
|
c22c87e16b | ||
|
|
4551dabb39 | ||
|
|
774ad0e5ef | ||
|
|
bd87e982ef | ||
|
|
ecd4973948 | ||
|
|
6dd1eee6c3 | ||
|
|
42703def02 | ||
|
|
afc08d4e46 | ||
|
|
65875b66c2 | ||
|
|
091758022f | ||
|
|
c395a7a750 | ||
|
|
2ab045658b | ||
|
|
c196cd84d3 | ||
|
|
c3c18cd555 | ||
|
|
cb48c672bd | ||
|
|
713073203c | ||
|
|
eafdb8cd31 | ||
|
|
d592fb96a6 | ||
|
|
0c116b7701 | ||
|
|
664bb1f71c | ||
|
|
5f809cc26a | ||
|
|
1bb70edd4b | ||
|
|
2922b44747 | ||
|
|
f34078a604 | ||
|
|
1c1bb078b1 | ||
|
|
9ec841ff67 | ||
|
|
665a16fe60 | ||
|
|
8d02406211 | ||
|
|
873d873194 | ||
|
|
2c9819762a | ||
|
|
ce70eebda6 | ||
|
|
47af58bb5b | ||
|
|
b0397981ce | ||
|
|
650d8689ee | ||
|
|
b443a1c308 | ||
|
|
b1bb79bd95 | ||
|
|
7ca1ebac79 | ||
|
|
f8036782e4 | ||
|
|
ca7b42981b | ||
|
|
c6440c9312 | ||
|
|
3de44a416c | ||
|
|
62f1c050ca | ||
|
|
6070e619da | ||
|
|
636fbed7f2 | ||
|
|
d354db382c | ||
|
|
501765eaa7 | ||
|
|
9f1eaf4a62 | ||
|
|
a4b098084d | ||
|
|
2cb006f3d9 | ||
|
|
775c724840 | ||
|
|
15dc047488 | ||
|
|
91b25400dc | ||
|
|
9b3839ac0b | ||
|
|
ff74dcdd8b | ||
|
|
d316c5000a | ||
|
|
d8692c836f | ||
|
|
0a4a3d8f2e | ||
|
|
5484b604a7 | ||
|
|
66c3c4862a | ||
|
|
e9d31bbf94 | ||
|
|
55bcd502e2 | ||
|
|
9bf22f2c79 | ||
|
|
cbf142dbf8 | ||
|
|
a6e94acefb | ||
|
|
469d73d641 | ||
|
|
0d521c68bd | ||
|
|
cd62c1dd9a | ||
|
|
e6422445a6 | ||
|
|
7683746032 | ||
|
|
a25fd19bcc | ||
|
|
6675e8f171 | ||
|
|
c836dce54d | ||
|
|
f3ab8f63e7 | ||
|
|
20d2c517b2 | ||
|
|
d6a2b31d5c | ||
|
|
533f96361a | ||
|
|
09807901c0 | ||
|
|
57ae9aa18c | ||
|
|
08efcaf4c1 | ||
|
|
b221b8121a | ||
|
|
abb75fe858 | ||
|
|
4591d0b5f6 | ||
|
|
b25f656372 | ||
|
|
cc1c8d6414 | ||
|
|
99a3abf697 | ||
|
|
023dc82f8e | ||
|
|
09a985fadb | ||
|
|
eb6b6e3aba | ||
|
|
89bde69417 | ||
|
|
6bb3c17f82 | ||
|
|
8be6d54f22 | ||
|
|
ea28d3e6e1 | ||
|
|
9fbce6a726 | ||
|
|
46467171ba | ||
|
|
d2d6d2ad14 | ||
|
|
f38d663e9d | ||
|
|
11e03c7a13 | ||
|
|
f466a02fd7 | ||
|
|
3bb4d5082b |
145
Assets/UniTask.YooAsset~/AsyncOperationBaseExtensions.cs
Normal file
145
Assets/UniTask.YooAsset~/AsyncOperationBaseExtensions.cs
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
using System;
|
||||||
|
using YooAsset;
|
||||||
|
using static Cysharp.Threading.Tasks.Internal.Error;
|
||||||
|
|
||||||
|
namespace Cysharp.Threading.Tasks
|
||||||
|
{
|
||||||
|
public static class AsyncOperationBaseExtensions
|
||||||
|
{
|
||||||
|
public static UniTask.Awaiter GetAwaiter(this AsyncOperationBase handle)
|
||||||
|
{
|
||||||
|
return ToUniTask(handle).GetAwaiter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UniTask ToUniTask(this AsyncOperationBase handle,
|
||||||
|
IProgress<float> progress = null,
|
||||||
|
PlayerLoopTiming timing = PlayerLoopTiming.Update)
|
||||||
|
{
|
||||||
|
ThrowArgumentNullException(handle, nameof(handle));
|
||||||
|
|
||||||
|
if(handle.IsDone)
|
||||||
|
{
|
||||||
|
return UniTask.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new UniTask(
|
||||||
|
AsyncOperationBaserConfiguredSource.Create(
|
||||||
|
handle,
|
||||||
|
timing,
|
||||||
|
progress,
|
||||||
|
out var token
|
||||||
|
),
|
||||||
|
token
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class AsyncOperationBaserConfiguredSource : IUniTaskSource,
|
||||||
|
IPlayerLoopItem,
|
||||||
|
ITaskPoolNode<AsyncOperationBaserConfiguredSource>
|
||||||
|
{
|
||||||
|
private static TaskPool<AsyncOperationBaserConfiguredSource> pool;
|
||||||
|
|
||||||
|
private AsyncOperationBaserConfiguredSource nextNode;
|
||||||
|
|
||||||
|
public ref AsyncOperationBaserConfiguredSource NextNode => ref nextNode;
|
||||||
|
|
||||||
|
static AsyncOperationBaserConfiguredSource()
|
||||||
|
{
|
||||||
|
TaskPool.RegisterSizeGetter(typeof(AsyncOperationBaserConfiguredSource), () => pool.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Action<AsyncOperationBase> continuationAction;
|
||||||
|
private AsyncOperationBase handle;
|
||||||
|
private IProgress<float> progress;
|
||||||
|
private bool completed;
|
||||||
|
private UniTaskCompletionSourceCore<AsyncUnit> core;
|
||||||
|
|
||||||
|
AsyncOperationBaserConfiguredSource() { continuationAction = Continuation; }
|
||||||
|
|
||||||
|
public static IUniTaskSource Create(AsyncOperationBase handle,
|
||||||
|
PlayerLoopTiming timing,
|
||||||
|
IProgress<float> progress,
|
||||||
|
out short token)
|
||||||
|
{
|
||||||
|
if(!pool.TryPop(out var result))
|
||||||
|
{
|
||||||
|
result = new AsyncOperationBaserConfiguredSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
result.handle = handle;
|
||||||
|
result.progress = progress;
|
||||||
|
result.completed = false;
|
||||||
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
|
if(progress is not null)
|
||||||
|
{
|
||||||
|
PlayerLoopHelper.AddAction(timing, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
handle.Completed += result.continuationAction;
|
||||||
|
|
||||||
|
token = result.core.Version;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Continuation(AsyncOperationBase _)
|
||||||
|
{
|
||||||
|
handle.Completed -= continuationAction;
|
||||||
|
|
||||||
|
if(completed)
|
||||||
|
{
|
||||||
|
TryReturn();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
completed = true;
|
||||||
|
if(handle.Status == EOperationStatus.Failed)
|
||||||
|
{
|
||||||
|
core.TrySetException(new Exception(handle.Error));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
core.TrySetResult(AsyncUnit.Default);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TryReturn()
|
||||||
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
|
core.Reset();
|
||||||
|
handle = default;
|
||||||
|
progress = default;
|
||||||
|
return pool.TryPush(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTaskStatus GetStatus(short token) => core.GetStatus(token);
|
||||||
|
|
||||||
|
public void OnCompleted(Action<object> continuation, object state, short token)
|
||||||
|
{
|
||||||
|
core.OnCompleted(continuation, state, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetResult(short token) { core.GetResult(token); }
|
||||||
|
|
||||||
|
public UniTaskStatus UnsafeGetStatus() => core.UnsafeGetStatus();
|
||||||
|
|
||||||
|
public bool MoveNext()
|
||||||
|
{
|
||||||
|
if(completed)
|
||||||
|
{
|
||||||
|
TryReturn();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!handle.IsDone)
|
||||||
|
{
|
||||||
|
progress?.Report(handle.Progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2cceff5ec1f84bd0a6a9b4ed7719527c
|
||||||
|
timeCreated: 1651978895
|
||||||
167
Assets/UniTask.YooAsset~/OperationHandleBaseExtensions.cs
Normal file
167
Assets/UniTask.YooAsset~/OperationHandleBaseExtensions.cs
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
using System;
|
||||||
|
using YooAsset;
|
||||||
|
using static Cysharp.Threading.Tasks.Internal.Error;
|
||||||
|
|
||||||
|
namespace Cysharp.Threading.Tasks
|
||||||
|
{
|
||||||
|
public static class OperationHandleBaseExtensions
|
||||||
|
{
|
||||||
|
public static UniTask.Awaiter GetAwaiter(this OperationHandleBase handle)
|
||||||
|
{
|
||||||
|
return ToUniTask(handle).GetAwaiter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UniTask ToUniTask(this OperationHandleBase handle,
|
||||||
|
IProgress<float> progress = null,
|
||||||
|
PlayerLoopTiming timing = PlayerLoopTiming.Update)
|
||||||
|
{
|
||||||
|
ThrowArgumentNullException(handle, nameof(handle));
|
||||||
|
|
||||||
|
if(!handle.IsValid)
|
||||||
|
{
|
||||||
|
return UniTask.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new UniTask(
|
||||||
|
OperationHandleBaserConfiguredSource.Create(
|
||||||
|
handle,
|
||||||
|
timing,
|
||||||
|
progress,
|
||||||
|
out var token
|
||||||
|
),
|
||||||
|
token
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class OperationHandleBaserConfiguredSource : IUniTaskSource,
|
||||||
|
IPlayerLoopItem,
|
||||||
|
ITaskPoolNode<OperationHandleBaserConfiguredSource>
|
||||||
|
{
|
||||||
|
private static TaskPool<OperationHandleBaserConfiguredSource> pool;
|
||||||
|
|
||||||
|
private OperationHandleBaserConfiguredSource nextNode;
|
||||||
|
|
||||||
|
public ref OperationHandleBaserConfiguredSource NextNode => ref nextNode;
|
||||||
|
|
||||||
|
static OperationHandleBaserConfiguredSource()
|
||||||
|
{
|
||||||
|
TaskPool.RegisterSizeGetter(typeof(OperationHandleBaserConfiguredSource), () => pool.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Action<OperationHandleBase> continuationAction;
|
||||||
|
private OperationHandleBase handle;
|
||||||
|
private IProgress<float> progress;
|
||||||
|
private bool completed;
|
||||||
|
private UniTaskCompletionSourceCore<AsyncUnit> core;
|
||||||
|
|
||||||
|
OperationHandleBaserConfiguredSource() { continuationAction = Continuation; }
|
||||||
|
|
||||||
|
public static IUniTaskSource Create(OperationHandleBase handle,
|
||||||
|
PlayerLoopTiming timing,
|
||||||
|
IProgress<float> progress,
|
||||||
|
out short token)
|
||||||
|
{
|
||||||
|
if(!pool.TryPop(out var result))
|
||||||
|
{
|
||||||
|
result = new OperationHandleBaserConfiguredSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
result.handle = handle;
|
||||||
|
result.progress = progress;
|
||||||
|
result.completed = false;
|
||||||
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
|
if(progress is not null)
|
||||||
|
{
|
||||||
|
PlayerLoopHelper.AddAction(timing, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(handle)
|
||||||
|
{
|
||||||
|
case AssetOperationHandle asset_handle:
|
||||||
|
asset_handle.Completed += result.continuationAction;
|
||||||
|
break;
|
||||||
|
case SceneOperationHandle scene_handle:
|
||||||
|
scene_handle.Completed += result.continuationAction;
|
||||||
|
break;
|
||||||
|
case SubAssetsOperationHandle sub_asset_handle:
|
||||||
|
sub_asset_handle.Completed += result.continuationAction;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
token = result.core.Version;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Continuation(OperationHandleBase _)
|
||||||
|
{
|
||||||
|
switch(handle)
|
||||||
|
{
|
||||||
|
case AssetOperationHandle asset_handle:
|
||||||
|
asset_handle.Completed -= continuationAction;
|
||||||
|
break;
|
||||||
|
case SceneOperationHandle scene_handle:
|
||||||
|
scene_handle.Completed -= continuationAction;
|
||||||
|
break;
|
||||||
|
case SubAssetsOperationHandle sub_asset_handle:
|
||||||
|
sub_asset_handle.Completed -= continuationAction;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(completed)
|
||||||
|
{
|
||||||
|
TryReturn();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
completed = true;
|
||||||
|
if(handle.Status == EOperationStatus.Failed)
|
||||||
|
{
|
||||||
|
core.TrySetException(new Exception(handle.LastError));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
core.TrySetResult(AsyncUnit.Default);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TryReturn()
|
||||||
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
|
core.Reset();
|
||||||
|
handle = default;
|
||||||
|
progress = default;
|
||||||
|
return pool.TryPush(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTaskStatus GetStatus(short token) => core.GetStatus(token);
|
||||||
|
|
||||||
|
public void OnCompleted(Action<object> continuation, object state, short token)
|
||||||
|
{
|
||||||
|
core.OnCompleted(continuation, state, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetResult(short token) { core.GetResult(token); }
|
||||||
|
|
||||||
|
public UniTaskStatus UnsafeGetStatus() => core.UnsafeGetStatus();
|
||||||
|
|
||||||
|
public bool MoveNext()
|
||||||
|
{
|
||||||
|
if(completed)
|
||||||
|
{
|
||||||
|
TryReturn();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(handle.IsValid)
|
||||||
|
{
|
||||||
|
progress?.Report(handle.Progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e1c9a3a6de2246bf88547a6b59b99b9f
|
||||||
|
timeCreated: 1650851321
|
||||||
19
Assets/UniTask.YooAsset~/README.md
Normal file
19
Assets/UniTask.YooAsset~/README.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# UniTask 扩展
|
||||||
|
|
||||||
|
[仓库链接](https://github.com/Cysharp/UniTask)
|
||||||
|
- 请去下载对应的源码,并删除此目录最后的波浪线
|
||||||
|
- 在 UniTask `_InternalVisibleTo.cs` 文件中增加 `[assembly: InternalsVisibleTo("UniTask.YooAsset")]` 后即可使用
|
||||||
|
|
||||||
|
## 代码示例
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var handle = YooAssets.LoadAssetAsync<GameObject>("Assets/Res/Prefabs/TestImg.prefab");
|
||||||
|
|
||||||
|
await handle.ToUniTask();
|
||||||
|
|
||||||
|
var obj = handle.AssetObject as GameObject;
|
||||||
|
var go = Instantiate(obj, transform);
|
||||||
|
|
||||||
|
go.transform.localPosition = Vector3.zero;
|
||||||
|
go.transform.localScale = Vector3.one;
|
||||||
|
```
|
||||||
7
Assets/UniTask.YooAsset~/README.md.meta
Normal file
7
Assets/UniTask.YooAsset~/README.md.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6375cc739b170490fbc6c38181b2c600
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
17
Assets/UniTask.YooAsset~/UniTask.YooAsset.asmdef
Normal file
17
Assets/UniTask.YooAsset~/UniTask.YooAsset.asmdef
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "UniTask.YooAsset",
|
||||||
|
"rootNamespace": "",
|
||||||
|
"references": [
|
||||||
|
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||||
|
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
||||||
|
],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
||||||
7
Assets/UniTask.YooAsset~/UniTask.YooAsset.asmdef.meta
Normal file
7
Assets/UniTask.YooAsset~/UniTask.YooAsset.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cf4f1d4730c114c48ab680458e5a2455
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,6 +1,202 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
All notable changes to this package will be documented in this file.
|
All notable changes to this package will be documented in this file.
|
||||||
|
|
||||||
|
## [1.0.9] - 2022-05-14
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了YooAssets.GetAssetInfos(string Tag)方法返回了无关的资源信息的问题。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 编辑器下的模拟运行模式,不再依赖配置里的构建版本。
|
||||||
|
- 更新资源清单结构,资源对象类增加分类标签。
|
||||||
|
- 优化了资源工具相关配置文件的加载方式和途径,这些配置文件可以放置在任何目录下。
|
||||||
|
- 优化了Location无效后的错误报告方式。
|
||||||
|
- 优化了资源包的构建参数,现在始终开启DisableLoadAssetByFileName,帮助减小运行时的内存。
|
||||||
|
- YooAssets.ProcessOperation()重命名为YooAssets.StartOperation()
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 新增YooAssets.IsNeedDownloadFromRemote()方法。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
public static bool IsNeedDownloadFromRemote(string location);
|
||||||
|
````
|
||||||
|
|
||||||
|
- 新增获取所有子资源对象的方法。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
class SubAssetsOperationHandle
|
||||||
|
{
|
||||||
|
public TObject[] GetSubAssetObjects<TObject>();
|
||||||
|
}
|
||||||
|
````
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- YooAssets.GetBundleInfo()方法已经移除。
|
||||||
|
|
||||||
|
## [1.0.8] - 2022-05-08
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了资源收集器导出配置文件时没有导出公共设置。
|
||||||
|
- 修复了不兼容Unity2018版本的错误。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- AssetBundleGrouper窗口变更为AssetBundleCollector窗口。
|
||||||
|
- **优化了编辑器下模拟运行的初始化速度**。
|
||||||
|
- **优化了资源收集窗口打开时卡顿的问题**。
|
||||||
|
- 资源收集XML配表支持版本兼容。
|
||||||
|
- 资源报告查看窗口支持预览AssetBundle文件内容的功能。
|
||||||
|
- 完善了对UniTask的支持。
|
||||||
|
- YooAssets所有接口支持初始化容错检测。
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 异步操作类增加进度查询字段。
|
||||||
|
|
||||||
|
```c#
|
||||||
|
class AsyncOperationBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 处理进度
|
||||||
|
/// </summary>
|
||||||
|
public float Progress { get; protected set; }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- 增加开启异步操作的方法。
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 开启一个异步操作
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="operation">异步操作对象</param>
|
||||||
|
public static void ProcessOperaiton(GameAsyncOperation operation)
|
||||||
|
```
|
||||||
|
|
||||||
|
- 新增编辑器下模拟模式的初始化参数。
|
||||||
|
|
||||||
|
````c#
|
||||||
|
/// <summary>
|
||||||
|
/// 用于模拟运行的资源清单路径
|
||||||
|
/// 注意:如果路径为空,会自动重新构建补丁清单。
|
||||||
|
/// </summary>
|
||||||
|
public string SimulatePatchManifestPath;
|
||||||
|
````
|
||||||
|
|
||||||
|
- 新增通用的初始化参数。
|
||||||
|
|
||||||
|
```c#
|
||||||
|
/// <summary>
|
||||||
|
/// 资源定位地址大小写不敏感
|
||||||
|
/// </summary>
|
||||||
|
public bool LocationToLower = false;
|
||||||
|
```
|
||||||
|
|
||||||
|
## [1.0.7] - 2022-05-04
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了异步操作系统的Task再次等待无效的问题。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- YooAssets.LoadRawFileAsync()方法重新命名为YooAssets.GetRawFileAsync()
|
||||||
|
- YooAssetSetting文件夹支持了全路径搜索定位。
|
||||||
|
- 优化了打包的核心逻辑,对依赖资源进行自动划分,以及支持设置依赖资源收集器。
|
||||||
|
- 初始化的时候,删除验证失败的资源文件。
|
||||||
|
- 构建报告浏览窗口支持排序功能。
|
||||||
|
- 着色器变种收集工具支持了配置缓存。
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 支持可寻址资源定位系统,包括编辑器和运行时环境。
|
||||||
|
- 增加快速构建模式,用于EditorPlayMode完美模拟线上环境。
|
||||||
|
- 增加了Window Dock功能,已打开的界面会自动停靠在一个窗体下。
|
||||||
|
- 增加一个新的打包规则:PackTopDirectory。
|
||||||
|
- 增加获取资源信息的方法。
|
||||||
|
```c#
|
||||||
|
public static AssetInfo[] GetAssetInfos(string tag)
|
||||||
|
```
|
||||||
|
- 增加补丁下载器下载全部资源的方法。
|
||||||
|
```c#
|
||||||
|
public static PatchDownloaderOperation CreatePatchDownloader(int downloadingMaxNumber, int failedTryAgain)
|
||||||
|
```
|
||||||
|
- 增加指定资源版本的资源更新下载方法。
|
||||||
|
```c#
|
||||||
|
public static UpdatePackageOperation UpdatePackageAsync(int resourceVersion, int timeout = 60)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- 移除了自动释放资源的初始化参数。
|
||||||
|
|
||||||
|
## [1.0.6] - 2022-04-26
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复工具界面显示异常在Unity2021版本下。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 操作句柄支持错误信息查询。
|
||||||
|
- 支持UniTask异步操作库。
|
||||||
|
- 优化类型搜索方式,改为全域搜索类型。
|
||||||
|
- AssetBundleGrouper窗口添加和移除Grouper支持操作回退。
|
||||||
|
|
||||||
|
## [1.0.5] - 2022-04-22
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了非主动收集的着色器没有打进统一的着色器资源包的问题。
|
||||||
|
- 修复了单个收集的资源对象没有设置依赖资源列表的问题。
|
||||||
|
- 修复Task异步加载一直等待的问题。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 资源打包的过滤文件列表增加cginc格式。
|
||||||
|
- 增加编辑器扩展的支持,第三方实现YooAsset插件。
|
||||||
|
- 优化原生文件加载逻辑,支持离线运行模式和编辑器运行模式。
|
||||||
|
- 优化场景卸载逻辑,在加载新的主场景的时候自动卸载已经加载的所有场景。
|
||||||
|
- 支持演练构建模式,在不生成资源包的情况下快速构建查看结果。
|
||||||
|
- 新增调试信息,出生场景和出生时间。
|
||||||
|
|
||||||
|
## [1.0.4] - 2022-04-18
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复资源清单附加版本之后引发的一个流程错误。
|
||||||
|
- 修复原生文件拷贝目录不存导致的加载失败。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 在编辑器下检测资源路径是否合法并警告。
|
||||||
|
- 完善原生文件异步加载接口。
|
||||||
|
|
||||||
|
## [1.0.3] - 2022-04-14
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- 修复了AssetBundleDebugger窗口的BundleView视口下,Using列表显示不完整的问题。
|
||||||
|
- 修复了AssetBundleDebugger窗口的BundleView视口下,Bundle列表内元素重复的问题。
|
||||||
|
- 修复了特殊情况下依赖的资源包列表里包含主资源包的问题。
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- 实例化GameObject的时候,如果没有传递坐标和角度则使用默认值。
|
||||||
|
- 优化了资源分组配置保存策略,修改为窗口关闭时保存。
|
||||||
|
- 简化了资源版本概念,降低学习成本,统一了CDN上的目录结构。
|
||||||
|
- 资源定位接口扩展,方便开发可寻址资产定位功能。
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- 离线运行模式支持WEBGL平台。
|
||||||
|
- 保留构建窗口界面的配置数据。
|
||||||
|
|
||||||
## [1.0.2] - 2022-04-07
|
## [1.0.2] - 2022-04-07
|
||||||
|
|
||||||
@@ -11,7 +207,7 @@ All notable changes to this package will be documented in this file.
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- StreamingAssets目录下增加了用于存放打包资源的总文件夹
|
- StreamingAssets目录下增加了用于存放打包资源的总文件夹。
|
||||||
|
|
||||||
## [1.0.1] - 2022-04-07
|
## [1.0.1] - 2022-04-07
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,12 @@ namespace YooAsset.Editor
|
|||||||
public BuildParametersContext(BuildParameters parameters)
|
public BuildParametersContext(BuildParameters parameters)
|
||||||
{
|
{
|
||||||
Parameters = parameters;
|
Parameters = parameters;
|
||||||
|
|
||||||
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
|
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
|
||||||
|
if (parameters.BuildMode == EBuildMode.DryRunBuild)
|
||||||
|
PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}";
|
||||||
|
else if (parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||||
|
PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -48,24 +53,29 @@ namespace YooAsset.Editor
|
|||||||
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
|
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
|
||||||
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
|
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
|
||||||
|
|
||||||
|
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
|
||||||
|
{
|
||||||
|
opt |= BuildAssetBundleOptions.DryRunBuild;
|
||||||
|
return opt;
|
||||||
|
}
|
||||||
|
|
||||||
if (Parameters.CompressOption == ECompressOption.Uncompressed)
|
if (Parameters.CompressOption == ECompressOption.Uncompressed)
|
||||||
opt |= BuildAssetBundleOptions.UncompressedAssetBundle;
|
opt |= BuildAssetBundleOptions.UncompressedAssetBundle;
|
||||||
else if (Parameters.CompressOption == ECompressOption.LZ4)
|
else if (Parameters.CompressOption == ECompressOption.LZ4)
|
||||||
opt |= BuildAssetBundleOptions.ChunkBasedCompression;
|
opt |= BuildAssetBundleOptions.ChunkBasedCompression;
|
||||||
|
|
||||||
if (Parameters.ForceRebuild)
|
if (Parameters.BuildMode == EBuildMode.ForceRebuild)
|
||||||
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
|
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
|
||||||
if (Parameters.AppendHash)
|
|
||||||
opt |= BuildAssetBundleOptions.AppendHashToAssetBundleName; //Append the hash to the assetBundle name
|
|
||||||
if (Parameters.DisableWriteTypeTree)
|
if (Parameters.DisableWriteTypeTree)
|
||||||
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
|
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
|
||||||
if (Parameters.IgnoreTypeTreeChanges)
|
if (Parameters.IgnoreTypeTreeChanges)
|
||||||
opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check.
|
opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check.
|
||||||
if (Parameters.DisableLoadAssetByFileName)
|
|
||||||
{
|
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
|
||||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
|
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
|
||||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
|
|
||||||
}
|
|
||||||
|
|
||||||
return opt;
|
return opt;
|
||||||
}
|
}
|
||||||
@@ -73,9 +83,9 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取构建的耗时(单位:秒)
|
/// 获取构建的耗时(单位:秒)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int GetBuildingSeconds()
|
public float GetBuildingSeconds()
|
||||||
{
|
{
|
||||||
int seconds = (int)(_buildWatch.ElapsedMilliseconds / 1000);
|
float seconds = _buildWatch.ElapsedMilliseconds / 1000f;
|
||||||
return seconds;
|
return seconds;
|
||||||
}
|
}
|
||||||
public void BeginWatch()
|
public void BeginWatch()
|
||||||
@@ -107,7 +117,8 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
new TaskPrepare(), //前期准备工作
|
new TaskPrepare(), //前期准备工作
|
||||||
new TaskGetBuildMap(), //获取构建列表
|
new TaskGetBuildMap(), //获取构建列表
|
||||||
new TaskBuilding(), //开始执行构建
|
new TaskBuilding(), //开始执行构建
|
||||||
|
new TaskVerifyBuildResult(), //验证构建结果
|
||||||
new TaskEncryption(), //加密资源文件
|
new TaskEncryption(), //加密资源文件
|
||||||
new TaskCreatePatchManifest(), //创建清单文件
|
new TaskCreatePatchManifest(), //创建清单文件
|
||||||
new TaskCreateReport(), //创建报告文件
|
new TaskCreateReport(), //创建报告文件
|
||||||
@@ -115,11 +126,16 @@ namespace YooAsset.Editor
|
|||||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (buildParameters.BuildMode == EBuildMode.SimulateBuild)
|
||||||
|
BuildRunner.EnableLog = false;
|
||||||
|
else
|
||||||
|
BuildRunner.EnableLog = true;
|
||||||
|
|
||||||
bool succeed = BuildRunner.Run(pipeline, _buildContext);
|
bool succeed = BuildRunner.Run(pipeline, _buildContext);
|
||||||
if (succeed)
|
if (succeed)
|
||||||
Debug.Log($"构建成功!");
|
Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !");
|
||||||
else
|
else
|
||||||
Debug.LogWarning($"构建失败!");
|
Debug.LogWarning($"{buildParameters.BuildMode} pipeline build failed !");
|
||||||
return succeed;
|
return succeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,11 +117,11 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 从输出目录加载补丁清单文件
|
/// 加载补丁清单文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static PatchManifest LoadPatchManifestFile(string fileDirectory)
|
internal static PatchManifest LoadPatchManifestFile(string fileDirectory, int resourceVersion)
|
||||||
{
|
{
|
||||||
string filePath = $"{fileDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string filePath = $"{fileDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||||
if (File.Exists(filePath) == false)
|
if (File.Exists(filePath) == false)
|
||||||
{
|
{
|
||||||
throw new System.Exception($"Not found patch manifest file : {filePath}");
|
throw new System.Exception($"Not found patch manifest file : {filePath}");
|
||||||
@@ -130,5 +130,16 @@ namespace YooAsset.Editor
|
|||||||
string jsonData = FileUtility.ReadFile(filePath);
|
string jsonData = FileUtility.ReadFile(filePath);
|
||||||
return PatchManifest.Deserialize(jsonData);
|
return PatchManifest.Deserialize(jsonData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取旧的补丁清单
|
||||||
|
/// </summary>
|
||||||
|
internal static PatchManifest GetOldPatchManifest(string pipelineOutputDirectory)
|
||||||
|
{
|
||||||
|
string staticVersionFilePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
|
||||||
|
string staticVersionContent = FileUtility.ReadFile(staticVersionFilePath);
|
||||||
|
int staticVersion = int.Parse(staticVersionContent);
|
||||||
|
return LoadPatchManifestFile(pipelineOutputDirectory, staticVersion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public class AssetBundleBuilderSetting : ScriptableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 构建版本号
|
||||||
|
/// </summary>
|
||||||
|
public int BuildVersion = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建模式
|
||||||
|
/// </summary>
|
||||||
|
public EBuildMode BuildMode = EBuildMode.ForceRebuild;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 内置资源标签
|
||||||
|
/// </summary>
|
||||||
|
public string BuildTags = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 压缩方式
|
||||||
|
/// </summary>
|
||||||
|
public ECompressOption CompressOption = ECompressOption.LZ4;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加密类名称
|
||||||
|
/// </summary>
|
||||||
|
public string EncyptionClassName = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 附加后缀格式
|
||||||
|
/// </summary>
|
||||||
|
public bool AppendExtension = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 09788b4733bab2d4792fdd5d28e7653c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public class AssetBundleBuilderSettingData
|
||||||
|
{
|
||||||
|
private static AssetBundleBuilderSetting _setting = null;
|
||||||
|
public static AssetBundleBuilderSetting Setting
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_setting == null)
|
||||||
|
LoadSettingData();
|
||||||
|
return _setting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载配置文件
|
||||||
|
/// </summary>
|
||||||
|
private static void LoadSettingData()
|
||||||
|
{
|
||||||
|
_setting = YooAssetEditorSettingsHelper.LoadSettingData<AssetBundleBuilderSetting>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 存储文件
|
||||||
|
/// </summary>
|
||||||
|
public static void SaveFile()
|
||||||
|
{
|
||||||
|
if (Setting != null)
|
||||||
|
{
|
||||||
|
EditorUtility.SetDirty(Setting);
|
||||||
|
AssetDatabase.SaveAssets();
|
||||||
|
Debug.Log($"{nameof(AssetBundleBuilderSetting)}.asset is saved!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 24698266f028e4a47bb88f091fd64547
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -14,8 +14,7 @@ namespace YooAsset.Editor
|
|||||||
[MenuItem("YooAsset/AssetBundle Builder", false, 102)]
|
[MenuItem("YooAsset/AssetBundle Builder", false, 102)]
|
||||||
public static void ShowExample()
|
public static void ShowExample()
|
||||||
{
|
{
|
||||||
AssetBundleBuilderWindow window = GetWindow<AssetBundleBuilderWindow>();
|
AssetBundleBuilderWindow window = GetWindow<AssetBundleBuilderWindow>("资源包构建工具", true, EditorDefine.DockedWindowTypes);
|
||||||
window.titleContent = new GUIContent("资源包构建工具");
|
|
||||||
window.minSize = new Vector2(800, 600);
|
window.minSize = new Vector2(800, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,32 +22,29 @@ namespace YooAsset.Editor
|
|||||||
private List<Type> _encryptionServicesClassTypes;
|
private List<Type> _encryptionServicesClassTypes;
|
||||||
private List<string> _encryptionServicesClassNames;
|
private List<string> _encryptionServicesClassNames;
|
||||||
|
|
||||||
private TextField _buildOutputTxt;
|
private TextField _buildOutputField;
|
||||||
private IntegerField _buildVersionField;
|
private IntegerField _buildVersionField;
|
||||||
private EnumField _compressionField;
|
private EnumField _buildModeField;
|
||||||
|
private TextField _buildTagsField;
|
||||||
private PopupField<string> _encryptionField;
|
private PopupField<string> _encryptionField;
|
||||||
|
private EnumField _compressionField;
|
||||||
private Toggle _appendExtensionToggle;
|
private Toggle _appendExtensionToggle;
|
||||||
private Toggle _forceRebuildToggle;
|
|
||||||
private TextField _buildTagsTxt;
|
|
||||||
|
|
||||||
|
|
||||||
public void CreateGUI()
|
public void CreateGUI()
|
||||||
{
|
{
|
||||||
VisualElement root = this.rootVisualElement;
|
|
||||||
|
|
||||||
// 加载布局文件
|
|
||||||
string rootPath = EditorTools.GetYooAssetPath();
|
|
||||||
string uxml = $"{rootPath}/Editor/AssetBundleBuilder/{nameof(AssetBundleBuilderWindow)}.uxml";
|
|
||||||
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
|
||||||
if (visualAsset == null)
|
|
||||||
{
|
|
||||||
Debug.LogError($"Not found {nameof(AssetBundleBuilderWindow)}.uxml : {uxml}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
visualAsset.CloneTree(root);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
VisualElement root = this.rootVisualElement;
|
||||||
|
|
||||||
|
// 加载布局文件
|
||||||
|
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleBuilderUXML;
|
||||||
|
if (visualAsset == null)
|
||||||
|
{
|
||||||
|
Debug.LogError($"Not found {nameof(AssetBundleBuilderWindow)}.uxml in settings.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
visualAsset.CloneTree(root);
|
||||||
|
|
||||||
_buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
_buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||||
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
|
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
|
||||||
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
|
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
|
||||||
@@ -56,28 +52,49 @@ namespace YooAsset.Editor
|
|||||||
// 输出目录
|
// 输出目录
|
||||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||||
string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(defaultOutputRoot, _buildTarget);
|
string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(defaultOutputRoot, _buildTarget);
|
||||||
_buildOutputTxt = root.Q<TextField>("BuildOutput");
|
_buildOutputField = root.Q<TextField>("BuildOutput");
|
||||||
_buildOutputTxt.SetValueWithoutNotify(pipelineOutputDirectory);
|
_buildOutputField.SetValueWithoutNotify(pipelineOutputDirectory);
|
||||||
_buildOutputTxt.SetEnabled(false);
|
_buildOutputField.SetEnabled(false);
|
||||||
|
|
||||||
// 构建版本
|
// 构建版本
|
||||||
var appVersion = new Version(Application.version);
|
|
||||||
_buildVersionField = root.Q<IntegerField>("BuildVersion");
|
_buildVersionField = root.Q<IntegerField>("BuildVersion");
|
||||||
_buildVersionField.SetValueWithoutNotify(appVersion.Revision);
|
_buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion);
|
||||||
|
_buildVersionField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
|
||||||
|
});
|
||||||
|
|
||||||
// 压缩方式
|
// 构建模式
|
||||||
_compressionField = root.Q<EnumField>("Compression");
|
_buildModeField = root.Q<EnumField>("BuildMode");
|
||||||
_compressionField.Init(ECompressOption.LZ4);
|
_buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode);
|
||||||
_compressionField.SetValueWithoutNotify(ECompressOption.LZ4);
|
_buildModeField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildMode);
|
||||||
_compressionField.style.width = 300;
|
_buildModeField.style.width = 300;
|
||||||
|
_buildModeField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value;
|
||||||
|
RefreshWindow();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 内置资源标签
|
||||||
|
_buildTagsField = root.Q<TextField>("BuildinTags");
|
||||||
|
_buildTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
|
||||||
|
_buildTagsField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.BuildTags = _buildTagsField.value;
|
||||||
|
});
|
||||||
|
|
||||||
// 加密方法
|
// 加密方法
|
||||||
var encryptionContainer = root.Q("EncryptionContainer");
|
var encryptionContainer = root.Q("EncryptionContainer");
|
||||||
if (_encryptionServicesClassNames.Count > 0)
|
if (_encryptionServicesClassNames.Count > 0)
|
||||||
{
|
{
|
||||||
_encryptionField = new PopupField<string>(_encryptionServicesClassNames, 0);
|
int defaultIndex = GetEncryptionDefaultIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName);
|
||||||
|
_encryptionField = new PopupField<string>(_encryptionServicesClassNames, defaultIndex);
|
||||||
_encryptionField.label = "Encryption";
|
_encryptionField.label = "Encryption";
|
||||||
_encryptionField.style.width = 300;
|
_encryptionField.style.width = 300;
|
||||||
|
_encryptionField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value;
|
||||||
|
});
|
||||||
encryptionContainer.Add(_encryptionField);
|
encryptionContainer.Add(_encryptionField);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -88,46 +105,52 @@ namespace YooAsset.Editor
|
|||||||
encryptionContainer.Add(_encryptionField);
|
encryptionContainer.Add(_encryptionField);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 附加后缀格式
|
// 压缩方式
|
||||||
_appendExtensionToggle = root.Q<Toggle>("AppendExtension");
|
_compressionField = root.Q<EnumField>("Compression");
|
||||||
|
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||||
// 强制构建
|
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||||
_forceRebuildToggle = root.Q<Toggle>("ForceRebuild");
|
_compressionField.style.width = 300;
|
||||||
_forceRebuildToggle.SetValueWithoutNotify(true);
|
_compressionField.RegisterValueChangedCallback(evt =>
|
||||||
_forceRebuildToggle.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
{
|
||||||
_buildTagsTxt.SetEnabled(_forceRebuildToggle.value);
|
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 内置标签
|
// 附加后缀格式
|
||||||
_buildTagsTxt = root.Q<TextField>("BuildinTags");
|
_appendExtensionToggle = root.Q<Toggle>("AppendExtension");
|
||||||
_buildTagsTxt.SetEnabled(_forceRebuildToggle.value);
|
_appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension);
|
||||||
|
_appendExtensionToggle.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value;
|
||||||
|
});
|
||||||
|
|
||||||
// 构建按钮
|
// 构建按钮
|
||||||
var buildButton = root.Q<Button>("Build");
|
var buildButton = root.Q<Button>("Build");
|
||||||
buildButton.clicked += BuildButton_clicked; ;
|
buildButton.clicked += BuildButton_clicked; ;
|
||||||
|
|
||||||
|
RefreshWindow();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogError(e.ToString());
|
Debug.LogError(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void OnDestroy()
|
||||||
|
{
|
||||||
|
AssetBundleBuilderSettingData.SaveFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshWindow()
|
||||||
|
{
|
||||||
|
bool enableElement = AssetBundleBuilderSettingData.Setting.BuildMode == EBuildMode.ForceRebuild;
|
||||||
|
_buildTagsField.SetEnabled(enableElement);
|
||||||
|
_encryptionField.SetEnabled(enableElement);
|
||||||
|
_compressionField.SetEnabled(enableElement);
|
||||||
|
_appendExtensionToggle.SetEnabled(enableElement);
|
||||||
|
}
|
||||||
private void BuildButton_clicked()
|
private void BuildButton_clicked()
|
||||||
{
|
{
|
||||||
string title;
|
var buildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
|
||||||
string content;
|
if (EditorUtility.DisplayDialog("提示", $"通过构建模式【{buildMode}】来构建!", "Yes", "No"))
|
||||||
if (_forceRebuildToggle.value)
|
|
||||||
{
|
|
||||||
title = "警告";
|
|
||||||
content = "确定开始强制构建吗,这样会删除所有已有构建的文件";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
title = "提示";
|
|
||||||
content = "确定开始增量构建吗";
|
|
||||||
}
|
|
||||||
if (EditorUtility.DisplayDialog(title, content, "Yes", "No"))
|
|
||||||
{
|
{
|
||||||
EditorTools.ClearUnityConsole();
|
EditorTools.ClearUnityConsole();
|
||||||
EditorApplication.delayCall += ExecuteBuild;
|
EditorApplication.delayCall += ExecuteBuild;
|
||||||
@@ -145,32 +168,37 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||||
BuildParameters buildParameters = new BuildParameters();
|
BuildParameters buildParameters = new BuildParameters();
|
||||||
buildParameters.VerifyBuildingResult = true;
|
|
||||||
buildParameters.OutputRoot = defaultOutputRoot;
|
buildParameters.OutputRoot = defaultOutputRoot;
|
||||||
buildParameters.BuildTarget = _buildTarget;
|
buildParameters.BuildTarget = _buildTarget;
|
||||||
|
buildParameters.BuildMode = (EBuildMode)_buildModeField.value;
|
||||||
buildParameters.BuildVersion = _buildVersionField.value;
|
buildParameters.BuildVersion = _buildVersionField.value;
|
||||||
buildParameters.CompressOption = (ECompressOption)_compressionField.value;
|
buildParameters.BuildinTags = _buildTagsField.value;
|
||||||
|
buildParameters.VerifyBuildingResult = true;
|
||||||
|
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
|
||||||
buildParameters.AppendFileExtension = _appendExtensionToggle.value;
|
buildParameters.AppendFileExtension = _appendExtensionToggle.value;
|
||||||
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
|
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
|
||||||
buildParameters.ForceRebuild = _forceRebuildToggle.value;
|
buildParameters.CompressOption = (ECompressOption)_compressionField.value;
|
||||||
buildParameters.BuildinTags = _buildTagsTxt.value;
|
|
||||||
|
|
||||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||||
builder.Run(buildParameters);
|
builder.Run(buildParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
// 加密类相关
|
||||||
/// 获取加密类的类型列表
|
private int GetEncryptionDefaultIndex(string className)
|
||||||
/// </summary>
|
{
|
||||||
|
for (int index = 0; index < _encryptionServicesClassNames.Count; index++)
|
||||||
|
{
|
||||||
|
if (_encryptionServicesClassNames[index] == className)
|
||||||
|
{
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
private List<Type> GetEncryptionServicesClassTypes()
|
private List<Type> GetEncryptionServicesClassTypes()
|
||||||
{
|
{
|
||||||
List<Type> classTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IEncryptionServices));
|
return EditorTools.GetAssignableTypes(typeof(IEncryptionServices));
|
||||||
return classTypes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建加密类的实例
|
|
||||||
/// </summary>
|
|
||||||
private IEncryptionServices CreateEncryptionServicesInstance()
|
private IEncryptionServices CreateEncryptionServicesInstance()
|
||||||
{
|
{
|
||||||
if (_encryptionField.index < 0)
|
if (_encryptionField.index < 0)
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
<ui:VisualElement name="BuildContainer">
|
<ui:VisualElement name="BuildContainer">
|
||||||
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
|
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
|
||||||
<uie:IntegerField label="Build Version" value="0" name="BuildVersion" />
|
<uie:IntegerField label="Build Version" value="0" name="BuildVersion" />
|
||||||
<uie:EnumField label="Compression" value="Center" name="Compression" />
|
<uie:EnumField label="Build Mode" name="BuildMode" />
|
||||||
<ui:VisualElement name="EncryptionContainer" style="height: 24px;" />
|
<ui:VisualElement name="EncryptionContainer" style="height: 24px;" />
|
||||||
|
<uie:EnumField label="Compression" value="Center" name="Compression" />
|
||||||
<ui:Toggle label="Append Extension" name="AppendExtension" style="height: 15px;" />
|
<ui:Toggle label="Append Extension" name="AppendExtension" style="height: 15px;" />
|
||||||
<ui:Toggle label="Force Rebuild" name="ForceRebuild" />
|
|
||||||
<ui:TextField picking-mode="Ignore" label="Buildin Tags" name="BuildinTags" />
|
<ui:TextField picking-mode="Ignore" label="Buildin Tags" name="BuildinTags" />
|
||||||
<ui:Button text="构建" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
|
<ui:Button text="构建" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public static class AssetBundleSimulateBuilder
|
||||||
|
{
|
||||||
|
private static string _manifestFilePath = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模拟构建
|
||||||
|
/// </summary>
|
||||||
|
public static void SimulateBuild()
|
||||||
|
{
|
||||||
|
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||||
|
BuildParameters buildParameters = new BuildParameters();
|
||||||
|
buildParameters.OutputRoot = defaultOutputRoot;
|
||||||
|
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||||
|
buildParameters.BuildMode = EBuildMode.SimulateBuild;
|
||||||
|
buildParameters.BuildVersion = 999;
|
||||||
|
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
|
||||||
|
|
||||||
|
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||||
|
bool buildResult = builder.Run(buildParameters);
|
||||||
|
if (buildResult)
|
||||||
|
{
|
||||||
|
string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildTarget);
|
||||||
|
_manifestFilePath = $"{pipelineOutputDirectory}_{EBuildMode.SimulateBuild}/{YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildVersion)}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_manifestFilePath = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取构建的补丁清单路径
|
||||||
|
/// </summary>
|
||||||
|
public static string GetPatchManifestPath()
|
||||||
|
{
|
||||||
|
return _manifestFilePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f94918fa1ea63c34fa0e49fdad4119cf
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,15 +1,26 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public class BuildAssetInfo
|
public class BuildAssetInfo
|
||||||
{
|
{
|
||||||
|
private string _mainBundleName;
|
||||||
|
private string _shareBundleName;
|
||||||
|
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
|
||||||
|
private bool _isAddAssetTags = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包名称
|
/// 收集器类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BundleName { private set; get; }
|
public ECollectorType CollectorType { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 可寻址地址
|
||||||
|
/// </summary>
|
||||||
|
public string Address { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源路径
|
/// 资源路径
|
||||||
@@ -22,25 +33,20 @@ namespace YooAsset.Editor
|
|||||||
public bool IsRawAsset { private set; get; }
|
public bool IsRawAsset { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 不写入资源列表
|
/// 是否为着色器资源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool NotWriteToAssetList { private set; get; }
|
public bool IsShaderAsset { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否为主动收集资源
|
/// 资源的分类标签
|
||||||
/// </summary>
|
|
||||||
public bool IsCollectAsset { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 被依赖次数
|
|
||||||
/// </summary>
|
|
||||||
public int DependCount = 0;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源分类标签列表
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly List<string> AssetTags = new List<string>();
|
public readonly List<string> AssetTags = new List<string>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源包的分类标签
|
||||||
|
/// </summary>
|
||||||
|
public readonly List<string> BundleTags = new List<string>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 依赖的所有资源
|
/// 依赖的所有资源
|
||||||
/// 注意:包括零依赖资源和冗余资源(资源包名无效)
|
/// 注意:包括零依赖资源和冗余资源(资源包名无效)
|
||||||
@@ -48,21 +54,35 @@ namespace YooAsset.Editor
|
|||||||
public List<BuildAssetInfo> AllDependAssetInfos { private set; get; }
|
public List<BuildAssetInfo> AllDependAssetInfos { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
public BuildAssetInfo(string assetPath, bool isRawAsset, bool notWriteToAssetList)
|
public BuildAssetInfo(ECollectorType collectorType, string mainBundleName, string address, string assetPath, bool isRawAsset)
|
||||||
{
|
{
|
||||||
|
_mainBundleName = mainBundleName;
|
||||||
|
CollectorType = collectorType;
|
||||||
|
Address = address;
|
||||||
AssetPath = assetPath;
|
AssetPath = assetPath;
|
||||||
IsRawAsset = isRawAsset;
|
IsRawAsset = isRawAsset;
|
||||||
NotWriteToAssetList = notWriteToAssetList;
|
|
||||||
IsCollectAsset = true;
|
System.Type assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||||
|
if (assetType == typeof(UnityEngine.Shader))
|
||||||
|
IsShaderAsset = true;
|
||||||
|
else
|
||||||
|
IsShaderAsset = false;
|
||||||
}
|
}
|
||||||
public BuildAssetInfo(string assetPath)
|
public BuildAssetInfo(ECollectorType collectorType, string assetPath)
|
||||||
{
|
{
|
||||||
|
CollectorType = collectorType;
|
||||||
|
Address = string.Empty;
|
||||||
AssetPath = assetPath;
|
AssetPath = assetPath;
|
||||||
IsRawAsset = false;
|
IsRawAsset = false;
|
||||||
NotWriteToAssetList = true;
|
|
||||||
IsCollectAsset = false;
|
System.Type assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||||
|
if (assetType == typeof(UnityEngine.Shader))
|
||||||
|
IsShaderAsset = true;
|
||||||
|
else
|
||||||
|
IsShaderAsset = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置所有依赖的资源
|
/// 设置所有依赖的资源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -75,47 +95,117 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置资源包名称
|
/// 添加资源的分类标签
|
||||||
/// </summary>
|
/// 说明:原始定义的资源分类标签
|
||||||
public void SetBundleName(string bundleName)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(BundleName) == false)
|
|
||||||
throw new System.Exception("Should never get here !");
|
|
||||||
|
|
||||||
BundleName = bundleName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 添加资源分类标签
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddAssetTags(List<string> tags)
|
public void AddAssetTags(List<string> tags)
|
||||||
{
|
{
|
||||||
|
if (_isAddAssetTags)
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
_isAddAssetTags = true;
|
||||||
|
|
||||||
foreach (var tag in tags)
|
foreach (var tag in tags)
|
||||||
{
|
{
|
||||||
AddAssetTag(tag);
|
if (AssetTags.Contains(tag) == false)
|
||||||
|
{
|
||||||
|
AssetTags.Add(tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 添加资源分类标签
|
/// 添加资源包的分类标签
|
||||||
|
/// 说明:传染算法统计到的分类标签
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void AddAssetTag(string tag)
|
public void AddBundleTags(List<string> tags)
|
||||||
{
|
{
|
||||||
if (AssetTags.Contains(tag) == false)
|
foreach (var tag in tags)
|
||||||
{
|
{
|
||||||
AssetTags.Add(tag);
|
if (BundleTags.Contains(tag) == false)
|
||||||
|
{
|
||||||
|
BundleTags.Add(tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包名称是否有效
|
/// 资源包名是否存在
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool BundleNameIsValid()
|
public bool HasBundleName()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(BundleName))
|
string bundleName = GetBundleName();
|
||||||
|
if (string.IsNullOrEmpty(bundleName))
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源包名称
|
||||||
|
/// </summary>
|
||||||
|
public string GetBundleName()
|
||||||
|
{
|
||||||
|
if (CollectorType == ECollectorType.None)
|
||||||
|
return _shareBundleName;
|
||||||
|
else
|
||||||
|
return _mainBundleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加关联的资源包名称
|
||||||
|
/// </summary>
|
||||||
|
public void AddReferenceBundleName(string bundleName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(bundleName))
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
if (_referenceBundleNames.Contains(bundleName) == false)
|
||||||
|
_referenceBundleNames.Add(bundleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 计算主资源或共享资源的完整包名
|
||||||
|
/// </summary>
|
||||||
|
public void CalculateFullBundleName()
|
||||||
|
{
|
||||||
|
if (CollectorType == ECollectorType.None)
|
||||||
|
{
|
||||||
|
if (IsRawAsset)
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders)
|
||||||
|
{
|
||||||
|
if (IsShaderAsset)
|
||||||
|
{
|
||||||
|
string shareBundleName = $"{AssetBundleCollectorSettingData.Setting.ShadersBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||||
|
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_referenceBundleNames.Count > 1)
|
||||||
|
{
|
||||||
|
var bundleNameList = _referenceBundleNames.ToList();
|
||||||
|
bundleNameList.Sort();
|
||||||
|
string combineName = string.Join("|", bundleNameList);
|
||||||
|
var combineNameHash = HashUtility.StringSHA1(combineName);
|
||||||
|
var shareBundleName = $"share_{combineNameHash}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||||
|
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (IsRawAsset)
|
||||||
|
{
|
||||||
|
string mainBundleName = $"{_mainBundleName}.{YooAssetSettingsData.Setting.RawFileVariant}";
|
||||||
|
_mainBundleName = EditorTools.GetRegularPath(mainBundleName).ToLower();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string mainBundleName = $"{_mainBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||||
|
_mainBundleName = EditorTools.GetRegularPath(mainBundleName).ToLower(); ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,14 +68,14 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源标签列表
|
/// 获取资源包的分类标签列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] GetAssetTags()
|
public string[] GetBundleTags()
|
||||||
{
|
{
|
||||||
List<string> result = new List<string>(BuildinAssets.Count);
|
List<string> result = new List<string>(BuildinAssets.Count);
|
||||||
foreach (var assetInfo in BuildinAssets)
|
foreach (var assetInfo in BuildinAssets)
|
||||||
{
|
{
|
||||||
foreach (var assetTag in assetInfo.AssetTags)
|
foreach (var assetTag in assetInfo.BundleTags)
|
||||||
{
|
{
|
||||||
if (result.Contains(assetTag) == false)
|
if (result.Contains(assetTag) == false)
|
||||||
result.Add(assetTag);
|
result.Add(assetTag);
|
||||||
@@ -105,7 +105,7 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public BuildAssetInfo[] GetAllPatchAssetInfos()
|
public BuildAssetInfo[] GetAllPatchAssetInfos()
|
||||||
{
|
{
|
||||||
return BuildinAssets.Where(t => t.IsCollectAsset && t.NotWriteToAssetList == false).ToArray();
|
return BuildinAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -25,13 +25,17 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void PackAsset(BuildAssetInfo assetInfo)
|
public void PackAsset(BuildAssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (TryGetBundleInfo(assetInfo.BundleName, out BuildBundleInfo bundleInfo))
|
string bundleName = assetInfo.GetBundleName();
|
||||||
|
if (string.IsNullOrEmpty(bundleName))
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
|
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
|
||||||
{
|
{
|
||||||
bundleInfo.PackAsset(assetInfo);
|
bundleInfo.PackAsset(assetInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BuildBundleInfo newBundleInfo = new BuildBundleInfo(assetInfo.BundleName);
|
BuildBundleInfo newBundleInfo = new BuildBundleInfo(bundleName);
|
||||||
newBundleInfo.PackAsset(assetInfo);
|
newBundleInfo.PackAsset(assetInfo);
|
||||||
BundleInfos.Add(newBundleInfo);
|
BundleInfos.Add(newBundleInfo);
|
||||||
}
|
}
|
||||||
@@ -51,13 +55,13 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取AssetBundle内包含的标记列表
|
/// 获取资源包的分类标签列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] GetAssetTags(string bundleName)
|
public string[] GetBundleTags(string bundleName)
|
||||||
{
|
{
|
||||||
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
|
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
|
||||||
{
|
{
|
||||||
return bundleInfo.GetAssetTags();
|
return bundleInfo.GetBundleTags();
|
||||||
}
|
}
|
||||||
throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}");
|
throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}");
|
||||||
}
|
}
|
||||||
|
|||||||
136
Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs
Normal file
136
Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public static class BuildMapCreater
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 执行资源构建上下文
|
||||||
|
/// </summary>
|
||||||
|
public static BuildMapContext CreateBuildMap(EBuildMode buildMode)
|
||||||
|
{
|
||||||
|
BuildMapContext context = new BuildMapContext();
|
||||||
|
Dictionary<string, BuildAssetInfo> buildAssetDic = new Dictionary<string, BuildAssetInfo>(1000);
|
||||||
|
|
||||||
|
// 1. 检测配置合法性
|
||||||
|
AssetBundleCollectorSettingData.Setting.CheckConfigError();
|
||||||
|
|
||||||
|
// 2. 获取所有收集器收集的资源
|
||||||
|
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode);
|
||||||
|
|
||||||
|
// 3. 剔除未被引用的依赖资源
|
||||||
|
List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>();
|
||||||
|
foreach (var collectAssetInfo in allCollectAssets)
|
||||||
|
{
|
||||||
|
if (collectAssetInfo.CollectorType == ECollectorType.DependAssetCollector)
|
||||||
|
{
|
||||||
|
if (IsRemoveDependAsset(allCollectAssets, collectAssetInfo.AssetPath))
|
||||||
|
removeDependList.Add(collectAssetInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var removeValue in removeDependList)
|
||||||
|
{
|
||||||
|
allCollectAssets.Remove(removeValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 录入所有收集器收集的资源
|
||||||
|
foreach (var collectAssetInfo in allCollectAssets)
|
||||||
|
{
|
||||||
|
if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
|
||||||
|
{
|
||||||
|
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.CollectorType, collectAssetInfo.BundleName,
|
||||||
|
collectAssetInfo.Address, collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset);
|
||||||
|
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
|
||||||
|
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
||||||
|
buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"Should never get here !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 录入相关依赖的资源
|
||||||
|
foreach (var collectAssetInfo in allCollectAssets)
|
||||||
|
{
|
||||||
|
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
|
||||||
|
{
|
||||||
|
if (buildAssetDic.ContainsKey(dependAssetPath))
|
||||||
|
{
|
||||||
|
buildAssetDic[dependAssetPath].AddBundleTags(collectAssetInfo.AssetTags);
|
||||||
|
buildAssetDic[dependAssetPath].AddReferenceBundleName(collectAssetInfo.BundleName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var buildAssetInfo = new BuildAssetInfo(ECollectorType.None, dependAssetPath);
|
||||||
|
buildAssetInfo.AddBundleTags(collectAssetInfo.AssetTags);
|
||||||
|
buildAssetInfo.AddReferenceBundleName(collectAssetInfo.BundleName);
|
||||||
|
buildAssetDic.Add(dependAssetPath, buildAssetInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
context.AssetFileCount = buildAssetDic.Count;
|
||||||
|
|
||||||
|
// 6. 填充主动收集资源的依赖列表
|
||||||
|
foreach (var collectAssetInfo in allCollectAssets)
|
||||||
|
{
|
||||||
|
var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count);
|
||||||
|
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
|
||||||
|
{
|
||||||
|
if (buildAssetDic.TryGetValue(dependAssetPath, out BuildAssetInfo value))
|
||||||
|
dependAssetInfos.Add(value);
|
||||||
|
else
|
||||||
|
throw new Exception("Should never get here !");
|
||||||
|
}
|
||||||
|
buildAssetDic[collectAssetInfo.AssetPath].SetAllDependAssetInfos(dependAssetInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. 计算完整的资源包名
|
||||||
|
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
||||||
|
{
|
||||||
|
pair.Value.CalculateFullBundleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 8. 移除不参与构建的资源
|
||||||
|
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
|
||||||
|
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
||||||
|
{
|
||||||
|
var buildAssetInfo = pair.Value;
|
||||||
|
if (buildAssetInfo.HasBundleName() == false)
|
||||||
|
removeBuildList.Add(buildAssetInfo);
|
||||||
|
}
|
||||||
|
foreach (var removeValue in removeBuildList)
|
||||||
|
{
|
||||||
|
buildAssetDic.Remove(removeValue.AssetPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9. 构建资源包
|
||||||
|
var allBuildinAssets = buildAssetDic.Values.ToList();
|
||||||
|
if (allBuildinAssets.Count == 0)
|
||||||
|
throw new Exception("构建的资源列表不能为空");
|
||||||
|
foreach (var assetInfo in allBuildinAssets)
|
||||||
|
{
|
||||||
|
context.PackAsset(assetInfo);
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
private static bool IsRemoveDependAsset(List<CollectAssetInfo> allCollectAssets, string dependAssetPath)
|
||||||
|
{
|
||||||
|
foreach (var collectAssetInfo in allCollectAssets)
|
||||||
|
{
|
||||||
|
var collectorType = collectAssetInfo.CollectorType;
|
||||||
|
if (collectorType == ECollectorType.MainAssetCollector || collectorType == ECollectorType.StaticAssetCollector)
|
||||||
|
{
|
||||||
|
if (collectAssetInfo.DependAssets.Contains(dependAssetPath))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BuildRunner.Log($"发现未被依赖的资源并自动移除 : {dependAssetPath}");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
|
||||||
{
|
|
||||||
public static class BuildMapHelper
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 执行资源构建上下文
|
|
||||||
/// </summary>
|
|
||||||
public static BuildMapContext SetupBuildMap()
|
|
||||||
{
|
|
||||||
BuildMapContext context = new BuildMapContext();
|
|
||||||
Dictionary<string, BuildAssetInfo> buildAssetDic = new Dictionary<string, BuildAssetInfo>();
|
|
||||||
|
|
||||||
// 0. 检测配置合法性
|
|
||||||
AssetBundleGrouperSettingData.Setting.CheckConfigError();
|
|
||||||
|
|
||||||
// 1. 获取主动收集的资源
|
|
||||||
List<CollectAssetInfo> collectAssetInfos = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets();
|
|
||||||
|
|
||||||
// 2. 录入主动收集的资源
|
|
||||||
foreach (var collectAssetInfo in collectAssetInfos)
|
|
||||||
{
|
|
||||||
if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
|
|
||||||
{
|
|
||||||
var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset, collectAssetInfo.NotWriteToAssetList);
|
|
||||||
buildAssetInfo.SetBundleName(collectAssetInfo.BundleName);
|
|
||||||
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
|
|
||||||
buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception($"Should never get here !");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 录入并分析依赖资源
|
|
||||||
foreach (var collectAssetInfo in collectAssetInfos)
|
|
||||||
{
|
|
||||||
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
|
|
||||||
{
|
|
||||||
if (buildAssetDic.ContainsKey(dependAssetPath))
|
|
||||||
{
|
|
||||||
buildAssetDic[dependAssetPath].DependCount++;
|
|
||||||
buildAssetDic[dependAssetPath].AddAssetTags(collectAssetInfo.AssetTags);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
|
|
||||||
buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
|
|
||||||
buildAssetDic.Add(dependAssetPath, buildAssetInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
context.AssetFileCount = buildAssetDic.Count;
|
|
||||||
|
|
||||||
// 4. 设置主动收集资源的依赖列表
|
|
||||||
foreach (var collectAssetInfo in collectAssetInfos)
|
|
||||||
{
|
|
||||||
var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count);
|
|
||||||
foreach (var dependAssetPath in collectAssetInfo.DependAssets)
|
|
||||||
{
|
|
||||||
if (buildAssetDic.TryGetValue(dependAssetPath, out BuildAssetInfo value))
|
|
||||||
dependAssetInfos.Add(value);
|
|
||||||
else
|
|
||||||
throw new Exception("Should never get here !");
|
|
||||||
}
|
|
||||||
buildAssetDic[collectAssetInfo.AssetPath].SetAllDependAssetInfos(dependAssetInfos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. 移除零依赖的资源
|
|
||||||
List<BuildAssetInfo> removeList = new List<BuildAssetInfo>();
|
|
||||||
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
|
||||||
{
|
|
||||||
var buildAssetInfo = pair.Value;
|
|
||||||
if (buildAssetInfo.IsCollectAsset)
|
|
||||||
continue;
|
|
||||||
if (buildAssetInfo.DependCount == 0)
|
|
||||||
removeList.Add(buildAssetInfo);
|
|
||||||
}
|
|
||||||
foreach (var removeValue in removeList)
|
|
||||||
{
|
|
||||||
buildAssetDic.Remove(removeValue.AssetPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. 设置未命名的资源包
|
|
||||||
IPackRule defaultPackRule = new PackDirectory();
|
|
||||||
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
|
||||||
{
|
|
||||||
var buildAssetInfo = pair.Value;
|
|
||||||
if (buildAssetInfo.BundleNameIsValid() == false)
|
|
||||||
{
|
|
||||||
string bundleName = defaultPackRule.GetBundleName(new PackRuleData(buildAssetInfo.AssetPath));
|
|
||||||
bundleName = AssetBundleCollector.RevisedBundleName(bundleName, false);
|
|
||||||
buildAssetInfo.SetBundleName(bundleName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 7. 构建资源包
|
|
||||||
var allBuildAssets = buildAssetDic.Values.ToList();
|
|
||||||
if (allBuildAssets.Count == 0)
|
|
||||||
throw new Exception("构建的资源列表不能为空");
|
|
||||||
foreach (var assetInfo in allBuildAssets)
|
|
||||||
{
|
|
||||||
context.PackAsset(assetInfo);
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,11 +9,6 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class BuildParameters
|
public class BuildParameters
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 验证构建结果
|
|
||||||
/// </summary>
|
|
||||||
public bool VerifyBuildingResult = false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 输出的根目录
|
/// 输出的根目录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -24,48 +19,48 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public BuildTarget BuildTarget;
|
public BuildTarget BuildTarget;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建模式
|
||||||
|
/// </summary>
|
||||||
|
public EBuildMode BuildMode;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建的版本(资源版本号)
|
/// 构建的版本(资源版本号)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BuildVersion;
|
public int BuildVersion;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 启用自动分包机制
|
|
||||||
/// 说明:自动分包机制可以实现资源零冗余
|
|
||||||
/// </summary>
|
|
||||||
public bool EnableAutoCollect = true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 追加文件扩展名
|
|
||||||
/// </summary>
|
|
||||||
public bool AppendFileExtension = false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 加密类
|
|
||||||
/// </summary>
|
|
||||||
public IEncryptionServices EncryptionServices;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 强制重新构建整个项目,如果为FALSE则是增量打包
|
|
||||||
/// </summary>
|
|
||||||
public bool ForceRebuild;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 内置资源的标记列表
|
/// 内置资源的标记列表
|
||||||
/// 注意:分号为分隔符
|
/// 注意:分号为分隔符
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BuildinTags;
|
public string BuildinTags;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 验证构建结果
|
||||||
|
/// </summary>
|
||||||
|
public bool VerifyBuildingResult = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 启用可寻址资源定位
|
||||||
|
/// </summary>
|
||||||
|
public bool EnableAddressable = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 追加文件扩展名
|
||||||
|
/// </summary>
|
||||||
|
public bool AppendFileExtension = false;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加密类
|
||||||
|
/// </summary>
|
||||||
|
public IEncryptionServices EncryptionServices = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 压缩选项
|
/// 压缩选项
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ECompressOption CompressOption;
|
public ECompressOption CompressOption = ECompressOption.Uncompressed;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 文件名附加上哈希值
|
|
||||||
/// </summary>
|
|
||||||
public bool AppendHash = false;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
|
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
|
||||||
@@ -77,11 +72,6 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IgnoreTypeTreeChanges = true;
|
public bool IgnoreTypeTreeChanges = true;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 禁用名称查找资源(可以降内存并提高加载效率)
|
|
||||||
/// </summary>
|
|
||||||
public bool DisableLoadAssetByFileName = false;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取内置标记列表
|
/// 获取内置标记列表
|
||||||
|
|||||||
@@ -7,15 +7,36 @@ namespace YooAsset.Editor
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class ReportAssetInfo
|
public class ReportAssetInfo
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 可寻址地址
|
||||||
|
/// </summary>
|
||||||
|
public string Address;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源路径
|
/// 资源路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string AssetPath;
|
public string AssetPath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源GUID
|
||||||
|
/// 说明:Meta文件记录的GUID
|
||||||
|
/// </summary>
|
||||||
|
public string AssetGUID;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源的分类标签
|
||||||
|
/// </summary>
|
||||||
|
public string[] AssetTags;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所属资源包名称
|
/// 所属资源包名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string MainBundle;
|
public string MainBundleName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 所属资源包的大小
|
||||||
|
/// </summary>
|
||||||
|
public long MainBundleSize;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 依赖的资源包名称列表
|
/// 依赖的资源包名称列表
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@@ -7,6 +8,21 @@ namespace YooAsset.Editor
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class ReportBundleInfo
|
public class ReportBundleInfo
|
||||||
{
|
{
|
||||||
|
public class FlagsData
|
||||||
|
{
|
||||||
|
public bool IsEncrypted { private set; get; }
|
||||||
|
public bool IsBuildin { private set; get; }
|
||||||
|
public bool IsRawFile { private set; get; }
|
||||||
|
public FlagsData(bool isEncrypted, bool isBuildin, bool isRawFile)
|
||||||
|
{
|
||||||
|
IsEncrypted = isEncrypted;
|
||||||
|
IsBuildin = isBuildin;
|
||||||
|
IsRawFile = isRawFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private FlagsData _flagData;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包名称
|
/// 资源包名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -27,11 +43,6 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long SizeBytes;
|
public long SizeBytes;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 文件版本
|
|
||||||
/// </summary>
|
|
||||||
public int Version;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tags
|
/// Tags
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -41,5 +52,44 @@ namespace YooAsset.Editor
|
|||||||
/// Flags
|
/// Flags
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Flags;
|
public int Flags;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取标志位的解析数据
|
||||||
|
/// </summary>
|
||||||
|
public FlagsData GetFlagData()
|
||||||
|
{
|
||||||
|
if (_flagData == null)
|
||||||
|
{
|
||||||
|
BitMask32 value = Flags;
|
||||||
|
bool isEncrypted = value.Test(0);
|
||||||
|
bool isBuildin = value.Test(1);
|
||||||
|
bool isRawFile = value.Test(2);
|
||||||
|
_flagData = new FlagsData(isEncrypted, isBuildin, isRawFile);
|
||||||
|
}
|
||||||
|
return _flagData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源分类标签的字符串
|
||||||
|
/// </summary>
|
||||||
|
public string GetTagsString()
|
||||||
|
{
|
||||||
|
if (Tags != null)
|
||||||
|
return String.Join(";", Tags);
|
||||||
|
else
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否为原生文件
|
||||||
|
/// </summary>
|
||||||
|
public bool IsRawFile()
|
||||||
|
{
|
||||||
|
if (System.IO.Path.GetExtension(BundleName) == $".{YooAssetSettingsData.Setting.RawFileVariant}")
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,15 +28,25 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public BuildTarget BuildTarget;
|
public BuildTarget BuildTarget;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构建模式
|
||||||
|
/// </summary>
|
||||||
|
public EBuildMode BuildMode;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构建版本
|
/// 构建版本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BuildVersion;
|
public int BuildVersion;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 启用自动分包机制
|
/// 内置资源标签
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool EnableAutoCollect;
|
public string BuildinTags;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 启用可寻址资源定位
|
||||||
|
/// </summary>
|
||||||
|
public bool EnableAddressable;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 追加文件扩展名
|
/// 追加文件扩展名
|
||||||
@@ -59,13 +69,9 @@ namespace YooAsset.Editor
|
|||||||
public string EncryptionServicesClassName;
|
public string EncryptionServicesClassName;
|
||||||
|
|
||||||
// 构建参数
|
// 构建参数
|
||||||
public bool ForceRebuild;
|
|
||||||
public string BuildinTags;
|
|
||||||
public ECompressOption CompressOption;
|
public ECompressOption CompressOption;
|
||||||
public bool AppendHash;
|
|
||||||
public bool DisableWriteTypeTree;
|
public bool DisableWriteTypeTree;
|
||||||
public bool IgnoreTypeTreeChanges;
|
public bool IgnoreTypeTreeChanges;
|
||||||
public bool DisableLoadAssetByFileName;
|
|
||||||
|
|
||||||
// 构建结果
|
// 构建结果
|
||||||
public int AssetFileTotalCount;
|
public int AssetFileTotalCount;
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public class BuildRunner
|
public class BuildRunner
|
||||||
{
|
{
|
||||||
|
public static bool EnableLog = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 执行构建流程
|
/// 执行构建流程
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -24,11 +27,14 @@ namespace YooAsset.Editor
|
|||||||
IBuildTask task = pipeline[i];
|
IBuildTask task = pipeline[i];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var taskAttribute = task.GetType().GetCustomAttribute<TaskAttribute>();
|
||||||
|
Log($"---------------------------------------->{taskAttribute.Desc}");
|
||||||
task.Run(context);
|
task.Run(context);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogError($"Build task {task.GetType().Name} failed : {e}");
|
Debug.LogError($"Build task {task.GetType().Name} failed !");
|
||||||
|
Debug.LogError($"Build error : {e}");
|
||||||
succeed = false;
|
succeed = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -37,5 +43,24 @@ namespace YooAsset.Editor
|
|||||||
// 返回运行结果
|
// 返回运行结果
|
||||||
return succeed;
|
return succeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 日志输出
|
||||||
|
/// </summary>
|
||||||
|
public static void Log(string info)
|
||||||
|
{
|
||||||
|
if (EnableLog)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.Log(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 日志输出
|
||||||
|
/// </summary>
|
||||||
|
public static void Info(string info)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.Log(info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
|
public class TaskAttribute : Attribute
|
||||||
|
{
|
||||||
|
public string Desc;
|
||||||
|
public TaskAttribute(string desc)
|
||||||
|
{
|
||||||
|
Desc = desc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 35749e57d9a3da84aa60c348bc6bbe9d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -8,6 +8,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
|
[TaskAttribute("资源构建内容打包")]
|
||||||
public class TaskBuilding : IBuildTask
|
public class TaskBuilding : IBuildTask
|
||||||
{
|
{
|
||||||
public class UnityManifestContext : IContextObject
|
public class UnityManifestContext : IContextObject
|
||||||
@@ -20,175 +21,45 @@ namespace YooAsset.Editor
|
|||||||
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
|
|
||||||
Debug.Log($"开始构建......");
|
// 模拟构建模式下跳过引擎构建
|
||||||
|
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||||
|
if (buildMode == EBuildMode.SimulateBuild)
|
||||||
|
return;
|
||||||
|
|
||||||
BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions();
|
BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions();
|
||||||
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(buildParametersContext.PipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), opt, buildParametersContext.Parameters.BuildTarget);
|
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(buildParametersContext.PipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), opt, buildParametersContext.Parameters.BuildTarget);
|
||||||
if (unityManifest == null)
|
if (unityManifest == null)
|
||||||
throw new Exception("构建过程中发生错误!");
|
throw new Exception("构建过程中发生错误!");
|
||||||
|
|
||||||
|
BuildRunner.Log("Unity引擎打包成功!");
|
||||||
UnityManifestContext unityManifestContext = new UnityManifestContext();
|
UnityManifestContext unityManifestContext = new UnityManifestContext();
|
||||||
unityManifestContext.UnityManifest = unityManifest;
|
unityManifestContext.UnityManifest = unityManifest;
|
||||||
context.SetContextObject(unityManifestContext);
|
context.SetContextObject(unityManifestContext);
|
||||||
|
|
||||||
// 拷贝原生文件
|
// 拷贝原生文件
|
||||||
|
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||||
|
{
|
||||||
|
CopyRawBundle(buildMapContext, buildParametersContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 拷贝原生文件
|
||||||
|
/// </summary>
|
||||||
|
private void CopyRawBundle(BuildMapContext buildMapContext, AssetBundleBuilder.BuildParametersContext buildParametersContext)
|
||||||
|
{
|
||||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
{
|
{
|
||||||
if (bundleInfo.IsRawFile)
|
if (bundleInfo.IsRawFile)
|
||||||
{
|
{
|
||||||
string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
|
string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||||
foreach(var buildAsset in bundleInfo.BuildinAssets)
|
foreach (var buildAsset in bundleInfo.BuildinAssets)
|
||||||
{
|
{
|
||||||
if(buildAsset.IsRawAsset)
|
if (buildAsset.IsRawAsset)
|
||||||
EditorTools.CopyFile(buildAsset.AssetPath, dest, true);
|
EditorTools.CopyFile(buildAsset.AssetPath, dest, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证构建结果
|
|
||||||
if (buildParametersContext.Parameters.VerifyBuildingResult)
|
|
||||||
{
|
|
||||||
VerifyingBuildingResult(context, unityManifest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 验证构建结果
|
|
||||||
/// </summary>
|
|
||||||
private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest)
|
|
||||||
{
|
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
|
||||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
|
||||||
string[] buildedBundles = unityManifest.GetAllAssetBundles();
|
|
||||||
|
|
||||||
// 1. 过滤掉原生Bundle
|
|
||||||
List<BuildBundleInfo> expectBundles = new List<BuildBundleInfo>(buildedBundles.Length);
|
|
||||||
foreach(var bundleInfo in buildMapContext.BundleInfos)
|
|
||||||
{
|
|
||||||
if (bundleInfo.IsRawFile == false)
|
|
||||||
expectBundles.Add(bundleInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 验证数量
|
|
||||||
if (buildedBundles.Length != expectBundles.Count)
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"构建过程中可能存在无效的资源,导致和预期构建的Bundle数量不一致!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 正向验证Bundle
|
|
||||||
foreach (var bundleName in buildedBundles)
|
|
||||||
{
|
|
||||||
if (buildMapContext.IsContainsBundle(bundleName) == false)
|
|
||||||
{
|
|
||||||
throw new Exception($"Should never get here !");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 反向验证Bundle
|
|
||||||
bool isPass = true;
|
|
||||||
foreach (var expectBundle in expectBundles)
|
|
||||||
{
|
|
||||||
bool isMatch = false;
|
|
||||||
foreach (var buildedBundle in buildedBundles)
|
|
||||||
{
|
|
||||||
if (buildedBundle == expectBundle.BundleName)
|
|
||||||
{
|
|
||||||
isMatch = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isMatch == false)
|
|
||||||
{
|
|
||||||
isPass = false;
|
|
||||||
Debug.LogWarning($"没有找到预期构建的Bundle文件 : {expectBundle.BundleName}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(isPass == false)
|
|
||||||
{
|
|
||||||
throw new Exception("构建结果验证没有通过,请参考警告日志!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5. 验证Asset
|
|
||||||
int progressValue = 0;
|
|
||||||
foreach (var buildedBundle in buildedBundles)
|
|
||||||
{
|
|
||||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{buildedBundle}";
|
|
||||||
string[] allBuildinAssetPaths = GetAssetBundleAllAssets(filePath);
|
|
||||||
string[] expectBuildinAssetPaths = buildMapContext.GetBuildinAssetPaths(buildedBundle);
|
|
||||||
if (expectBuildinAssetPaths.Length != allBuildinAssetPaths.Length)
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"构建的Bundle文件内的资源对象数量和预期不匹配 : {buildedBundle}");
|
|
||||||
isPass = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var buildinAssetPath in allBuildinAssetPaths)
|
|
||||||
{
|
|
||||||
var guid = AssetDatabase.AssetPathToGUID(buildinAssetPath);
|
|
||||||
if (string.IsNullOrEmpty(guid))
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"无效的资源路径,请检查路径是否带有特殊符号或中文:{buildinAssetPath}");
|
|
||||||
isPass = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isMatch = false;
|
|
||||||
foreach (var exceptBuildAssetPath in expectBuildinAssetPaths)
|
|
||||||
{
|
|
||||||
var guidExcept = AssetDatabase.AssetPathToGUID(exceptBuildAssetPath);
|
|
||||||
if (guid == guidExcept)
|
|
||||||
{
|
|
||||||
isMatch = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isMatch == false)
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"在构建的Bundle文件里发现了没有匹配的资源对象:{buildinAssetPath}");
|
|
||||||
isPass = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorTools.DisplayProgressBar("验证构建结果", ++progressValue, buildedBundles.Length);
|
|
||||||
}
|
|
||||||
EditorTools.ClearProgressBar();
|
|
||||||
if (isPass == false)
|
|
||||||
{
|
|
||||||
throw new Exception("构建结果验证没有通过,请参考警告日志!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 卸载所有加载的Bundle
|
|
||||||
Debug.Log("构建结果验证成功!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 解析.manifest文件并获取资源列表
|
|
||||||
/// </summary>
|
|
||||||
private string[] GetAssetBundleAllAssets(string filePath)
|
|
||||||
{
|
|
||||||
string manifestFilePath = $"{filePath}.manifest";
|
|
||||||
List<string> assetLines = new List<string>();
|
|
||||||
using (StreamReader reader = File.OpenText(manifestFilePath))
|
|
||||||
{
|
|
||||||
string content;
|
|
||||||
bool findTarget = false;
|
|
||||||
while (null != (content = reader.ReadLine()))
|
|
||||||
{
|
|
||||||
if (content.StartsWith("Dependencies:"))
|
|
||||||
break;
|
|
||||||
if (findTarget == false && content.StartsWith("Assets:"))
|
|
||||||
findTarget = true;
|
|
||||||
if (findTarget)
|
|
||||||
{
|
|
||||||
if (content.StartsWith("- "))
|
|
||||||
{
|
|
||||||
string assetPath = content.TrimStart("- ".ToCharArray());
|
|
||||||
assetLines.Add(assetPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return assetLines.ToArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,30 +6,27 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
/// <summary>
|
[TaskAttribute("拷贝内置文件到流目录")]
|
||||||
/// 拷贝内置文件到StreamingAssets
|
|
||||||
/// </summary>
|
|
||||||
public class TaskCopyBuildinFiles : IBuildTask
|
public class TaskCopyBuildinFiles : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
// 注意:我们只有在强制重建的时候才会拷贝
|
// 注意:我们只有在强制重建的时候才会拷贝
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||||
if(buildParameters.Parameters.ForceRebuild)
|
if (buildParameters.Parameters.BuildMode == EBuildMode.ForceRebuild)
|
||||||
{
|
{
|
||||||
// 清空流目录
|
// 清空流目录
|
||||||
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
||||||
|
|
||||||
// 拷贝内置文件
|
// 拷贝内置文件
|
||||||
var pipelineOutputDirectory = buildParameters.PipelineOutputDirectory;
|
CopyBuildinFilesToStreaming(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
|
||||||
CopyBuildinFilesToStreaming(pipelineOutputDirectory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyBuildinFilesToStreaming(string pipelineOutputDirectory)
|
private void CopyBuildinFilesToStreaming(string pipelineOutputDirectory, int buildVersion)
|
||||||
{
|
{
|
||||||
// 加载补丁清单
|
// 加载补丁清单
|
||||||
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory);
|
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildVersion);
|
||||||
|
|
||||||
// 拷贝文件列表
|
// 拷贝文件列表
|
||||||
foreach (var patchBundle in patchManifest.BundleList)
|
foreach (var patchBundle in patchManifest.BundleList)
|
||||||
@@ -39,26 +36,33 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}";
|
string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}";
|
||||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{patchBundle.Hash}";
|
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{patchBundle.Hash}";
|
||||||
Debug.Log($"拷贝内置文件到流目录:{patchBundle.BundleName}");
|
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝清单文件
|
// 拷贝清单文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(buildVersion)}";
|
||||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.GetPatchManifestFileName(buildVersion)}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝清单哈希文件
|
// 拷贝清单哈希文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}";
|
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(buildVersion)}";
|
||||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}";
|
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.GetPatchManifestHashFileName(buildVersion)}";
|
||||||
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拷贝静态版本文件
|
||||||
|
{
|
||||||
|
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
|
||||||
|
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettings.VersionFileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新目录
|
// 刷新目录
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
|
BuildRunner.Log($"内置文件拷贝完成:{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,9 +5,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
/// <summary>
|
[TaskAttribute("创建补丁清单文件")]
|
||||||
/// 创建补丁清单文件
|
|
||||||
/// </summary>
|
|
||||||
public class TaskCreatePatchManifest : IBuildTask
|
public class TaskCreatePatchManifest : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
@@ -24,23 +22,32 @@ namespace YooAsset.Editor
|
|||||||
private void CreatePatchManifestFile(AssetBundleBuilder.BuildParametersContext buildParameters,
|
private void CreatePatchManifestFile(AssetBundleBuilder.BuildParametersContext buildParameters,
|
||||||
BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
|
BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
|
||||||
{
|
{
|
||||||
|
int resourceVersion = buildParameters.Parameters.BuildVersion;
|
||||||
|
|
||||||
// 创建新补丁清单
|
// 创建新补丁清单
|
||||||
PatchManifest patchManifest = new PatchManifest();
|
PatchManifest patchManifest = new PatchManifest();
|
||||||
|
patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable;
|
||||||
patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion;
|
patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion;
|
||||||
patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags;
|
patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||||
patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
|
patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
|
||||||
patchManifest.AssetList = GetAllPatchAsset(buildMapContext, patchManifest);
|
patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest);
|
||||||
|
|
||||||
// 创建补丁清单文件
|
// 创建补丁清单文件
|
||||||
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||||
UnityEngine.Debug.Log($"创建补丁清单文件:{manifestFilePath}");
|
BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}");
|
||||||
PatchManifest.Serialize(manifestFilePath, patchManifest);
|
PatchManifest.Serialize(manifestFilePath, patchManifest);
|
||||||
|
|
||||||
// 创建补丁清单哈希文件
|
// 创建补丁清单哈希文件
|
||||||
string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}";
|
string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
|
||||||
string manifestHash = HashUtility.FileMD5(manifestFilePath);
|
string manifestHash = HashUtility.FileMD5(manifestFilePath);
|
||||||
UnityEngine.Debug.Log($"创建补丁清单哈希文件:{manifestHashFilePath}");
|
BuildRunner.Log($"创建补丁清单哈希文件:{manifestHashFilePath}");
|
||||||
FileUtility.CreateFile(manifestHashFilePath, manifestHash);
|
FileUtility.CreateFile(manifestHashFilePath, manifestHash);
|
||||||
|
|
||||||
|
// 创建静态版本文件
|
||||||
|
string staticVersionFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
|
||||||
|
string staticVersion = resourceVersion.ToString();
|
||||||
|
BuildRunner.Log($"创建静态版本文件:{staticVersionFilePath}");
|
||||||
|
FileUtility.CreateFile(staticVersionFilePath, staticVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -54,22 +61,16 @@ namespace YooAsset.Editor
|
|||||||
// 内置标记列表
|
// 内置标记列表
|
||||||
List<string> buildinTags = buildParameters.Parameters.GetBuildinTags();
|
List<string> buildinTags = buildParameters.Parameters.GetBuildinTags();
|
||||||
|
|
||||||
// 加载旧补丁清单
|
var buildMode = buildParameters.Parameters.BuildMode;
|
||||||
PatchManifest oldPatchManifest = null;
|
bool standardBuild = buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild;
|
||||||
if (buildParameters.Parameters.ForceRebuild == false)
|
|
||||||
{
|
|
||||||
oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
{
|
{
|
||||||
var bundleName = bundleInfo.BundleName;
|
var bundleName = bundleInfo.BundleName;
|
||||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
|
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
|
||||||
string hash = HashUtility.FileMD5(filePath);
|
string hash = GetFileHash(filePath, standardBuild);
|
||||||
string crc = HashUtility.FileCRC32(filePath);
|
string crc32 = GetFileCRC(filePath, standardBuild);
|
||||||
long size = FileUtility.GetFileSize(filePath);
|
long size = GetFileSize(filePath, standardBuild);
|
||||||
int version = buildParameters.Parameters.BuildVersion;
|
string[] tags = buildMapContext.GetBundleTags(bundleName);
|
||||||
string[] tags = buildMapContext.GetAssetTags(bundleName);
|
|
||||||
bool isEncrypted = encryptionContext.IsEncryptFile(bundleName);
|
bool isEncrypted = encryptionContext.IsEncryptFile(bundleName);
|
||||||
bool isBuildin = IsBuildinBundle(tags, buildinTags);
|
bool isBuildin = IsBuildinBundle(tags, buildinTags);
|
||||||
bool isRawFile = bundleInfo.IsRawFile;
|
bool isRawFile = bundleInfo.IsRawFile;
|
||||||
@@ -80,14 +81,7 @@ namespace YooAsset.Editor
|
|||||||
hash += bundleInfo.GetAppendExtension();
|
hash += bundleInfo.GetAppendExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:如果文件没有变化使用旧版本号
|
PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc32, size, tags);
|
||||||
if (oldPatchManifest != null && oldPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle value))
|
|
||||||
{
|
|
||||||
if (value.Hash == hash)
|
|
||||||
version = value.Version;
|
|
||||||
}
|
|
||||||
|
|
||||||
PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc, size, version, tags);
|
|
||||||
patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile);
|
patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile);
|
||||||
result.Add(patchBundle);
|
result.Add(patchBundle);
|
||||||
}
|
}
|
||||||
@@ -107,11 +101,33 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
private string GetFileHash(string filePath, bool standardBuild)
|
||||||
|
{
|
||||||
|
if (standardBuild)
|
||||||
|
return HashUtility.FileMD5(filePath);
|
||||||
|
else
|
||||||
|
return "00000000000000000000000000000000"; //32位
|
||||||
|
}
|
||||||
|
private string GetFileCRC(string filePath, bool standardBuild)
|
||||||
|
{
|
||||||
|
if (standardBuild)
|
||||||
|
return HashUtility.FileCRC32(filePath);
|
||||||
|
else
|
||||||
|
return "00000000"; //8位
|
||||||
|
}
|
||||||
|
private long GetFileSize(string filePath, bool standardBuild)
|
||||||
|
{
|
||||||
|
if (standardBuild)
|
||||||
|
return FileUtility.GetFileSize(filePath);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取资源列表
|
/// 获取资源列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private List<PatchAsset> GetAllPatchAsset(BuildMapContext buildMapContext, PatchManifest patchManifest)
|
private List<PatchAsset> GetAllPatchAsset(AssetBundleBuilder.BuildParametersContext buildParameters,
|
||||||
|
BuildMapContext buildMapContext, PatchManifest patchManifest)
|
||||||
{
|
{
|
||||||
List<PatchAsset> result = new List<PatchAsset>(1000);
|
List<PatchAsset> result = new List<PatchAsset>(1000);
|
||||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
@@ -120,24 +136,33 @@ namespace YooAsset.Editor
|
|||||||
foreach (var assetInfo in assetInfos)
|
foreach (var assetInfo in assetInfos)
|
||||||
{
|
{
|
||||||
PatchAsset patchAsset = new PatchAsset();
|
PatchAsset patchAsset = new PatchAsset();
|
||||||
|
if (buildParameters.Parameters.EnableAddressable)
|
||||||
|
patchAsset.Address = assetInfo.Address;
|
||||||
|
else
|
||||||
|
patchAsset.Address = string.Empty;
|
||||||
patchAsset.AssetPath = assetInfo.AssetPath;
|
patchAsset.AssetPath = assetInfo.AssetPath;
|
||||||
patchAsset.BundleID = GetAssetBundleID(assetInfo.BundleName, patchManifest);
|
patchAsset.AssetTags = assetInfo.AssetTags.ToArray();
|
||||||
patchAsset.DependIDs = GetAssetBundleDependIDs(assetInfo, patchManifest);
|
patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest);
|
||||||
|
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
|
||||||
result.Add(patchAsset);
|
result.Add(patchAsset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
private int[] GetAssetBundleDependIDs(BuildAssetInfo assetInfo, PatchManifest patchManifest)
|
private int[] GetAssetBundleDependIDs(int mainBundleID, BuildAssetInfo assetInfo, PatchManifest patchManifest)
|
||||||
{
|
{
|
||||||
List<int> result = new List<int>();
|
List<int> result = new List<int>();
|
||||||
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
|
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
|
||||||
{
|
{
|
||||||
if (dependAssetInfo.BundleNameIsValid() == false)
|
if (dependAssetInfo.HasBundleName())
|
||||||
continue;
|
{
|
||||||
int bundleID = GetAssetBundleID(dependAssetInfo.BundleName, patchManifest);
|
int bundleID = GetAssetBundleID(dependAssetInfo.GetBundleName(), patchManifest);
|
||||||
if (result.Contains(bundleID) == false)
|
if (mainBundleID != bundleID)
|
||||||
result.Add(bundleID);
|
{
|
||||||
|
if (result.Contains(bundleID) == false)
|
||||||
|
result.Add(bundleID);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,15 +3,17 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
/// <summary>
|
[TaskAttribute("制作补丁包")]
|
||||||
/// 制作补丁包
|
|
||||||
/// </summary>
|
|
||||||
public class TaskCreatePatchPackage : IBuildTask
|
public class TaskCreatePatchPackage : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||||
CopyPatchFiles(buildParameters);
|
var buildMode = buildParameters.Parameters.BuildMode;
|
||||||
|
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||||
|
{
|
||||||
|
CopyPatchFiles(buildParameters);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -19,31 +21,37 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void CopyPatchFiles(AssetBundleBuilder.BuildParametersContext buildParameters)
|
private void CopyPatchFiles(AssetBundleBuilder.BuildParametersContext buildParameters)
|
||||||
{
|
{
|
||||||
|
int resourceVersion = buildParameters.Parameters.BuildVersion;
|
||||||
string packageDirectory = buildParameters.GetPackageDirectory();
|
string packageDirectory = buildParameters.GetPackageDirectory();
|
||||||
UnityEngine.Debug.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}");
|
BuildRunner.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}");
|
||||||
|
|
||||||
// 拷贝Report文件
|
// 拷贝Report文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.ReportFileName}";
|
string reportFileName = YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion);
|
||||||
string destPath = $"{packageDirectory}/{YooAssetSettings.ReportFileName}";
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{reportFileName}";
|
||||||
|
string destPath = $"{packageDirectory}/{reportFileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
UnityEngine.Debug.Log($"拷贝Report文件到:{destPath}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝PatchManifest文件
|
// 拷贝补丁清单文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||||
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}";
|
string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
UnityEngine.Debug.Log($"拷贝PatchManifest文件到:{destPath}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝PatchManifest哈希文件
|
// 拷贝补丁清单哈希文件
|
||||||
{
|
{
|
||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}";
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
|
||||||
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}";
|
string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
|
||||||
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拷贝静态版本文件
|
||||||
|
{
|
||||||
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
|
||||||
|
string destPath = $"{packageDirectory}/{YooAssetSettings.VersionFileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
UnityEngine.Debug.Log($"拷贝PatchManifest哈希文件到:{destPath}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝UnityManifest序列化文件
|
// 拷贝UnityManifest序列化文件
|
||||||
@@ -51,7 +59,6 @@ namespace YooAsset.Editor
|
|||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
|
||||||
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
|
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
UnityEngine.Debug.Log($"拷贝UnityManifest文件到:{destPath}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝UnityManifest文本文件
|
// 拷贝UnityManifest文本文件
|
||||||
@@ -62,20 +69,15 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 拷贝所有补丁文件
|
// 拷贝所有补丁文件
|
||||||
// 注意:拷贝的补丁文件都是需要玩家热更新的文件
|
|
||||||
int progressValue = 0;
|
int progressValue = 0;
|
||||||
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
|
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
|
||||||
int patchFileTotalCount = patchManifest.BundleList.Count;
|
int patchFileTotalCount = patchManifest.BundleList.Count;
|
||||||
foreach (var patchBundle in patchManifest.BundleList)
|
foreach (var patchBundle in patchManifest.BundleList)
|
||||||
{
|
{
|
||||||
if (patchBundle.Version == buildParameters.Parameters.BuildVersion)
|
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}";
|
||||||
{
|
string destPath = $"{packageDirectory}/{patchBundle.Hash}";
|
||||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}";
|
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||||
string destPath = $"{packageDirectory}/{patchBundle.Hash}";
|
EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount);
|
||||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
|
||||||
UnityEngine.Debug.Log($"拷贝补丁文件到补丁包:{patchBundle.BundleName}");
|
|
||||||
EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
EditorTools.ClearProgressBar();
|
EditorTools.ClearProgressBar();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,56 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
/// <summary>
|
[TaskAttribute("创建构建报告文件")]
|
||||||
/// 创建报告文件
|
|
||||||
/// </summary>
|
|
||||||
public class TaskCreateReport : IBuildTask
|
public class TaskCreateReport : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
CreateReportFile(buildParameters, buildMapContext);
|
buildParameters.StopWatch();
|
||||||
|
|
||||||
|
var buildMode = buildParameters.Parameters.BuildMode;
|
||||||
|
if (buildMode != EBuildMode.SimulateBuild)
|
||||||
|
{
|
||||||
|
CreateReportFile(buildParameters, buildMapContext);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float buildSeconds = buildParameters.GetBuildingSeconds();
|
||||||
|
BuildRunner.Info($"Build time consuming {buildSeconds} seconds.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext)
|
private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext)
|
||||||
{
|
{
|
||||||
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
|
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
|
||||||
BuildReport buildReport = new BuildReport();
|
BuildReport buildReport = new BuildReport();
|
||||||
buildParameters.StopWatch();
|
|
||||||
|
|
||||||
// 概述信息
|
// 概述信息
|
||||||
{
|
{
|
||||||
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
|
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
|
||||||
buildReport.Summary.BuildTime = DateTime.Now.ToString();
|
buildReport.Summary.BuildTime = DateTime.Now.ToString();
|
||||||
buildReport.Summary.BuildSeconds = buildParameters.GetBuildingSeconds();
|
buildReport.Summary.BuildSeconds = (int)buildParameters.GetBuildingSeconds();
|
||||||
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
|
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
|
||||||
|
buildReport.Summary.BuildMode = buildParameters.Parameters.BuildMode;
|
||||||
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
|
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
|
||||||
buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect;
|
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||||
|
buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable;
|
||||||
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
|
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
|
||||||
buildReport.Summary.AutoCollectShaders = AssetBundleGrouperSettingData.Setting.AutoCollectShaders;
|
buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
|
||||||
buildReport.Summary.ShadersBundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName;
|
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
|
||||||
buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ?
|
buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ?
|
||||||
"null" : buildParameters.Parameters.EncryptionServices.GetType().FullName;
|
"null" : buildParameters.Parameters.EncryptionServices.GetType().FullName;
|
||||||
|
|
||||||
// 构建参数
|
// 构建参数
|
||||||
buildReport.Summary.ForceRebuild = buildParameters.Parameters.ForceRebuild;
|
|
||||||
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
|
||||||
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption;
|
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption;
|
||||||
buildReport.Summary.AppendHash = buildParameters.Parameters.AppendHash;
|
|
||||||
buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree;
|
buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree;
|
||||||
buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges;
|
buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges;
|
||||||
buildReport.Summary.DisableLoadAssetByFileName = buildParameters.Parameters.DisableLoadAssetByFileName;
|
|
||||||
|
|
||||||
// 构建结果
|
// 构建结果
|
||||||
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
|
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
|
||||||
@@ -63,8 +70,12 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
var mainBundle = patchManifest.BundleList[patchAsset.BundleID];
|
var mainBundle = patchManifest.BundleList[patchAsset.BundleID];
|
||||||
ReportAssetInfo reportAssetInfo = new ReportAssetInfo();
|
ReportAssetInfo reportAssetInfo = new ReportAssetInfo();
|
||||||
|
reportAssetInfo.Address = patchAsset.Address;
|
||||||
reportAssetInfo.AssetPath = patchAsset.AssetPath;
|
reportAssetInfo.AssetPath = patchAsset.AssetPath;
|
||||||
reportAssetInfo.MainBundle = mainBundle.BundleName;
|
reportAssetInfo.AssetTags = patchAsset.AssetTags;
|
||||||
|
reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath);
|
||||||
|
reportAssetInfo.MainBundleName = mainBundle.BundleName;
|
||||||
|
reportAssetInfo.MainBundleSize = mainBundle.SizeBytes;
|
||||||
reportAssetInfo.DependBundles = GetDependBundles(patchManifest, patchAsset);
|
reportAssetInfo.DependBundles = GetDependBundles(patchManifest, patchAsset);
|
||||||
reportAssetInfo.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, patchAsset.AssetPath);
|
reportAssetInfo.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, patchAsset.AssetPath);
|
||||||
buildReport.AssetInfos.Add(reportAssetInfo);
|
buildReport.AssetInfos.Add(reportAssetInfo);
|
||||||
@@ -79,19 +90,19 @@ namespace YooAsset.Editor
|
|||||||
reportBundleInfo.Hash = patchBundle.Hash;
|
reportBundleInfo.Hash = patchBundle.Hash;
|
||||||
reportBundleInfo.CRC = patchBundle.CRC;
|
reportBundleInfo.CRC = patchBundle.CRC;
|
||||||
reportBundleInfo.SizeBytes = patchBundle.SizeBytes;
|
reportBundleInfo.SizeBytes = patchBundle.SizeBytes;
|
||||||
reportBundleInfo.Version = patchBundle.Version;
|
|
||||||
reportBundleInfo.Tags = patchBundle.Tags;
|
reportBundleInfo.Tags = patchBundle.Tags;
|
||||||
reportBundleInfo.Flags = patchBundle.Flags;
|
reportBundleInfo.Flags = patchBundle.Flags;
|
||||||
buildReport.BundleInfos.Add(reportBundleInfo);
|
buildReport.BundleInfos.Add(reportBundleInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除旧文件
|
// 删除旧文件
|
||||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.ReportFileName}";
|
string filePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion)}";
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
File.Delete(filePath);
|
File.Delete(filePath);
|
||||||
|
|
||||||
// 序列化文件
|
// 序列化文件
|
||||||
BuildReport.Serialize(filePath, buildReport);
|
BuildReport.Serialize(filePath, buildReport);
|
||||||
|
BuildRunner.Log($"资源构建报告文件创建完成:{filePath}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
|
[TaskAttribute("资源包加密")]
|
||||||
public class TaskEncryption : IBuildTask
|
public class TaskEncryption : IBuildTask
|
||||||
{
|
{
|
||||||
public class EncryptionContext : IContextObject
|
public class EncryptionContext : IContextObject
|
||||||
@@ -26,9 +27,19 @@ namespace YooAsset.Editor
|
|||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
|
|
||||||
EncryptionContext encryptionContext = new EncryptionContext();
|
var buildMode = buildParameters.Parameters.BuildMode;
|
||||||
encryptionContext.EncryptList = EncryptFiles(buildParameters, buildMapContext);
|
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||||
context.SetContextObject(encryptionContext);
|
{
|
||||||
|
EncryptionContext encryptionContext = new EncryptionContext();
|
||||||
|
encryptionContext.EncryptList = EncryptFiles(buildParameters, buildMapContext);
|
||||||
|
context.SetContextObject(encryptionContext);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EncryptionContext encryptionContext = new EncryptionContext();
|
||||||
|
encryptionContext.EncryptList = new List<string>();
|
||||||
|
context.SetContextObject(encryptionContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -45,7 +56,6 @@ namespace YooAsset.Editor
|
|||||||
if (encryptionServices == null)
|
if (encryptionServices == null)
|
||||||
return encryptList;
|
return encryptList;
|
||||||
|
|
||||||
UnityEngine.Debug.Log($"开始加密资源文件");
|
|
||||||
int progressValue = 0;
|
int progressValue = 0;
|
||||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||||
{
|
{
|
||||||
@@ -66,7 +76,7 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
byte[] bytes = encryptionServices.Encrypt(fileData);
|
byte[] bytes = encryptionServices.Encrypt(fileData);
|
||||||
File.WriteAllBytes(filePath, bytes);
|
File.WriteAllBytes(filePath, bytes);
|
||||||
UnityEngine.Debug.Log($"文件加密完成:{filePath}");
|
BuildRunner.Log($"文件加密完成:{filePath}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +85,8 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
EditorTools.ClearProgressBar();
|
EditorTools.ClearProgressBar();
|
||||||
|
|
||||||
|
if(encryptList.Count == 0)
|
||||||
|
UnityEngine.Debug.LogWarning($"没有发现需要加密的文件!");
|
||||||
return encryptList;
|
return encryptList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,15 @@ using UnityEditor;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
|
[TaskAttribute("获取资源构建内容")]
|
||||||
public class TaskGetBuildMap : IBuildTask
|
public class TaskGetBuildMap : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildMapContext = BuildMapHelper.SetupBuildMap();
|
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||||
|
var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode);
|
||||||
context.SetContextObject(buildMapContext);
|
context.SetContextObject(buildMapContext);
|
||||||
|
BuildRunner.Log("构建内容准备完毕!");
|
||||||
|
|
||||||
// 检测构建结果
|
// 检测构建结果
|
||||||
CheckBuildMapContent(buildMapContext);
|
CheckBuildMapContent(buildMapContext);
|
||||||
@@ -30,7 +33,7 @@ namespace YooAsset.Editor
|
|||||||
if (isRawFile)
|
if (isRawFile)
|
||||||
{
|
{
|
||||||
if (bundleInfo.BuildinAssets.Count != 1)
|
if (bundleInfo.BuildinAssets.Count != 1)
|
||||||
throw new Exception("The bundle does not support multiple raw asset : {bundleInfo.BundleName}");
|
throw new Exception($"The bundle does not support multiple raw asset : {bundleInfo.BundleName}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using UnityEditor;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
|
[TaskAttribute("资源构建准备工作")]
|
||||||
public class TaskPrepare : IBuildTask
|
public class TaskPrepare : IBuildTask
|
||||||
{
|
{
|
||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
@@ -26,7 +27,8 @@ namespace YooAsset.Editor
|
|||||||
throw new Exception("输出目录不能为空");
|
throw new Exception("输出目录不能为空");
|
||||||
|
|
||||||
// 增量更新时候的必要检测
|
// 增量更新时候的必要检测
|
||||||
if (buildParameters.Parameters.ForceRebuild == false)
|
var buildMode = buildParameters.Parameters.BuildMode;
|
||||||
|
if (buildMode == EBuildMode.IncrementalBuild)
|
||||||
{
|
{
|
||||||
// 检测历史版本是否存在
|
// 检测历史版本是否存在
|
||||||
if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot) == false)
|
if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot) == false)
|
||||||
@@ -43,26 +45,26 @@ namespace YooAsset.Editor
|
|||||||
throw new Exception($"补丁包已经存在:{packageDirectory}");
|
throw new Exception($"补丁包已经存在:{packageDirectory}");
|
||||||
|
|
||||||
// 检测内置资源分类标签是否一致
|
// 检测内置资源分类标签是否一致
|
||||||
PatchManifest oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
|
var oldPatchManifest = AssetBundleBuilderHelper.GetOldPatchManifest(buildParameters.PipelineOutputDirectory);
|
||||||
if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags)
|
if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags)
|
||||||
throw new Exception($"增量更新时内置资源标签必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}");
|
throw new Exception($"增量更新时内置资源标签必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果是强制重建
|
// 如果是强制重建
|
||||||
if (buildParameters.Parameters.ForceRebuild)
|
if (buildMode == EBuildMode.ForceRebuild)
|
||||||
{
|
{
|
||||||
// 删除平台总目录
|
// 删除平台总目录
|
||||||
string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}";
|
string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}";
|
||||||
if (EditorTools.DeleteDirectory(platformDirectory))
|
if (EditorTools.DeleteDirectory(platformDirectory))
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.Log($"删除平台总目录:{platformDirectory}");
|
BuildRunner.Log($"删除平台总目录:{platformDirectory}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果输出目录不存在
|
// 如果输出目录不存在
|
||||||
if (EditorTools.CreateDirectory(buildParameters.PipelineOutputDirectory))
|
if (EditorTools.CreateDirectory(buildParameters.PipelineOutputDirectory))
|
||||||
{
|
{
|
||||||
UnityEngine.Debug.Log($"创建输出目录:{buildParameters.PipelineOutputDirectory}");
|
BuildRunner.Log($"创建输出目录:{buildParameters.PipelineOutputDirectory}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,174 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
[TaskAttribute("验证构建结果")]
|
||||||
|
public class TaskVerifyBuildResult : IBuildTask
|
||||||
|
{
|
||||||
|
void IBuildTask.Run(BuildContext context)
|
||||||
|
{
|
||||||
|
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||||
|
|
||||||
|
// 模拟构建模式下跳过验证
|
||||||
|
if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 验证构建结果
|
||||||
|
if (buildParametersContext.Parameters.VerifyBuildingResult)
|
||||||
|
{
|
||||||
|
var unityManifestContext = context.GetContextObject<TaskBuilding.UnityManifestContext>();
|
||||||
|
VerifyingBuildingResult(context, unityManifestContext.UnityManifest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 验证构建结果
|
||||||
|
/// </summary>
|
||||||
|
private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest)
|
||||||
|
{
|
||||||
|
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||||
|
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||||
|
string[] buildedBundles = unityManifest.GetAllAssetBundles();
|
||||||
|
|
||||||
|
// 1. 过滤掉原生Bundle
|
||||||
|
List<BuildBundleInfo> expectBundles = new List<BuildBundleInfo>(buildedBundles.Length);
|
||||||
|
foreach(var bundleInfo in buildMapContext.BundleInfos)
|
||||||
|
{
|
||||||
|
if (bundleInfo.IsRawFile == false)
|
||||||
|
expectBundles.Add(bundleInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 验证数量
|
||||||
|
if (buildedBundles.Length != expectBundles.Count)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"构建过程中可能存在无效的资源,导致和预期构建的Bundle数量不一致!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 正向验证Bundle
|
||||||
|
foreach (var bundleName in buildedBundles)
|
||||||
|
{
|
||||||
|
if (buildMapContext.IsContainsBundle(bundleName) == false)
|
||||||
|
{
|
||||||
|
throw new Exception($"Should never get here !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 反向验证Bundle
|
||||||
|
bool isPass = true;
|
||||||
|
foreach (var expectBundle in expectBundles)
|
||||||
|
{
|
||||||
|
bool isMatch = false;
|
||||||
|
foreach (var buildedBundle in buildedBundles)
|
||||||
|
{
|
||||||
|
if (buildedBundle == expectBundle.BundleName)
|
||||||
|
{
|
||||||
|
isMatch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isMatch == false)
|
||||||
|
{
|
||||||
|
isPass = false;
|
||||||
|
Debug.LogWarning($"没有找到预期构建的Bundle文件 : {expectBundle.BundleName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(isPass == false)
|
||||||
|
{
|
||||||
|
throw new Exception("构建结果验证没有通过,请参考警告日志!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 验证Asset
|
||||||
|
var buildMode = buildParameters.Parameters.BuildMode;
|
||||||
|
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||||
|
{
|
||||||
|
int progressValue = 0;
|
||||||
|
foreach (var buildedBundle in buildedBundles)
|
||||||
|
{
|
||||||
|
string filePath = $"{buildParameters.PipelineOutputDirectory}/{buildedBundle}";
|
||||||
|
string[] allBuildinAssetPaths = GetAssetBundleAllAssets(filePath);
|
||||||
|
string[] expectBuildinAssetPaths = buildMapContext.GetBuildinAssetPaths(buildedBundle);
|
||||||
|
if (expectBuildinAssetPaths.Length != allBuildinAssetPaths.Length)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"构建的Bundle文件内的资源对象数量和预期不匹配 : {buildedBundle}");
|
||||||
|
isPass = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var buildinAssetPath in allBuildinAssetPaths)
|
||||||
|
{
|
||||||
|
var guid = AssetDatabase.AssetPathToGUID(buildinAssetPath);
|
||||||
|
if (string.IsNullOrEmpty(guid))
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"无效的资源路径,请检查路径是否带有特殊符号或中文:{buildinAssetPath}");
|
||||||
|
isPass = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isMatch = false;
|
||||||
|
foreach (var exceptBuildAssetPath in expectBuildinAssetPaths)
|
||||||
|
{
|
||||||
|
var guidExcept = AssetDatabase.AssetPathToGUID(exceptBuildAssetPath);
|
||||||
|
if (guid == guidExcept)
|
||||||
|
{
|
||||||
|
isMatch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isMatch == false)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"在构建的Bundle文件里发现了没有匹配的资源对象:{buildinAssetPath}");
|
||||||
|
isPass = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorTools.DisplayProgressBar("验证构建结果", ++progressValue, buildedBundles.Length);
|
||||||
|
}
|
||||||
|
EditorTools.ClearProgressBar();
|
||||||
|
if (isPass == false)
|
||||||
|
{
|
||||||
|
throw new Exception("构建结果验证没有通过,请参考警告日志!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 卸载所有加载的Bundle
|
||||||
|
BuildRunner.Log("构建结果验证成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 解析.manifest文件并获取资源列表
|
||||||
|
/// </summary>
|
||||||
|
private string[] GetAssetBundleAllAssets(string filePath)
|
||||||
|
{
|
||||||
|
string manifestFilePath = $"{filePath}.manifest";
|
||||||
|
List<string> assetLines = new List<string>();
|
||||||
|
using (StreamReader reader = File.OpenText(manifestFilePath))
|
||||||
|
{
|
||||||
|
string content;
|
||||||
|
bool findTarget = false;
|
||||||
|
while (null != (content = reader.ReadLine()))
|
||||||
|
{
|
||||||
|
if (content.StartsWith("Dependencies:"))
|
||||||
|
break;
|
||||||
|
if (findTarget == false && content.StartsWith("Assets:"))
|
||||||
|
findTarget = true;
|
||||||
|
if (findTarget)
|
||||||
|
{
|
||||||
|
if (content.StartsWith("- "))
|
||||||
|
{
|
||||||
|
string assetPath = content.TrimStart("- ".ToCharArray());
|
||||||
|
assetLines.Add(assetPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return assetLines.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b883ac0c3c25e8143847a9326e2961cf
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
29
Assets/YooAsset/Editor/AssetBundleBuilder/EBuildMode.cs
Normal file
29
Assets/YooAsset/Editor/AssetBundleBuilder/EBuildMode.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 资源包流水线的构建模式
|
||||||
|
/// </summary>
|
||||||
|
public enum EBuildMode
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 强制重建模式
|
||||||
|
/// </summary>
|
||||||
|
ForceRebuild,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 增量构建模式
|
||||||
|
/// </summary>
|
||||||
|
IncrementalBuild,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 演练构建模式
|
||||||
|
/// </summary>
|
||||||
|
DryRunBuild,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模拟构建模式
|
||||||
|
/// </summary>
|
||||||
|
SimulateBuild,
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/YooAsset/Editor/AssetBundleBuilder/EBuildMode.cs.meta
Normal file
11
Assets/YooAsset/Editor/AssetBundleBuilder/EBuildMode.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0b6f2523a865e454d8fa3f48a2852d5a
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class AssetBundleCollector
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 收集路径
|
||||||
|
/// 注意:支持文件夹或单个资源文件
|
||||||
|
/// </summary>
|
||||||
|
public string CollectPath = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 收集器类型
|
||||||
|
/// </summary>
|
||||||
|
public ECollectorType CollectorType = ECollectorType.MainAssetCollector;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 寻址规则类名
|
||||||
|
/// </summary>
|
||||||
|
public string AddressRuleName = nameof(AddressByFileName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 打包规则类名
|
||||||
|
/// </summary>
|
||||||
|
public string PackRuleName = nameof(PackDirectory);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 过滤规则类名
|
||||||
|
/// </summary>
|
||||||
|
public string FilterRuleName = nameof(CollectAll);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源分类标签
|
||||||
|
/// </summary>
|
||||||
|
public string AssetTags = string.Empty;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 收集器是否有效
|
||||||
|
/// </summary>
|
||||||
|
public bool IsValid()
|
||||||
|
{
|
||||||
|
if (AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(CollectPath) == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (CollectorType == ECollectorType.None)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检测配置错误
|
||||||
|
/// </summary>
|
||||||
|
public void CheckConfigError()
|
||||||
|
{
|
||||||
|
if (AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(CollectPath) == null)
|
||||||
|
throw new Exception($"Invalid collect path : {CollectPath}");
|
||||||
|
|
||||||
|
if (CollectorType == ECollectorType.None)
|
||||||
|
throw new Exception($"{nameof(ECollectorType)}.{ECollectorType.None} is invalid in collector : {CollectPath}");
|
||||||
|
|
||||||
|
if (AssetBundleCollectorSettingData.HasPackRuleName(PackRuleName) == false)
|
||||||
|
throw new Exception($"Invalid {nameof(IPackRule)} class type : {PackRuleName} in collector : {CollectPath}");
|
||||||
|
|
||||||
|
if (AssetBundleCollectorSettingData.HasFilterRuleName(FilterRuleName) == false)
|
||||||
|
throw new Exception($"Invalid {nameof(IFilterRule)} class type : {FilterRuleName} in collector : {CollectPath}");
|
||||||
|
|
||||||
|
if (AssetBundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
|
||||||
|
throw new Exception($"Invalid {nameof(IAddressRule)} class type : {AddressRuleName} in collector : {CollectPath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取打包收集的资源文件
|
||||||
|
/// </summary>
|
||||||
|
public List<CollectAssetInfo> GetAllCollectAssets(AssetBundleCollectorGroup group)
|
||||||
|
{
|
||||||
|
// 注意:模拟构建模式下只收集主资源
|
||||||
|
if (AssetBundleCollectorSetting.BuildMode == EBuildMode.SimulateBuild)
|
||||||
|
{
|
||||||
|
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||||
|
return new List<CollectAssetInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
|
||||||
|
bool isRawAsset = PackRuleName == nameof(PackRawFile);
|
||||||
|
|
||||||
|
// 检测原生资源包的收集器类型
|
||||||
|
if (isRawAsset && CollectorType != ECollectorType.MainAssetCollector)
|
||||||
|
throw new Exception($"The raw file must be set to {nameof(ECollectorType)}.{ECollectorType.MainAssetCollector} : {CollectPath}");
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(CollectPath))
|
||||||
|
throw new Exception($"The collect path is null or empty in group : {group.GroupName}");
|
||||||
|
|
||||||
|
// 收集打包资源
|
||||||
|
if (AssetDatabase.IsValidFolder(CollectPath))
|
||||||
|
{
|
||||||
|
string collectDirectory = CollectPath;
|
||||||
|
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
||||||
|
foreach (string assetPath in findAssets)
|
||||||
|
{
|
||||||
|
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
|
||||||
|
{
|
||||||
|
if (result.ContainsKey(assetPath) == false)
|
||||||
|
{
|
||||||
|
var collectAssetInfo = CreateCollectAssetInfo(group, assetPath, isRawAsset);
|
||||||
|
result.Add(assetPath, collectAssetInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"The collecting asset file is existed : {assetPath} in collector : {CollectPath}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string assetPath = CollectPath;
|
||||||
|
if (IsValidateAsset(assetPath) && IsCollectAsset(assetPath))
|
||||||
|
{
|
||||||
|
var collectAssetInfo = CreateCollectAssetInfo(group, assetPath, isRawAsset);
|
||||||
|
result.Add(assetPath, collectAssetInfo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"The collecting single asset file is invalid : {assetPath} in collector : {CollectPath}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测可寻址地址是否重复
|
||||||
|
if (AssetBundleCollectorSettingData.Setting.EnableAddressable)
|
||||||
|
{
|
||||||
|
HashSet<string> adressTemper = new HashSet<string>();
|
||||||
|
foreach (var collectInfoPair in result)
|
||||||
|
{
|
||||||
|
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||||
|
{
|
||||||
|
string address = collectInfoPair.Value.Address;
|
||||||
|
if (adressTemper.Contains(address) == false)
|
||||||
|
adressTemper.Add(address);
|
||||||
|
else
|
||||||
|
throw new Exception($"The address is existed : {address} in collector : {CollectPath}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回列表
|
||||||
|
return result.Values.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private CollectAssetInfo CreateCollectAssetInfo(AssetBundleCollectorGroup group, string assetPath, bool isRawAsset)
|
||||||
|
{
|
||||||
|
string address = GetAddress(group, assetPath);
|
||||||
|
string bundleName = GetBundleName(group, assetPath);
|
||||||
|
List<string> assetTags = GetAssetTags(group);
|
||||||
|
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetPath, assetTags, isRawAsset);
|
||||||
|
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
|
||||||
|
return collectAssetInfo;
|
||||||
|
}
|
||||||
|
private bool IsValidateAsset(string assetPath)
|
||||||
|
{
|
||||||
|
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (AssetDatabase.IsValidFolder(assetPath))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// 注意:忽略编辑器下的类型资源
|
||||||
|
Type type = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||||
|
if (type == typeof(LightingDataAsset))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
string ext = System.IO.Path.GetExtension(assetPath);
|
||||||
|
if (ext == "" || ext == ".dll" || ext == ".cs" || ext == ".js" || ext == ".boo" || ext == ".meta" || ext == ".cginc")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private bool IsCollectAsset(string assetPath)
|
||||||
|
{
|
||||||
|
// 如果收集全路径着色器
|
||||||
|
if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders)
|
||||||
|
{
|
||||||
|
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||||
|
if (assetType == typeof(UnityEngine.Shader))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据规则设置过滤资源文件
|
||||||
|
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
|
||||||
|
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath));
|
||||||
|
}
|
||||||
|
private string GetAddress(AssetBundleCollectorGroup group, string assetPath)
|
||||||
|
{
|
||||||
|
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
IAddressRule addressRuleInstance = AssetBundleCollectorSettingData.GetAddressRuleInstance(AddressRuleName);
|
||||||
|
string adressValue = addressRuleInstance.GetAssetAddress(new AddressRuleData(assetPath, CollectPath, group.GroupName));
|
||||||
|
return adressValue;
|
||||||
|
}
|
||||||
|
private string GetBundleName(AssetBundleCollectorGroup group, string assetPath)
|
||||||
|
{
|
||||||
|
// 如果自动收集所有的着色器
|
||||||
|
if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders)
|
||||||
|
{
|
||||||
|
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||||
|
if (assetType == typeof(UnityEngine.Shader))
|
||||||
|
{
|
||||||
|
string bundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
|
||||||
|
return EditorTools.GetRegularPath(bundleName).ToLower();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据规则设置获取资源包名称
|
||||||
|
{
|
||||||
|
IPackRule packRuleInstance = AssetBundleCollectorSettingData.GetPackRuleInstance(PackRuleName);
|
||||||
|
string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, group.GroupName));
|
||||||
|
return EditorTools.GetRegularPath(bundleName).ToLower();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
||||||
|
{
|
||||||
|
List<string> tags = StringUtility.StringToStringList(group.AssetTags, ';');
|
||||||
|
List<string> temper = StringUtility.StringToStringList(AssetTags, ';');
|
||||||
|
tags.AddRange(temper);
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
private List<string> GetAllDependencies(string mainAssetPath)
|
||||||
|
{
|
||||||
|
// 注意:模拟构建模式下不需要收集依赖资源
|
||||||
|
if(AssetBundleCollectorSetting.BuildMode == EBuildMode.SimulateBuild)
|
||||||
|
return new List<string>();
|
||||||
|
|
||||||
|
List<string> result = new List<string>();
|
||||||
|
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
||||||
|
foreach (string assetPath in depends)
|
||||||
|
{
|
||||||
|
if (IsValidateAsset(assetPath))
|
||||||
|
{
|
||||||
|
// 注意:排除主资源对象
|
||||||
|
if (assetPath != mainAssetPath)
|
||||||
|
result.Add(assetPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Xml;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public class AssetBundleCollectorConfig
|
||||||
|
{
|
||||||
|
public const string ConfigVersion = "1.0";
|
||||||
|
|
||||||
|
public const string XmlVersion = "Version";
|
||||||
|
public const string XmlCommon = "Common";
|
||||||
|
public const string XmlEnableAddressable = "AutoAddressable";
|
||||||
|
public const string XmlAutoCollectShader = "AutoCollectShader";
|
||||||
|
public const string XmlShaderBundleName = "ShaderBundleName";
|
||||||
|
public const string XmlGroup = "Group";
|
||||||
|
public const string XmlGroupName = "GroupName";
|
||||||
|
public const string XmlGroupDesc = "GroupDesc";
|
||||||
|
public const string XmlCollector = "Collector";
|
||||||
|
public const string XmlCollectPath = "CollectPath";
|
||||||
|
public const string XmlCollectorType = "CollectType";
|
||||||
|
public const string XmlAddressRule = "AddressRule";
|
||||||
|
public const string XmlPackRule = "PackRule";
|
||||||
|
public const string XmlFilterRule = "FilterRule";
|
||||||
|
public const string XmlAssetTags = "AssetTags";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导入XML配置表
|
||||||
|
/// </summary>
|
||||||
|
public static void ImportXmlConfig(string filePath)
|
||||||
|
{
|
||||||
|
if (File.Exists(filePath) == false)
|
||||||
|
throw new FileNotFoundException(filePath);
|
||||||
|
|
||||||
|
if (Path.GetExtension(filePath) != ".xml")
|
||||||
|
throw new Exception($"Only support xml : {filePath}");
|
||||||
|
|
||||||
|
// 加载配置文件
|
||||||
|
XmlDocument xml = new XmlDocument();
|
||||||
|
xml.Load(filePath);
|
||||||
|
XmlElement root = xml.DocumentElement;
|
||||||
|
|
||||||
|
// 读取配置版本
|
||||||
|
string configVersion = root.GetAttribute(XmlVersion);
|
||||||
|
if(configVersion != ConfigVersion)
|
||||||
|
{
|
||||||
|
throw new Exception($"The config version is invalid : {configVersion}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取公共配置
|
||||||
|
bool enableAddressable = false;
|
||||||
|
bool autoCollectShaders = false;
|
||||||
|
string shaderBundleName = string.Empty;
|
||||||
|
var commonNodeList = root.GetElementsByTagName(XmlCommon);
|
||||||
|
if (commonNodeList.Count > 0)
|
||||||
|
{
|
||||||
|
XmlElement commonElement = commonNodeList[0] as XmlElement;
|
||||||
|
if (commonElement.HasAttribute(XmlEnableAddressable) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlEnableAddressable} in {XmlCommon}");
|
||||||
|
if (commonElement.HasAttribute(XmlAutoCollectShader) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlAutoCollectShader} in {XmlCommon}");
|
||||||
|
if (commonElement.HasAttribute(XmlShaderBundleName) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlShaderBundleName} in {XmlCommon}");
|
||||||
|
|
||||||
|
enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
|
||||||
|
autoCollectShaders = commonElement.GetAttribute(XmlAutoCollectShader) == "True" ? true : false;
|
||||||
|
shaderBundleName = commonElement.GetAttribute(XmlShaderBundleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取分组配置
|
||||||
|
List<AssetBundleCollectorGroup> groupTemper = new List<AssetBundleCollectorGroup>();
|
||||||
|
var groupNodeList = root.GetElementsByTagName(XmlGroup);
|
||||||
|
foreach (var groupNode in groupNodeList)
|
||||||
|
{
|
||||||
|
XmlElement groupElement = groupNode as XmlElement;
|
||||||
|
if (groupElement.HasAttribute(XmlGroupName) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlGroupName} in {XmlGroup}");
|
||||||
|
if (groupElement.HasAttribute(XmlGroupDesc) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlGroupDesc} in {XmlGroup}");
|
||||||
|
if (groupElement.HasAttribute(XmlAssetTags) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGroup}");
|
||||||
|
|
||||||
|
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
||||||
|
group.GroupName = groupElement.GetAttribute(XmlGroupName);
|
||||||
|
group.GroupDesc = groupElement.GetAttribute(XmlGroupDesc);
|
||||||
|
group.AssetTags = groupElement.GetAttribute(XmlAssetTags);
|
||||||
|
groupTemper.Add(group);
|
||||||
|
|
||||||
|
// 读取收集器配置
|
||||||
|
var collectorNodeList = groupElement.GetElementsByTagName(XmlCollector);
|
||||||
|
foreach (var collectorNode in collectorNodeList)
|
||||||
|
{
|
||||||
|
XmlElement collectorElement = collectorNode as XmlElement;
|
||||||
|
if (collectorElement.HasAttribute(XmlCollectPath) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlCollectPath} in {XmlCollector}");
|
||||||
|
if (collectorElement.HasAttribute(XmlCollectorType) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlCollectorType} in {XmlCollector}");
|
||||||
|
if (collectorElement.HasAttribute(XmlAddressRule) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlAddressRule} in {XmlCollector}");
|
||||||
|
if (collectorElement.HasAttribute(XmlPackRule) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlPackRule} in {XmlCollector}");
|
||||||
|
if (collectorElement.HasAttribute(XmlFilterRule) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlFilterRule} in {XmlCollector}");
|
||||||
|
if (collectorElement.HasAttribute(XmlAssetTags) == false)
|
||||||
|
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}");
|
||||||
|
|
||||||
|
AssetBundleCollector collector = new AssetBundleCollector();
|
||||||
|
collector.CollectPath = collectorElement.GetAttribute(XmlCollectPath);
|
||||||
|
collector.CollectorType = StringUtility.NameToEnum<ECollectorType>(collectorElement.GetAttribute(XmlCollectorType));
|
||||||
|
collector.AddressRuleName = collectorElement.GetAttribute(XmlAddressRule);
|
||||||
|
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
|
||||||
|
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
|
||||||
|
collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags); ;
|
||||||
|
group.Collectors.Add(collector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存配置数据
|
||||||
|
AssetBundleCollectorSettingData.ClearAll();
|
||||||
|
AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable;
|
||||||
|
AssetBundleCollectorSettingData.Setting.AutoCollectShaders = autoCollectShaders;
|
||||||
|
AssetBundleCollectorSettingData.Setting.ShadersBundleName = shaderBundleName;
|
||||||
|
AssetBundleCollectorSettingData.Setting.Groups.AddRange(groupTemper);
|
||||||
|
AssetBundleCollectorSettingData.SaveFile();
|
||||||
|
Debug.Log($"导入配置完毕!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导出XML配置表
|
||||||
|
/// </summary>
|
||||||
|
public static void ExportXmlConfig(string savePath)
|
||||||
|
{
|
||||||
|
if (File.Exists(savePath))
|
||||||
|
File.Delete(savePath);
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||||
|
sb.AppendLine("<root>");
|
||||||
|
sb.AppendLine("</root>");
|
||||||
|
|
||||||
|
XmlDocument xmlDoc = new XmlDocument();
|
||||||
|
xmlDoc.LoadXml(sb.ToString());
|
||||||
|
XmlElement root = xmlDoc.DocumentElement;
|
||||||
|
|
||||||
|
// 设置配置版本
|
||||||
|
root.SetAttribute(XmlVersion, ConfigVersion);
|
||||||
|
|
||||||
|
// 设置公共配置
|
||||||
|
var commonElement = xmlDoc.CreateElement(XmlCommon);
|
||||||
|
commonElement.SetAttribute(XmlEnableAddressable, AssetBundleCollectorSettingData.Setting.EnableAddressable.ToString());
|
||||||
|
commonElement.SetAttribute(XmlAutoCollectShader, AssetBundleCollectorSettingData.Setting.AutoCollectShaders.ToString());
|
||||||
|
commonElement.SetAttribute(XmlShaderBundleName, AssetBundleCollectorSettingData.Setting.ShadersBundleName);
|
||||||
|
root.AppendChild(commonElement);
|
||||||
|
|
||||||
|
// 设置分组配置
|
||||||
|
foreach (var group in AssetBundleCollectorSettingData.Setting.Groups)
|
||||||
|
{
|
||||||
|
var groupElement = xmlDoc.CreateElement(XmlGroup);
|
||||||
|
groupElement.SetAttribute(XmlGroupName, group.GroupName);
|
||||||
|
groupElement.SetAttribute(XmlGroupDesc, group.GroupDesc);
|
||||||
|
groupElement.SetAttribute(XmlAssetTags, group.AssetTags);
|
||||||
|
root.AppendChild(groupElement);
|
||||||
|
|
||||||
|
// 设置收集器配置
|
||||||
|
foreach (var collector in group.Collectors)
|
||||||
|
{
|
||||||
|
var collectorElement = xmlDoc.CreateElement(XmlCollector);
|
||||||
|
collectorElement.SetAttribute(XmlCollectPath, collector.CollectPath);
|
||||||
|
collectorElement.SetAttribute(XmlCollectorType, collector.CollectorType.ToString());
|
||||||
|
collectorElement.SetAttribute(XmlAddressRule, collector.AddressRuleName);
|
||||||
|
collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName);
|
||||||
|
collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName);
|
||||||
|
collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags);
|
||||||
|
groupElement.AppendChild(collectorElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成配置文件
|
||||||
|
xmlDoc.Save(savePath);
|
||||||
|
Debug.Log($"导出配置完毕!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,17 +8,17 @@ using UnityEditor;
|
|||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class AssetBundleGrouper
|
public class AssetBundleCollectorGroup
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 分组名称
|
/// 分组名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GrouperName = string.Empty;
|
public string GroupName = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 分组描述
|
/// 分组描述
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GrouperDesc = string.Empty;
|
public string GroupDesc = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源分类标签
|
/// 资源分类标签
|
||||||
@@ -36,7 +36,7 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void CheckConfigError()
|
public void CheckConfigError()
|
||||||
{
|
{
|
||||||
foreach(var collector in Collectors)
|
foreach (var collector in Collectors)
|
||||||
{
|
{
|
||||||
collector.CheckConfigError();
|
collector.CheckConfigError();
|
||||||
}
|
}
|
||||||
@@ -48,21 +48,38 @@ namespace YooAsset.Editor
|
|||||||
public List<CollectAssetInfo> GetAllCollectAssets()
|
public List<CollectAssetInfo> GetAllCollectAssets()
|
||||||
{
|
{
|
||||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||||
foreach(var collector in Collectors)
|
|
||||||
|
// 收集打包资源
|
||||||
|
foreach (var collector in Collectors)
|
||||||
{
|
{
|
||||||
var temper = collector.GetAllCollectAssets(this);
|
var temper = collector.GetAllCollectAssets(this);
|
||||||
foreach(var assetInfo in temper)
|
foreach (var assetInfo in temper)
|
||||||
{
|
{
|
||||||
if(result.ContainsKey(assetInfo.AssetPath) == false)
|
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||||
{
|
|
||||||
result.Add(assetInfo.AssetPath, assetInfo);
|
result.Add(assetInfo.AssetPath, assetInfo);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group : {GroupName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测可寻址地址是否重复
|
||||||
|
if (AssetBundleCollectorSettingData.Setting.EnableAddressable)
|
||||||
|
{
|
||||||
|
HashSet<string> adressTemper = new HashSet<string>();
|
||||||
|
foreach (var collectInfoPair in result)
|
||||||
|
{
|
||||||
|
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||||
{
|
{
|
||||||
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in grouper : {GrouperName}");
|
string address = collectInfoPair.Value.Address;
|
||||||
|
if (adressTemper.Contains(address) == false)
|
||||||
|
adressTemper.Add(address);
|
||||||
|
else
|
||||||
|
throw new Exception($"The address is existed : {address} in group : {GroupName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 返回列表
|
||||||
return result.Values.ToList();
|
return result.Values.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public class AssetBundleCollectorSetting : ScriptableObject
|
||||||
|
{
|
||||||
|
public static EBuildMode BuildMode;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否启用可寻址资源定位
|
||||||
|
/// </summary>
|
||||||
|
public bool EnableAddressable = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自动收集着色器
|
||||||
|
/// </summary>
|
||||||
|
public bool AutoCollectShaders = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 自动收集的着色器资源包名称
|
||||||
|
/// </summary>
|
||||||
|
public string ShadersBundleName = "myshaders";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分组列表
|
||||||
|
/// </summary>
|
||||||
|
public List<AssetBundleCollectorGroup> Groups = new List<AssetBundleCollectorGroup>();
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检测配置错误
|
||||||
|
/// </summary>
|
||||||
|
public void CheckConfigError()
|
||||||
|
{
|
||||||
|
foreach (var group in Groups)
|
||||||
|
{
|
||||||
|
group.CheckConfigError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取打包收集的资源文件
|
||||||
|
/// </summary>
|
||||||
|
public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
|
||||||
|
{
|
||||||
|
BuildMode = buildMode;
|
||||||
|
|
||||||
|
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||||
|
|
||||||
|
// 收集打包资源
|
||||||
|
foreach (var group in Groups)
|
||||||
|
{
|
||||||
|
var temper = group.GetAllCollectAssets();
|
||||||
|
foreach (var assetInfo in temper)
|
||||||
|
{
|
||||||
|
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
||||||
|
result.Add(assetInfo.AssetPath, assetInfo);
|
||||||
|
else
|
||||||
|
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group setting.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测可寻址地址是否重复
|
||||||
|
if (EnableAddressable)
|
||||||
|
{
|
||||||
|
HashSet<string> adressTemper = new HashSet<string>();
|
||||||
|
foreach (var collectInfoPair in result)
|
||||||
|
{
|
||||||
|
if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
|
||||||
|
{
|
||||||
|
string address = collectInfoPair.Value.Address;
|
||||||
|
if (adressTemper.Contains(address) == false)
|
||||||
|
adressTemper.Add(address);
|
||||||
|
else
|
||||||
|
throw new Exception($"The address is existed : {address} in group setting.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回列表
|
||||||
|
return result.Values.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +1,31 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public class AssetBundleGrouperSettingData
|
public class AssetBundleCollectorSettingData
|
||||||
{
|
{
|
||||||
|
private static readonly Dictionary<string, System.Type> _cacheAddressRuleTypes = new Dictionary<string, System.Type>();
|
||||||
|
private static readonly Dictionary<string, IAddressRule> _cacheAddressRuleInstance = new Dictionary<string, IAddressRule>();
|
||||||
|
|
||||||
private static readonly Dictionary<string, System.Type> _cachePackRuleTypes = new Dictionary<string, System.Type>();
|
private static readonly Dictionary<string, System.Type> _cachePackRuleTypes = new Dictionary<string, System.Type>();
|
||||||
private static readonly Dictionary<string, IPackRule> _cachePackRuleInstance = new Dictionary<string, IPackRule>();
|
private static readonly Dictionary<string, IPackRule> _cachePackRuleInstance = new Dictionary<string, IPackRule>();
|
||||||
|
|
||||||
private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>();
|
private static readonly Dictionary<string, System.Type> _cacheFilterRuleTypes = new Dictionary<string, System.Type>();
|
||||||
private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>();
|
private static readonly Dictionary<string, IFilterRule> _cacheFilterRuleInstance = new Dictionary<string, IFilterRule>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 配置数据是否被修改
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsDirty { private set; get; } = false;
|
||||||
|
|
||||||
private static AssetBundleGrouperSetting _setting = null;
|
|
||||||
public static AssetBundleGrouperSetting Setting
|
private static AssetBundleCollectorSetting _setting = null;
|
||||||
|
public static AssetBundleCollectorSetting Setting
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -26,6 +35,18 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<string> GetAddressRuleNames()
|
||||||
|
{
|
||||||
|
if (_setting == null)
|
||||||
|
LoadSettingData();
|
||||||
|
|
||||||
|
List<string> names = new List<string>();
|
||||||
|
foreach (var pair in _cacheAddressRuleTypes)
|
||||||
|
{
|
||||||
|
names.Add(pair.Key);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
}
|
||||||
public static List<string> GetPackRuleNames()
|
public static List<string> GetPackRuleNames()
|
||||||
{
|
{
|
||||||
if (_setting == null)
|
if (_setting == null)
|
||||||
@@ -50,6 +71,15 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
public static bool HasAddressRuleName(string ruleName)
|
||||||
|
{
|
||||||
|
foreach (var pair in _cacheAddressRuleTypes)
|
||||||
|
{
|
||||||
|
if (pair.Key == ruleName)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public static bool HasPackRuleName(string ruleName)
|
public static bool HasPackRuleName(string ruleName)
|
||||||
{
|
{
|
||||||
foreach (var pair in _cachePackRuleTypes)
|
foreach (var pair in _cachePackRuleTypes)
|
||||||
@@ -69,26 +99,13 @@ namespace YooAsset.Editor
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 加载配置文件
|
/// 加载配置文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static void LoadSettingData()
|
private static void LoadSettingData()
|
||||||
{
|
{
|
||||||
// 加载配置文件
|
_setting = YooAssetEditorSettingsHelper.LoadSettingData<AssetBundleCollectorSetting>();
|
||||||
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleGrouperSetting>(EditorDefine.AssetBundleGrouperSettingFilePath);
|
|
||||||
if (_setting == null)
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"Create new {nameof(AssetBundleGrouperSetting)}.asset : {EditorDefine.AssetBundleGrouperSettingFilePath}");
|
|
||||||
_setting = ScriptableObject.CreateInstance<AssetBundleGrouperSetting>();
|
|
||||||
EditorTools.CreateFileDirectory(EditorDefine.AssetBundleGrouperSettingFilePath);
|
|
||||||
AssetDatabase.CreateAsset(Setting, EditorDefine.AssetBundleGrouperSettingFilePath);
|
|
||||||
AssetDatabase.SaveAssets();
|
|
||||||
AssetDatabase.Refresh();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Log($"Load {nameof(AssetBundleGrouperSetting)}.asset ok");
|
|
||||||
}
|
|
||||||
|
|
||||||
// IPackRule
|
// IPackRule
|
||||||
{
|
{
|
||||||
@@ -101,11 +118,13 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
typeof(PackSeparately),
|
typeof(PackSeparately),
|
||||||
typeof(PackDirectory),
|
typeof(PackDirectory),
|
||||||
|
typeof(PackTopDirectory),
|
||||||
typeof(PackCollector),
|
typeof(PackCollector),
|
||||||
typeof(PackGrouper),
|
typeof(PackGroup),
|
||||||
typeof(PackRawFile),
|
typeof(PackRawFile),
|
||||||
};
|
};
|
||||||
var customTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IPackRule));
|
|
||||||
|
var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule));
|
||||||
types.AddRange(customTypes);
|
types.AddRange(customTypes);
|
||||||
for (int i = 0; i < types.Count; i++)
|
for (int i = 0; i < types.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -129,7 +148,8 @@ namespace YooAsset.Editor
|
|||||||
typeof(CollectPrefab),
|
typeof(CollectPrefab),
|
||||||
typeof(CollectSprite)
|
typeof(CollectSprite)
|
||||||
};
|
};
|
||||||
var customTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IFilterRule));
|
|
||||||
|
var customTypes = EditorTools.GetAssignableTypes(typeof(IFilterRule));
|
||||||
types.AddRange(customTypes);
|
types.AddRange(customTypes);
|
||||||
for (int i = 0; i < types.Count; i++)
|
for (int i = 0; i < types.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -138,6 +158,30 @@ namespace YooAsset.Editor
|
|||||||
_cacheFilterRuleTypes.Add(type.Name, type);
|
_cacheFilterRuleTypes.Add(type.Name, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IAddressRule
|
||||||
|
{
|
||||||
|
// 清空缓存集合
|
||||||
|
_cacheAddressRuleTypes.Clear();
|
||||||
|
_cacheAddressRuleInstance.Clear();
|
||||||
|
|
||||||
|
// 获取所有类型
|
||||||
|
List<Type> types = new List<Type>(100)
|
||||||
|
{
|
||||||
|
typeof(AddressByFileName),
|
||||||
|
typeof(AddressByCollectorAndFileName),
|
||||||
|
typeof(AddressByGroupAndFileName)
|
||||||
|
};
|
||||||
|
|
||||||
|
var customTypes = EditorTools.GetAssignableTypes(typeof(IAddressRule));
|
||||||
|
types.AddRange(customTypes);
|
||||||
|
for (int i = 0; i < types.Count; i++)
|
||||||
|
{
|
||||||
|
Type type = types[i];
|
||||||
|
if (_cacheAddressRuleTypes.ContainsKey(type.Name) == false)
|
||||||
|
_cacheAddressRuleTypes.Add(type.Name, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -147,8 +191,10 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
if (Setting != null)
|
if (Setting != null)
|
||||||
{
|
{
|
||||||
|
IsDirty = false;
|
||||||
EditorUtility.SetDirty(Setting);
|
EditorUtility.SetDirty(Setting);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
|
Debug.Log($"{nameof(AssetBundleCollectorSetting)}.asset is saved!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,11 +205,28 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
Setting.AutoCollectShaders = false;
|
Setting.AutoCollectShaders = false;
|
||||||
Setting.ShadersBundleName = string.Empty;
|
Setting.ShadersBundleName = string.Empty;
|
||||||
Setting.Groupers.Clear();
|
Setting.Groups.Clear();
|
||||||
SaveFile();
|
SaveFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 实例类相关
|
// 实例类相关
|
||||||
|
public static IAddressRule GetAddressRuleInstance(string ruleName)
|
||||||
|
{
|
||||||
|
if (_cacheAddressRuleInstance.TryGetValue(ruleName, out IAddressRule instance))
|
||||||
|
return instance;
|
||||||
|
|
||||||
|
// 如果不存在创建类的实例
|
||||||
|
if (_cacheAddressRuleTypes.TryGetValue(ruleName, out Type type))
|
||||||
|
{
|
||||||
|
instance = (IAddressRule)Activator.CreateInstance(type);
|
||||||
|
_cacheAddressRuleInstance.Add(ruleName, instance);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"{nameof(IAddressRule)}类型无效:{ruleName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
public static IPackRule GetPackRuleInstance(string ruleName)
|
public static IPackRule GetPackRuleInstance(string ruleName)
|
||||||
{
|
{
|
||||||
if (_cachePackRuleInstance.TryGetValue(ruleName, out IPackRule instance))
|
if (_cachePackRuleInstance.TryGetValue(ruleName, out IPackRule instance))
|
||||||
@@ -199,68 +262,72 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 可寻址编辑相关
|
||||||
|
public static void ModifyAddressable(bool enableAddressable)
|
||||||
|
{
|
||||||
|
Setting.EnableAddressable = enableAddressable;
|
||||||
|
IsDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
// 着色器编辑相关
|
// 着色器编辑相关
|
||||||
public static void ModifyShader(bool isCollectAllShaders, string shadersBundleName)
|
public static void ModifyShader(bool isCollectAllShaders, string shadersBundleName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(shadersBundleName))
|
|
||||||
return;
|
|
||||||
Setting.AutoCollectShaders = isCollectAllShaders;
|
Setting.AutoCollectShaders = isCollectAllShaders;
|
||||||
Setting.ShadersBundleName = shadersBundleName;
|
Setting.ShadersBundleName = shadersBundleName;
|
||||||
SaveFile();
|
IsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 资源分组编辑相关
|
// 资源分组编辑相关
|
||||||
public static void CreateGrouper(string grouperName, string grouperDesc, string assetTags, bool saveFile = true)
|
public static void CreateGroup(string groupName)
|
||||||
{
|
{
|
||||||
AssetBundleGrouper grouper = new AssetBundleGrouper();
|
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
||||||
grouper.GrouperName = grouperName;
|
group.GroupName = groupName;
|
||||||
grouper.GrouperDesc = grouperDesc;
|
Setting.Groups.Add(group);
|
||||||
grouper.AssetTags = assetTags;
|
IsDirty = true;
|
||||||
Setting.Groupers.Add(grouper);
|
|
||||||
|
|
||||||
if (saveFile)
|
|
||||||
SaveFile();
|
|
||||||
}
|
}
|
||||||
public static void RemoveGrouper(AssetBundleGrouper grouper)
|
public static void RemoveGroup(AssetBundleCollectorGroup group)
|
||||||
{
|
{
|
||||||
if (Setting.Groupers.Remove(grouper))
|
if (Setting.Groups.Remove(group))
|
||||||
{
|
{
|
||||||
SaveFile();
|
IsDirty = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Failed remove group : {group.GroupName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void ModifyGrouper(AssetBundleGrouper grouper)
|
public static void ModifyGroup(AssetBundleCollectorGroup group)
|
||||||
{
|
{
|
||||||
if (grouper != null)
|
if (group != null)
|
||||||
{
|
{
|
||||||
SaveFile();
|
IsDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 资源收集器编辑相关
|
// 资源收集器编辑相关
|
||||||
public static void CreateCollector(AssetBundleGrouper grouper, string collectPath, string packRuleName, string filterRuleName, bool notWriteToAssetList, bool saveFile = true)
|
public static void CreateCollector(AssetBundleCollectorGroup group, string collectPath)
|
||||||
{
|
{
|
||||||
AssetBundleCollector collector = new AssetBundleCollector();
|
AssetBundleCollector collector = new AssetBundleCollector();
|
||||||
collector.CollectPath = collectPath;
|
collector.CollectPath = collectPath;
|
||||||
collector.PackRuleName = packRuleName;
|
group.Collectors.Add(collector);
|
||||||
collector.FilterRuleName = filterRuleName;
|
IsDirty = true;
|
||||||
collector.NotWriteToAssetList = notWriteToAssetList;
|
|
||||||
grouper.Collectors.Add(collector);
|
|
||||||
|
|
||||||
if (saveFile)
|
|
||||||
SaveFile();
|
|
||||||
}
|
}
|
||||||
public static void RemoveCollector(AssetBundleGrouper grouper, AssetBundleCollector collector)
|
public static void RemoveCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||||
{
|
{
|
||||||
if (grouper.Collectors.Remove(collector))
|
if (group.Collectors.Remove(collector))
|
||||||
{
|
{
|
||||||
SaveFile();
|
IsDirty = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void ModifyCollector(AssetBundleGrouper grouper, AssetBundleCollector collector)
|
public static void ModifyCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||||
{
|
{
|
||||||
if (grouper != null && collector != null)
|
if (group != null && collector != null)
|
||||||
{
|
{
|
||||||
SaveFile();
|
IsDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,605 @@
|
|||||||
|
#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 AssetBundleCollectorWindow : EditorWindow
|
||||||
|
{
|
||||||
|
[MenuItem("YooAsset/AssetBundle Collector", false, 101)]
|
||||||
|
public static void ShowExample()
|
||||||
|
{
|
||||||
|
AssetBundleCollectorWindow window = GetWindow<AssetBundleCollectorWindow>("资源包收集工具", true, EditorDefine.DockedWindowTypes);
|
||||||
|
window.minSize = new Vector2(800, 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<string> _collectorTypeList;
|
||||||
|
private List<string> _addressRuleList;
|
||||||
|
private List<string> _packRuleList;
|
||||||
|
private List<string> _filterRuleList;
|
||||||
|
private ListView _groupListView;
|
||||||
|
private ScrollView _collectorScrollView;
|
||||||
|
private Toggle _enableAddressableToogle;
|
||||||
|
private Toggle _autoCollectShaderToogle;
|
||||||
|
private TextField _shaderBundleNameTxt;
|
||||||
|
private TextField _groupNameTxt;
|
||||||
|
private TextField _groupDescTxt;
|
||||||
|
private TextField _groupAssetTagsTxt;
|
||||||
|
private VisualElement _groupContainer;
|
||||||
|
|
||||||
|
public void CreateGUI()
|
||||||
|
{
|
||||||
|
Undo.undoRedoPerformed -= RefreshWindow;
|
||||||
|
Undo.undoRedoPerformed += RefreshWindow;
|
||||||
|
|
||||||
|
_collectorTypeList = new List<string>()
|
||||||
|
{
|
||||||
|
$"{nameof(ECollectorType.MainAssetCollector)}",
|
||||||
|
$"{nameof(ECollectorType.StaticAssetCollector)}",
|
||||||
|
$"{nameof(ECollectorType.DependAssetCollector)}"
|
||||||
|
};
|
||||||
|
_addressRuleList = AssetBundleCollectorSettingData.GetAddressRuleNames();
|
||||||
|
_packRuleList = AssetBundleCollectorSettingData.GetPackRuleNames();
|
||||||
|
_filterRuleList = AssetBundleCollectorSettingData.GetFilterRuleNames();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
VisualElement root = this.rootVisualElement;
|
||||||
|
|
||||||
|
// 加载布局文件
|
||||||
|
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleCollectorUXML;
|
||||||
|
if (visualAsset == null)
|
||||||
|
{
|
||||||
|
Debug.LogError($"Not found {nameof(AssetBundleCollectorWindow)}.uxml in settings.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
visualAsset.CloneTree(root);
|
||||||
|
|
||||||
|
// 导入导出按钮
|
||||||
|
var exportBtn = root.Q<Button>("ExportButton");
|
||||||
|
exportBtn.clicked += ExportBtn_clicked;
|
||||||
|
var importBtn = root.Q<Button>("ImportButton");
|
||||||
|
importBtn.clicked += ImportBtn_clicked;
|
||||||
|
|
||||||
|
// 公共设置相关
|
||||||
|
_enableAddressableToogle = root.Q<Toggle>("EnableAddressable");
|
||||||
|
_enableAddressableToogle.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleCollectorSettingData.ModifyAddressable(evt.newValue);
|
||||||
|
});
|
||||||
|
_autoCollectShaderToogle = root.Q<Toggle>("AutoCollectShader");
|
||||||
|
_autoCollectShaderToogle.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleCollectorSettingData.ModifyShader(evt.newValue, _shaderBundleNameTxt.value);
|
||||||
|
_shaderBundleNameTxt.SetEnabled(evt.newValue);
|
||||||
|
});
|
||||||
|
_shaderBundleNameTxt = root.Q<TextField>("ShaderBundleName");
|
||||||
|
_shaderBundleNameTxt.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
AssetBundleCollectorSettingData.ModifyShader(_autoCollectShaderToogle.value, evt.newValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 分组列表相关
|
||||||
|
_groupListView = root.Q<ListView>("GroupListView");
|
||||||
|
_groupListView.makeItem = MakeGroupListViewItem;
|
||||||
|
_groupListView.bindItem = BindGroupListViewItem;
|
||||||
|
#if UNITY_2020_1_OR_NEWER
|
||||||
|
_groupListView.onSelectionChange += GroupListView_onSelectionChange;
|
||||||
|
#else
|
||||||
|
_groupListView.onSelectionChanged += GroupListView_onSelectionChange;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 分组添加删除按钮
|
||||||
|
var groupAddContainer = root.Q("GroupAddContainer");
|
||||||
|
{
|
||||||
|
var addBtn = groupAddContainer.Q<Button>("AddBtn");
|
||||||
|
addBtn.clicked += AddGroupBtn_clicked;
|
||||||
|
var removeBtn = groupAddContainer.Q<Button>("RemoveBtn");
|
||||||
|
removeBtn.clicked += RemoveGroupBtn_clicked;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分组容器
|
||||||
|
_groupContainer = root.Q("GroupContainer");
|
||||||
|
|
||||||
|
// 分组名称
|
||||||
|
_groupNameTxt = root.Q<TextField>("GroupName");
|
||||||
|
_groupNameTxt.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||||
|
if (selectGroup != null)
|
||||||
|
{
|
||||||
|
selectGroup.GroupName = evt.newValue;
|
||||||
|
AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 分组备注
|
||||||
|
_groupDescTxt = root.Q<TextField>("GroupDesc");
|
||||||
|
_groupDescTxt.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||||
|
if (selectGroup != null)
|
||||||
|
{
|
||||||
|
selectGroup.GroupDesc = evt.newValue;
|
||||||
|
AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 分组的资源标签
|
||||||
|
_groupAssetTagsTxt = root.Q<TextField>("GroupAssetTags");
|
||||||
|
_groupAssetTagsTxt.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||||
|
if (selectGroup != null)
|
||||||
|
{
|
||||||
|
selectGroup.AssetTags = evt.newValue;
|
||||||
|
AssetBundleCollectorSettingData.ModifyGroup(selectGroup);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 收集列表相关
|
||||||
|
_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()
|
||||||
|
{
|
||||||
|
if (AssetBundleCollectorSettingData.IsDirty)
|
||||||
|
AssetBundleCollectorSettingData.SaveFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshWindow()
|
||||||
|
{
|
||||||
|
_enableAddressableToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.EnableAddressable);
|
||||||
|
_autoCollectShaderToogle.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.AutoCollectShaders);
|
||||||
|
_shaderBundleNameTxt.SetEnabled(AssetBundleCollectorSettingData.Setting.AutoCollectShaders);
|
||||||
|
_shaderBundleNameTxt.SetValueWithoutNotify(AssetBundleCollectorSettingData.Setting.ShadersBundleName);
|
||||||
|
_groupContainer.visible = false;
|
||||||
|
|
||||||
|
FillGroupViewData();
|
||||||
|
}
|
||||||
|
private void ExportBtn_clicked()
|
||||||
|
{
|
||||||
|
string resultPath = EditorTools.OpenFolderPanel("Export XML", "Assets/");
|
||||||
|
if (resultPath != null)
|
||||||
|
{
|
||||||
|
AssetBundleCollectorConfig.ExportXmlConfig($"{resultPath}/{nameof(AssetBundleCollectorConfig)}.xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ImportBtn_clicked()
|
||||||
|
{
|
||||||
|
string resultPath = EditorTools.OpenFilePath("Import XML", "Assets/", "xml");
|
||||||
|
if (resultPath != null)
|
||||||
|
{
|
||||||
|
AssetBundleCollectorConfig.ImportXmlConfig(resultPath);
|
||||||
|
RefreshWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分组列表相关
|
||||||
|
private void FillGroupViewData()
|
||||||
|
{
|
||||||
|
_groupListView.Clear();
|
||||||
|
_groupListView.ClearSelection();
|
||||||
|
_groupListView.itemsSource = AssetBundleCollectorSettingData.Setting.Groups;
|
||||||
|
_groupListView.Rebuild();
|
||||||
|
}
|
||||||
|
private VisualElement MakeGroupListViewItem()
|
||||||
|
{
|
||||||
|
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 BindGroupListViewItem(VisualElement element, int index)
|
||||||
|
{
|
||||||
|
var group = AssetBundleCollectorSettingData.Setting.Groups[index];
|
||||||
|
|
||||||
|
// Group Name
|
||||||
|
var textField1 = element.Q<Label>("Label1");
|
||||||
|
if (string.IsNullOrEmpty(group.GroupDesc))
|
||||||
|
textField1.text = group.GroupName;
|
||||||
|
else
|
||||||
|
textField1.text = $"{group.GroupName} ({group.GroupDesc})";
|
||||||
|
}
|
||||||
|
private void GroupListView_onSelectionChange(IEnumerable<object> objs)
|
||||||
|
{
|
||||||
|
FillCollectorViewData();
|
||||||
|
}
|
||||||
|
private void AddGroupBtn_clicked()
|
||||||
|
{
|
||||||
|
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset AddGroup");
|
||||||
|
AssetBundleCollectorSettingData.CreateGroup("Default Group");
|
||||||
|
FillGroupViewData();
|
||||||
|
}
|
||||||
|
private void RemoveGroupBtn_clicked()
|
||||||
|
{
|
||||||
|
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||||
|
if (selectGroup == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset RemoveGroup");
|
||||||
|
|
||||||
|
AssetBundleCollectorSettingData.RemoveGroup(selectGroup);
|
||||||
|
FillGroupViewData();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 收集列表相关
|
||||||
|
private void FillCollectorViewData()
|
||||||
|
{
|
||||||
|
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||||
|
if (selectGroup == null)
|
||||||
|
{
|
||||||
|
_groupContainer.visible = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_groupContainer.visible = true;
|
||||||
|
_groupNameTxt.SetValueWithoutNotify(selectGroup.GroupName);
|
||||||
|
_groupDescTxt.SetValueWithoutNotify(selectGroup.GroupDesc);
|
||||||
|
_groupAssetTagsTxt.SetValueWithoutNotify(selectGroup.AssetTags);
|
||||||
|
|
||||||
|
// 填充数据
|
||||||
|
_collectorScrollView.Clear();
|
||||||
|
for (int i = 0; i < selectGroup.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 elementBottom = new VisualElement();
|
||||||
|
elementBottom.style.flexDirection = FlexDirection.Row;
|
||||||
|
element.Add(elementBottom);
|
||||||
|
|
||||||
|
VisualElement elementFoldout = new VisualElement();
|
||||||
|
elementFoldout.style.flexDirection = FlexDirection.Row;
|
||||||
|
element.Add(elementFoldout);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bottom VisualElement
|
||||||
|
{
|
||||||
|
var label = new Label();
|
||||||
|
label.style.width = 90;
|
||||||
|
elementBottom.Add(label);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var popupField = new PopupField<string>(_collectorTypeList, 0);
|
||||||
|
popupField.name = "PopupField0";
|
||||||
|
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
|
popupField.style.width = 150;
|
||||||
|
elementBottom.Add(popupField);
|
||||||
|
}
|
||||||
|
if (_enableAddressableToogle.value)
|
||||||
|
{
|
||||||
|
var popupField = new PopupField<string>(_addressRuleList, 0);
|
||||||
|
popupField.name = "PopupField1";
|
||||||
|
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
|
popupField.style.width = 200;
|
||||||
|
elementBottom.Add(popupField);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var popupField = new PopupField<string>(_packRuleList, 0);
|
||||||
|
popupField.name = "PopupField2";
|
||||||
|
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
|
popupField.style.width = 150;
|
||||||
|
elementBottom.Add(popupField);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var popupField = new PopupField<string>(_filterRuleList, 0);
|
||||||
|
popupField.name = "PopupField3";
|
||||||
|
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
|
popupField.style.width = 150;
|
||||||
|
elementBottom.Add(popupField);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var textField = new TextField();
|
||||||
|
textField.name = "TextField1";
|
||||||
|
textField.label = "Tags";
|
||||||
|
textField.style.width = 100;
|
||||||
|
textField.style.marginLeft = 20;
|
||||||
|
textField.style.flexGrow = 1;
|
||||||
|
elementBottom.Add(textField);
|
||||||
|
var label = textField.Q<Label>();
|
||||||
|
label.style.minWidth = 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Foldout VisualElement
|
||||||
|
{
|
||||||
|
var label = new Label();
|
||||||
|
label.style.width = 90;
|
||||||
|
elementFoldout.Add(label);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
var foldout = new Foldout();
|
||||||
|
foldout.name = "Foldout1";
|
||||||
|
foldout.value = false;
|
||||||
|
foldout.text = "Main Assets";
|
||||||
|
elementFoldout.Add(foldout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Space VisualElement
|
||||||
|
{
|
||||||
|
var label = new Label();
|
||||||
|
label.style.height = 10;
|
||||||
|
elementSpace.Add(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
private void BindCollectorListViewItem(VisualElement element, int index)
|
||||||
|
{
|
||||||
|
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||||
|
if (selectGroup == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var collector = selectGroup.Collectors[index];
|
||||||
|
var collectObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(collector.CollectPath);
|
||||||
|
if (collectObject != null)
|
||||||
|
collectObject.name = collector.CollectPath;
|
||||||
|
|
||||||
|
// Foldout
|
||||||
|
var foldout = element.Q<Foldout>("Foldout1");
|
||||||
|
foldout.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
if (evt.newValue)
|
||||||
|
RefreshFoldout(foldout, selectGroup, collector);
|
||||||
|
else
|
||||||
|
foldout.Clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||||
|
if (foldout.value)
|
||||||
|
{
|
||||||
|
RefreshFoldout(foldout, selectGroup, collector);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Collector Type
|
||||||
|
var popupField0 = element.Q<PopupField<string>>("PopupField0");
|
||||||
|
popupField0.index = GetCollectorTypeIndex(collector.CollectorType.ToString());
|
||||||
|
popupField0.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
collector.CollectorType = StringUtility.NameToEnum<ECollectorType>(evt.newValue);
|
||||||
|
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||||
|
if (foldout.value)
|
||||||
|
{
|
||||||
|
RefreshFoldout(foldout, selectGroup, collector);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Address Rule
|
||||||
|
var popupField1 = element.Q<PopupField<string>>("PopupField1");
|
||||||
|
if (popupField1 != null)
|
||||||
|
{
|
||||||
|
popupField1.index = GetAddressRuleIndex(collector.AddressRuleName);
|
||||||
|
popupField1.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
collector.AddressRuleName = evt.newValue;
|
||||||
|
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||||
|
if (foldout.value)
|
||||||
|
{
|
||||||
|
RefreshFoldout(foldout, selectGroup, collector);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pack Rule
|
||||||
|
var popupField2 = element.Q<PopupField<string>>("PopupField2");
|
||||||
|
popupField2.index = GetPackRuleIndex(collector.PackRuleName);
|
||||||
|
popupField2.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
collector.PackRuleName = evt.newValue;
|
||||||
|
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||||
|
if (foldout.value)
|
||||||
|
{
|
||||||
|
RefreshFoldout(foldout, selectGroup, collector);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filter Rule
|
||||||
|
var popupField3 = element.Q<PopupField<string>>("PopupField3");
|
||||||
|
popupField3.index = GetFilterRuleIndex(collector.FilterRuleName);
|
||||||
|
popupField3.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
collector.FilterRuleName = evt.newValue;
|
||||||
|
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||||
|
if (foldout.value)
|
||||||
|
{
|
||||||
|
RefreshFoldout(foldout, selectGroup, collector);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tags
|
||||||
|
var textFiled1 = element.Q<TextField>("TextField1");
|
||||||
|
textFiled1.SetValueWithoutNotify(collector.AssetTags);
|
||||||
|
textFiled1.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
collector.AssetTags = evt.newValue;
|
||||||
|
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private void RefreshFoldout(Foldout foldout, AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||||
|
{
|
||||||
|
// 清空旧元素
|
||||||
|
foldout.Clear();
|
||||||
|
|
||||||
|
if (collector.IsValid() == false)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"The collector is invalid : {collector.CollectPath} in group : {group.GroupName}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collector.CollectorType == ECollectorType.MainAssetCollector || collector.CollectorType == ECollectorType.StaticAssetCollector)
|
||||||
|
{
|
||||||
|
List<CollectAssetInfo> collectAssetInfos = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
collectAssetInfos = collector.GetAllCollectAssets(group);
|
||||||
|
}
|
||||||
|
catch (System.Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError(e.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collectAssetInfos != null)
|
||||||
|
{
|
||||||
|
foreach (var collectAssetInfo in collectAssetInfos)
|
||||||
|
{
|
||||||
|
VisualElement elementRow = new VisualElement();
|
||||||
|
elementRow.style.flexDirection = FlexDirection.Row;
|
||||||
|
foldout.Add(elementRow);
|
||||||
|
|
||||||
|
string showInfo = collectAssetInfo.AssetPath;
|
||||||
|
if (_enableAddressableToogle.value)
|
||||||
|
{
|
||||||
|
IAddressRule instance = AssetBundleCollectorSettingData.GetAddressRuleInstance(collector.AddressRuleName);
|
||||||
|
AddressRuleData ruleData = new AddressRuleData(collectAssetInfo.AssetPath, collector.CollectPath, group.GroupName);
|
||||||
|
string addressValue = instance.GetAssetAddress(ruleData);
|
||||||
|
showInfo = $"[{addressValue}] {showInfo}";
|
||||||
|
}
|
||||||
|
|
||||||
|
var label = new Label();
|
||||||
|
label.text = showInfo;
|
||||||
|
label.style.width = 300;
|
||||||
|
label.style.marginLeft = 0;
|
||||||
|
label.style.flexGrow = 1;
|
||||||
|
elementRow.Add(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void AddCollectorBtn_clicked()
|
||||||
|
{
|
||||||
|
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||||
|
if (selectGroup == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AssetBundleCollectorSettingData.CreateCollector(selectGroup, string.Empty);
|
||||||
|
FillCollectorViewData();
|
||||||
|
}
|
||||||
|
private void RemoveCollectorBtn_clicked(AssetBundleCollector selectCollector)
|
||||||
|
{
|
||||||
|
var selectGroup = _groupListView.selectedItem as AssetBundleCollectorGroup;
|
||||||
|
if (selectGroup == null)
|
||||||
|
return;
|
||||||
|
if (selectCollector == null)
|
||||||
|
return;
|
||||||
|
AssetBundleCollectorSettingData.RemoveCollector(selectGroup, selectCollector);
|
||||||
|
FillCollectorViewData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetCollectorTypeIndex(string typeName)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collectorTypeList.Count; i++)
|
||||||
|
{
|
||||||
|
if (_collectorTypeList[i] == typeName)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
private int GetAddressRuleIndex(string ruleName)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _addressRuleList.Count; i++)
|
||||||
|
{
|
||||||
|
if (_addressRuleList[i] == ruleName)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
private int GetPackRuleIndex(string ruleName)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _packRuleList.Count; i++)
|
||||||
|
{
|
||||||
|
if (_packRuleList[i] == ruleName)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
private int GetFilterRuleIndex(string ruleName)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _filterRuleList.Count; i++)
|
||||||
|
{
|
||||||
|
if (_filterRuleList[i] == ruleName)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,31 +1,30 @@
|
|||||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||||
<uie:Toolbar name="Toolbar" style="display: flex;">
|
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
|
||||||
<uie:ToolbarSearchField focusable="true" name="SearchField" style="width: 300px; flex-grow: 1;" />
|
|
||||||
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
<ui:Button text="导出" display-tooltip-when-elided="true" name="ExportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||||
<ui:Button text="导入" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
<ui:Button text="导入" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
<ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;">
|
<ui:VisualElement name="ContentContainer" style="flex-grow: 1; flex-direction: row;">
|
||||||
<ui:VisualElement name="LeftContainer" style="width: 200px; flex-grow: 0; background-color: rgb(67, 67, 67); border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
<ui:VisualElement name="LeftContainer" style="width: 200px; flex-grow: 0; background-color: rgb(67, 67, 67); border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||||
<ui:ListView focusable="true" name="GrouperListView" item-height="20" style="flex-grow: 1;" />
|
<ui:ListView focusable="true" name="GroupListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||||
<ui:VisualElement name="GrouperAddContainer" style="height: 20px; flex-direction: row; justify-content: center;">
|
<ui:VisualElement name="GroupAddContainer" style="height: 20px; flex-direction: row; justify-content: center;">
|
||||||
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
|
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
|
||||||
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
|
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
<ui:VisualElement name="RightContainer" style="flex-direction: column; flex-grow: 1;">
|
<ui:VisualElement name="RightContainer" style="flex-direction: column; flex-grow: 1;">
|
||||||
<ui:VisualElement name="ShaderContainer" style="height: 30px; background-color: rgb(67, 67, 67); flex-direction: row; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
<ui:VisualElement name="PublicContainer" style="height: 30px; background-color: rgb(67, 67, 67); flex-direction: row; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||||
|
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
|
||||||
<ui:Toggle label="Auto Collect Shaders" name="AutoCollectShader" style="width: 196px; -unity-text-align: middle-left;" />
|
<ui:Toggle label="Auto Collect Shaders" name="AutoCollectShader" style="width: 196px; -unity-text-align: middle-left;" />
|
||||||
<ui:TextField picking-mode="Ignore" label="Shader Bundle Name" name="ShaderBundleName" style="flex-grow: 1; -unity-text-align: middle-left;" />
|
<ui:TextField picking-mode="Ignore" label="Shader Bundle Name" name="ShaderBundleName" style="flex-grow: 1; -unity-text-align: middle-left;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
<ui:VisualElement name="GrouperContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
<ui:VisualElement name="GroupContainer" style="flex-grow: 1; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||||
<ui:TextField picking-mode="Ignore" label="Grouper Name" name="GrouperName" />
|
<ui:TextField picking-mode="Ignore" label="Group Name" name="GroupName" />
|
||||||
<ui:TextField picking-mode="Ignore" label="Grouper Desc" name="GrouperDesc" />
|
<ui:TextField picking-mode="Ignore" label="Group Desc" name="GroupDesc" />
|
||||||
<ui:TextField picking-mode="Ignore" label="Grouper Asset Tags" name="GrouperAssetTags" />
|
<ui:TextField picking-mode="Ignore" label="Group Asset Tags" name="GroupAssetTags" />
|
||||||
<ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;">
|
<ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;">
|
||||||
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
|
<ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" />
|
||||||
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
|
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
<ui:ListView focusable="true" name="CollectorListView" item-height="50" style="flex-grow: 1;" />
|
<ui:ScrollView name="CollectorScrollView" style="flex-grow: 1;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
@@ -5,11 +5,21 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
public class CollectAssetInfo
|
public class CollectAssetInfo
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 收集器类型
|
||||||
|
/// </summary>
|
||||||
|
public ECollectorType CollectorType { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包名称
|
/// 资源包名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BundleName { private set; get; }
|
public string BundleName { private set; get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 可寻址地址
|
||||||
|
/// </summary>
|
||||||
|
public string Address { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源路径
|
/// 资源路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -25,32 +35,20 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsRawAsset { private set; get; }
|
public bool IsRawAsset { private set; get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 不写入资源列表
|
|
||||||
/// </summary>
|
|
||||||
public bool NotWriteToAssetList { private set; get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 依赖的资源列表
|
/// 依赖的资源列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> DependAssets = new List<string>();
|
public List<string> DependAssets = new List<string>();
|
||||||
|
|
||||||
|
|
||||||
public CollectAssetInfo(string bundleName, string assetPath, List<string> assetTags, bool isRawAsset, bool notWriteToAssetList)
|
public CollectAssetInfo(ECollectorType collectorType, string bundleName, string address, string assetPath, List<string> assetTags, bool isRawAsset)
|
||||||
{
|
{
|
||||||
|
CollectorType = collectorType;
|
||||||
BundleName = bundleName;
|
BundleName = bundleName;
|
||||||
|
Address = address;
|
||||||
AssetPath = assetPath;
|
AssetPath = assetPath;
|
||||||
AssetTags = assetTags;
|
AssetTags = assetTags;
|
||||||
IsRawAsset = isRawAsset;
|
IsRawAsset = isRawAsset;
|
||||||
NotWriteToAssetList = notWriteToAssetList;
|
|
||||||
}
|
|
||||||
public CollectAssetInfo(string assetPath, List<string> assetTags, bool isRawAsset, bool notWriteToAssetList)
|
|
||||||
{
|
|
||||||
BundleName = string.Empty;
|
|
||||||
AssetPath = assetPath;
|
|
||||||
AssetTags = assetTags;
|
|
||||||
IsRawAsset = isRawAsset;
|
|
||||||
NotWriteToAssetList = notWriteToAssetList;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 以文件名为定位地址
|
||||||
|
/// </summary>
|
||||||
|
public class AddressByFileName : IAddressRule
|
||||||
|
{
|
||||||
|
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||||
|
{
|
||||||
|
return Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 以组名+文件名为定位地址
|
||||||
|
/// </summary>
|
||||||
|
public class AddressByGroupAndFileName : IAddressRule
|
||||||
|
{
|
||||||
|
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||||
|
{
|
||||||
|
string fileName = Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||||
|
return $"{data.GroupName}_{fileName}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 以收集器名+文件名为定位地址
|
||||||
|
/// </summary>
|
||||||
|
public class AddressByCollectorAndFileName : IAddressRule
|
||||||
|
{
|
||||||
|
string IAddressRule.GetAssetAddress(AddressRuleData data)
|
||||||
|
{
|
||||||
|
string fileName = Path.GetFileNameWithoutExtension(data.AssetPath);
|
||||||
|
string collectorName = Path.GetFileNameWithoutExtension(data.CollectPath);
|
||||||
|
return $"{collectorName}_{fileName}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6df37bfd87103a54ca60c0c467a5f33b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -7,30 +7,64 @@ namespace YooAsset.Editor
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 以文件路径作为资源包名
|
/// 以文件路径作为资源包名
|
||||||
/// 注意:每个文件独自打资源包
|
/// 注意:每个文件独自打资源包
|
||||||
|
/// 例如:收集器路径为 "Assets/UIPanel"
|
||||||
|
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop/image/backgroud.bundle"
|
||||||
|
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop/view/main.bundle"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PackSeparately : IPackRule
|
public class PackSeparately : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
{
|
{
|
||||||
return StringUtility.RemoveExtension(data.AssetPath); //"Assets/Config/test.txt" --> "Assets/Config/test"
|
return StringUtility.RemoveExtension(data.AssetPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 以父类文件夹路径作为资源包名
|
/// 以父类文件夹路径作为资源包名
|
||||||
/// 注意:文件夹下所有文件打进一个资源包
|
/// 注意:文件夹下所有文件打进一个资源包
|
||||||
|
/// 例如:收集器路径为 "Assets/UIPanel"
|
||||||
|
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop/image.bundle"
|
||||||
|
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop/view.bundle"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PackDirectory : IPackRule
|
public class PackDirectory : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
{
|
{
|
||||||
return Path.GetDirectoryName(data.AssetPath); //"Assets/Config/test.txt" --> "Assets/Config"
|
return Path.GetDirectoryName(data.AssetPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 以收集器路径下顶级文件夹为资源包名
|
||||||
|
/// 注意:文件夹下所有文件打进一个资源包
|
||||||
|
/// 例如:收集器路径为 "Assets/UIPanel"
|
||||||
|
/// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets/uipanel/shop.bundle"
|
||||||
|
/// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets/uipanel/shop.bundle"
|
||||||
|
/// </summary>
|
||||||
|
public class PackTopDirectory : IPackRule
|
||||||
|
{
|
||||||
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
|
{
|
||||||
|
string assetPath = data.AssetPath.Replace(data.CollectPath, string.Empty);
|
||||||
|
assetPath = assetPath.TrimStart('/');
|
||||||
|
string[] splits = assetPath.Split('/');
|
||||||
|
if (splits.Length > 0)
|
||||||
|
{
|
||||||
|
if (Path.HasExtension(splits[0]))
|
||||||
|
throw new Exception($"Not found root directory : {assetPath}");
|
||||||
|
string bundleName = $"{data.CollectPath}/{splits[0]}";
|
||||||
|
return bundleName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception($"Not found root directory : {assetPath}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 以收集器路径作为资源包名
|
/// 以收集器路径作为资源包名
|
||||||
/// 注意:收集器下所有文件打进一个资源包
|
/// 注意:收集的所有文件打进一个资源包
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PackCollector : IPackRule
|
public class PackCollector : IPackRule
|
||||||
{
|
{
|
||||||
@@ -42,13 +76,13 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 以分组名称作为资源包名
|
/// 以分组名称作为资源包名
|
||||||
/// 注意:分组内所有文件打进一个资源包
|
/// 注意:收集的所有文件打进一个资源包
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PackGrouper : IPackRule
|
public class PackGroup : IPackRule
|
||||||
{
|
{
|
||||||
string IPackRule.GetBundleName(PackRuleData data)
|
string IPackRule.GetBundleName(PackRuleData data)
|
||||||
{
|
{
|
||||||
return data.GrouperName;
|
return data.GroupName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public enum ECollectorType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 收集参与打包的主资源对象,并写入到资源清单的资源列表里(可以通过代码加载)。
|
||||||
|
/// </summary>
|
||||||
|
MainAssetCollector,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 收集参与打包的主资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
|
||||||
|
/// </summary>
|
||||||
|
StaticAssetCollector,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 收集参与打包的依赖资源对象,但不写入到资源清单的资源列表里(无法通过代码加载)。
|
||||||
|
/// 注意:如果依赖资源对象没有被主资源对象引用,则不参与打包构建。
|
||||||
|
/// </summary>
|
||||||
|
DependAssetCollector,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 该收集器类型不能被设置
|
||||||
|
/// </summary>
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4bbef9cb5c1a40b41a28a65df3449abe
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
25
Assets/YooAsset/Editor/AssetBundleCollector/IAddressRule.cs
Normal file
25
Assets/YooAsset/Editor/AssetBundleCollector/IAddressRule.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public struct AddressRuleData
|
||||||
|
{
|
||||||
|
public string AssetPath;
|
||||||
|
public string CollectPath;
|
||||||
|
public string GroupName;
|
||||||
|
|
||||||
|
public AddressRuleData(string assetPath, string collectPath, string groupName)
|
||||||
|
{
|
||||||
|
AssetPath = assetPath;
|
||||||
|
CollectPath = collectPath;
|
||||||
|
GroupName = groupName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 寻址规则接口
|
||||||
|
/// </summary>
|
||||||
|
public interface IAddressRule
|
||||||
|
{
|
||||||
|
string GetAssetAddress(AddressRuleData data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 426a4ff47699b6844946329f54a89128
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -5,19 +5,19 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
public string AssetPath;
|
public string AssetPath;
|
||||||
public string CollectPath;
|
public string CollectPath;
|
||||||
public string GrouperName;
|
public string GroupName;
|
||||||
|
|
||||||
public PackRuleData(string assetPath)
|
public PackRuleData(string assetPath)
|
||||||
{
|
{
|
||||||
AssetPath = assetPath;
|
AssetPath = assetPath;
|
||||||
CollectPath = string.Empty;
|
CollectPath = string.Empty;
|
||||||
GrouperName = string.Empty;
|
GroupName = string.Empty;
|
||||||
}
|
}
|
||||||
public PackRuleData(string assetPath, string collectPath, string grouperName)
|
public PackRuleData(string assetPath, string collectPath, string groupName)
|
||||||
{
|
{
|
||||||
AssetPath = assetPath;
|
AssetPath = assetPath;
|
||||||
CollectPath = collectPath;
|
CollectPath = collectPath;
|
||||||
GrouperName = grouperName;
|
GroupName = groupName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#if UNITY_2019_4_OR_NEWER
|
#if UNITY_2019_4_OR_NEWER
|
||||||
|
using System;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
@@ -11,8 +12,7 @@ namespace YooAsset.Editor
|
|||||||
[MenuItem("YooAsset/AssetBundle Debugger", false, 104)]
|
[MenuItem("YooAsset/AssetBundle Debugger", false, 104)]
|
||||||
public static void ShowExample()
|
public static void ShowExample()
|
||||||
{
|
{
|
||||||
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>();
|
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>("资源包调试工具", true, EditorDefine.DockedWindowTypes);
|
||||||
wnd.titleContent = new GUIContent("资源包调试工具");
|
|
||||||
wnd.minSize = new Vector2(800, 600);
|
wnd.minSize = new Vector2(800, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,8 +38,8 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ToolbarMenu _viewModeMenu;
|
private ToolbarMenu _viewModeMenu;
|
||||||
private AssetListDebuggerViewer _assetListViewer;
|
private DebuggerAssetListViewer _assetListViewer;
|
||||||
private BundleListDebuggerViewer _bundleListViewer;
|
private DebuggerBundleListViewer _bundleListViewer;
|
||||||
|
|
||||||
private EViewMode _viewMode;
|
private EViewMode _viewMode;
|
||||||
private readonly DebugReport _debugReport = new DebugReport();
|
private readonly DebugReport _debugReport = new DebugReport();
|
||||||
@@ -48,45 +48,50 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
public void CreateGUI()
|
public void CreateGUI()
|
||||||
{
|
{
|
||||||
VisualElement root = rootVisualElement;
|
try
|
||||||
|
{
|
||||||
|
VisualElement root = rootVisualElement;
|
||||||
|
|
||||||
// 加载布局文件
|
// 加载布局文件
|
||||||
string rootPath = EditorTools.GetYooAssetPath();
|
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleDebuggerUXML;
|
||||||
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/{nameof(AssetBundleDebuggerWindow)}.uxml";
|
if (visualAsset == null)
|
||||||
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
{
|
||||||
if (visualAsset == null)
|
Debug.LogError($"Not found {nameof(AssetBundleDebuggerWindow)}.uxml in settings.");
|
||||||
{
|
return;
|
||||||
Debug.LogError($"Not found {nameof(AssetBundleDebuggerWindow)}.uxml : {uxml}");
|
}
|
||||||
return;
|
visualAsset.CloneTree(root);
|
||||||
|
|
||||||
|
// 采样按钮
|
||||||
|
var sampleBtn = root.Q<Button>("SampleButton");
|
||||||
|
sampleBtn.clicked += SampleBtn_onClick;
|
||||||
|
|
||||||
|
// 视口模式菜单
|
||||||
|
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
||||||
|
//_viewModeMenu.menu.AppendAction(EViewMode.MemoryView.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
|
||||||
|
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
|
||||||
|
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
|
||||||
|
|
||||||
|
// 搜索栏
|
||||||
|
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||||
|
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
||||||
|
|
||||||
|
// 加载视图
|
||||||
|
_assetListViewer = new DebuggerAssetListViewer();
|
||||||
|
_assetListViewer.InitViewer();
|
||||||
|
|
||||||
|
// 加载视图
|
||||||
|
_bundleListViewer = new DebuggerBundleListViewer();
|
||||||
|
_bundleListViewer.InitViewer();
|
||||||
|
|
||||||
|
// 显示视图
|
||||||
|
_viewMode = EViewMode.AssetView;
|
||||||
|
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
||||||
|
_assetListViewer.AttachParent(root);
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError(e.ToString());
|
||||||
}
|
}
|
||||||
visualAsset.CloneTree(root);
|
|
||||||
|
|
||||||
// 采样按钮
|
|
||||||
var sampleBtn = root.Q<Button>("SampleButton");
|
|
||||||
sampleBtn.clicked += SampleBtn_onClick;
|
|
||||||
|
|
||||||
// 视口模式菜单
|
|
||||||
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
|
||||||
//_viewModeMenu.menu.AppendAction(EViewMode.MemoryView.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
|
|
||||||
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
|
|
||||||
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
|
|
||||||
|
|
||||||
// 搜索栏
|
|
||||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
|
||||||
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
|
||||||
|
|
||||||
// 加载视图
|
|
||||||
_assetListViewer = new AssetListDebuggerViewer();
|
|
||||||
_assetListViewer.InitViewer();
|
|
||||||
|
|
||||||
// 加载视图
|
|
||||||
_bundleListViewer = new BundleListDebuggerViewer();
|
|
||||||
_bundleListViewer.InitViewer();
|
|
||||||
|
|
||||||
// 显示视图
|
|
||||||
_viewMode = EViewMode.AssetView;
|
|
||||||
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
|
||||||
_assetListViewer.AttachParent(root);
|
|
||||||
}
|
}
|
||||||
private void SampleBtn_onClick()
|
private void SampleBtn_onClick()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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">
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||||
<uie:Toolbar name="Toolbar" style="display: flex;">
|
<uie:Toolbar name="Toolbar" style="display: flex;">
|
||||||
<uie:ToolbarButton text="刷新" display-tooltip-when-elided="true" name="SampleButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" />
|
|
||||||
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" />
|
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" />
|
||||||
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
|
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
|
||||||
|
<uie:ToolbarButton text="刷新" display-tooltip-when-elided="true" name="SampleButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
internal class AssetListDebuggerViewer
|
internal class DebuggerAssetListViewer
|
||||||
{
|
{
|
||||||
private VisualTreeAsset _visualAsset;
|
private VisualTreeAsset _visualAsset;
|
||||||
private TemplateContainer _root;
|
private TemplateContainer _root;
|
||||||
@@ -23,13 +23,11 @@ namespace YooAsset.Editor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void InitViewer()
|
public void InitViewer()
|
||||||
{
|
{
|
||||||
// 加载布局文件
|
// 加载布局文件
|
||||||
string rootPath = EditorTools.GetYooAssetPath();
|
_visualAsset = YooAssetEditorSettingsData.Setting.DebuggerAssetListViewerUXML;
|
||||||
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(AssetListDebuggerViewer)}.uxml";
|
|
||||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
|
||||||
if (_visualAsset == null)
|
if (_visualAsset == null)
|
||||||
{
|
{
|
||||||
Debug.LogError($"Not found {nameof(AssetListDebuggerViewer)}.uxml : {uxml}");
|
Debug.LogError($"Not found {nameof(DebuggerAssetListViewer)}.uxml in settings.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_root = _visualAsset.CloneTree();
|
_root = _visualAsset.CloneTree();
|
||||||
@@ -58,7 +56,9 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
_debugReport = debugReport;
|
_debugReport = debugReport;
|
||||||
_assetListView.Clear();
|
_assetListView.Clear();
|
||||||
|
_assetListView.ClearSelection();
|
||||||
_assetListView.itemsSource = FilterViewItems(debugReport, searchKeyWord);
|
_assetListView.itemsSource = FilterViewItems(debugReport, searchKeyWord);
|
||||||
|
_assetListView.Rebuild();
|
||||||
}
|
}
|
||||||
private List<DebugProviderInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
|
private List<DebugProviderInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
|
||||||
{
|
{
|
||||||
@@ -114,7 +114,7 @@ namespace YooAsset.Editor
|
|||||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
label.style.marginLeft = 3f;
|
label.style.marginLeft = 3f;
|
||||||
//label.style.flexGrow = 1f;
|
//label.style.flexGrow = 1f;
|
||||||
label.style.width = 100;
|
label.style.width = 150;
|
||||||
element.Add(label);
|
element.Add(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +124,26 @@ namespace YooAsset.Editor
|
|||||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
label.style.marginLeft = 3f;
|
label.style.marginLeft = 3f;
|
||||||
//label.style.flexGrow = 1f;
|
//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;
|
label.style.width = 120;
|
||||||
element.Add(label);
|
element.Add(label);
|
||||||
}
|
}
|
||||||
@@ -139,9 +159,17 @@ namespace YooAsset.Editor
|
|||||||
var label1 = element.Q<Label>("Label1");
|
var label1 = element.Q<Label>("Label1");
|
||||||
label1.text = providerInfo.AssetPath;
|
label1.text = providerInfo.AssetPath;
|
||||||
|
|
||||||
// Ref Count
|
// Spawn Scene
|
||||||
var label2 = element.Q<Label>("Label2");
|
var label2 = element.Q<Label>("Label2");
|
||||||
label2.text = providerInfo.RefCount.ToString();
|
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
|
// Status
|
||||||
StyleColor textColor;
|
StyleColor textColor;
|
||||||
@@ -149,9 +177,9 @@ namespace YooAsset.Editor
|
|||||||
textColor = new StyleColor(Color.yellow);
|
textColor = new StyleColor(Color.yellow);
|
||||||
else
|
else
|
||||||
textColor = label1.style.color;
|
textColor = label1.style.color;
|
||||||
var label3 = element.Q<Label>("Label3");
|
var label5 = element.Q<Label>("Label5");
|
||||||
label3.text = providerInfo.Status.ToString();
|
label5.text = providerInfo.Status.ToString();
|
||||||
label3.style.color = textColor;
|
label5.style.color = textColor;
|
||||||
}
|
}
|
||||||
private void AssetListView_onSelectionChange(IEnumerable<object> objs)
|
private void AssetListView_onSelectionChange(IEnumerable<object> objs)
|
||||||
{
|
{
|
||||||
@@ -178,16 +206,6 @@ namespace YooAsset.Editor
|
|||||||
element.Add(label);
|
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();
|
var label = new Label();
|
||||||
label.name = "Label3";
|
label.name = "Label3";
|
||||||
@@ -219,10 +237,6 @@ namespace YooAsset.Editor
|
|||||||
var label1 = element.Q<Label>("Label1");
|
var label1 = element.Q<Label>("Label1");
|
||||||
label1.text = bundleInfo.BundleName;
|
label1.text = bundleInfo.BundleName;
|
||||||
|
|
||||||
// Version
|
|
||||||
var label2 = element.Q<Label>("Label2");
|
|
||||||
label2.text = bundleInfo.Version.ToString();
|
|
||||||
|
|
||||||
// Ref Count
|
// Ref Count
|
||||||
var label3 = element.Q<Label>("Label3");
|
var label3 = element.Q<Label>("Label3");
|
||||||
label3.text = bundleInfo.RefCount.ToString();
|
label3.text = bundleInfo.RefCount.ToString();
|
||||||
@@ -236,6 +250,7 @@ namespace YooAsset.Editor
|
|||||||
_dependListView.Clear();
|
_dependListView.Clear();
|
||||||
_dependListView.ClearSelection();
|
_dependListView.ClearSelection();
|
||||||
_dependListView.itemsSource = providerInfo.BundleInfos;
|
_dependListView.itemsSource = providerInfo.BundleInfos;
|
||||||
|
_dependListView.Rebuild();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,18 +2,19 @@
|
|||||||
<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;">
|
<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: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="Asset Path" 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="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
<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="Status" display-tooltip-when-elided="true" name="TopBar3" style="width: 120px; -unity-text-align: middle-left;" />
|
<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="Ref Count" display-tooltip-when-elided="true" name="TopBar4" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||||
|
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar5" style="width: 120px; -unity-text-align: middle-left;" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
<ui:ListView focusable="true" name="TopListView" item-height="18" style="flex-grow: 1;" />
|
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||||
</ui:VisualElement>
|
</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;">
|
<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: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="Depend Bundles" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||||
<uie:ToolbarButton text="Version" display-tooltip-when-elided="true" name="BottomBar2" style="width: 100px; -unity-text-align: middle-left;" />
|
|
||||||
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
|
<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:ToolbarButton text="Status" display-tooltip-when-elided="true" name="BottomBar4" style="width: 120px; -unity-text-align: middle-left;" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
<ui:ListView focusable="true" name="BottomListView" item-height="18" style="flex-grow: 1;" />
|
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
@@ -9,13 +9,13 @@ using UnityEngine.UIElements;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
internal class BundleListDebuggerViewer
|
internal class DebuggerBundleListViewer
|
||||||
{
|
{
|
||||||
private VisualTreeAsset _visualAsset;
|
private VisualTreeAsset _visualAsset;
|
||||||
private TemplateContainer _root;
|
private TemplateContainer _root;
|
||||||
|
|
||||||
private ListView _bundleListView;
|
private ListView _bundleListView;
|
||||||
private ListView _includeListView;
|
private ListView _usingListView;
|
||||||
private DebugReport _debugReport;
|
private DebugReport _debugReport;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -24,18 +24,16 @@ namespace YooAsset.Editor
|
|||||||
public void InitViewer()
|
public void InitViewer()
|
||||||
{
|
{
|
||||||
// 加载布局文件
|
// 加载布局文件
|
||||||
string rootPath = EditorTools.GetYooAssetPath();
|
_visualAsset = YooAssetEditorSettingsData.Setting.DebuggerBundleListViewerUXML;
|
||||||
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(BundleListDebuggerViewer)}.uxml";
|
|
||||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
|
||||||
if (_visualAsset == null)
|
if (_visualAsset == null)
|
||||||
{
|
{
|
||||||
Debug.LogError($"Not found {nameof(BundleListDebuggerViewer)}.uxml : {uxml}");
|
Debug.LogError($"Not found {nameof(DebuggerBundleListViewer)}.uxml in settings.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_root = _visualAsset.CloneTree();
|
_root = _visualAsset.CloneTree();
|
||||||
_root.style.flexGrow = 1f;
|
_root.style.flexGrow = 1f;
|
||||||
|
|
||||||
// 资源列表
|
// 资源包列表
|
||||||
_bundleListView = _root.Q<ListView>("TopListView");
|
_bundleListView = _root.Q<ListView>("TopListView");
|
||||||
_bundleListView.makeItem = MakeAssetListViewItem;
|
_bundleListView.makeItem = MakeAssetListViewItem;
|
||||||
_bundleListView.bindItem = BindAssetListViewItem;
|
_bundleListView.bindItem = BindAssetListViewItem;
|
||||||
@@ -45,10 +43,10 @@ namespace YooAsset.Editor
|
|||||||
#else
|
#else
|
||||||
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
|
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
|
||||||
#endif
|
#endif
|
||||||
// 依赖列表
|
// 使用列表
|
||||||
_includeListView = _root.Q<ListView>("BottomListView");
|
_usingListView = _root.Q<ListView>("BottomListView");
|
||||||
_includeListView.makeItem = MakeIncludeListViewItem;
|
_usingListView.makeItem = MakeIncludeListViewItem;
|
||||||
_includeListView.bindItem = BindIncludeListViewItem;
|
_usingListView.bindItem = BindIncludeListViewItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -58,24 +56,27 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
_debugReport = debugReport;
|
_debugReport = debugReport;
|
||||||
_bundleListView.Clear();
|
_bundleListView.Clear();
|
||||||
|
_bundleListView.ClearSelection();
|
||||||
_bundleListView.itemsSource = FilterViewItems(debugReport, searchKeyWord);
|
_bundleListView.itemsSource = FilterViewItems(debugReport, searchKeyWord);
|
||||||
|
_bundleListView.Rebuild();
|
||||||
}
|
}
|
||||||
private List<DebugBundleInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
|
private List<DebugBundleInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
|
||||||
{
|
{
|
||||||
var result = new List<DebugBundleInfo>(debugReport.ProviderInfos.Count);
|
Dictionary<string, DebugBundleInfo> result = new Dictionary<string, DebugBundleInfo>(debugReport.ProviderInfos.Count);
|
||||||
foreach (var providerInfo in debugReport.ProviderInfos)
|
foreach (var providerInfo in debugReport.ProviderInfos)
|
||||||
{
|
{
|
||||||
foreach(var bundleInfo in providerInfo.BundleInfos)
|
foreach (var bundleInfo in providerInfo.BundleInfos)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(searchKeyWord) == false)
|
if (string.IsNullOrEmpty(searchKeyWord) == false)
|
||||||
{
|
{
|
||||||
if (bundleInfo.BundleName.Contains(searchKeyWord) == false)
|
if (bundleInfo.BundleName.Contains(searchKeyWord) == false)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result.Add(bundleInfo);
|
if (result.ContainsKey(bundleInfo.BundleName) == false)
|
||||||
|
result.Add(bundleInfo.BundleName, bundleInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result.Values.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -94,7 +95,7 @@ namespace YooAsset.Editor
|
|||||||
_root.RemoveFromHierarchy();
|
_root.RemoveFromHierarchy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 顶部列表相关
|
// 顶部列表相关
|
||||||
private VisualElement MakeAssetListViewItem()
|
private VisualElement MakeAssetListViewItem()
|
||||||
{
|
{
|
||||||
@@ -111,16 +112,6 @@ namespace YooAsset.Editor
|
|||||||
element.Add(label);
|
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();
|
var label = new Label();
|
||||||
label.name = "Label3";
|
label.name = "Label3";
|
||||||
@@ -152,17 +143,13 @@ namespace YooAsset.Editor
|
|||||||
var label1 = element.Q<Label>("Label1");
|
var label1 = element.Q<Label>("Label1");
|
||||||
label1.text = bundleInfo.BundleName;
|
label1.text = bundleInfo.BundleName;
|
||||||
|
|
||||||
// Version
|
|
||||||
var label2 = element.Q<Label>("Label2");
|
|
||||||
label2.text = bundleInfo.Version.ToString();
|
|
||||||
|
|
||||||
// Ref Count
|
// Ref Count
|
||||||
var label3 = element.Q<Label>("Label3");
|
var label3 = element.Q<Label>("Label3");
|
||||||
label3.text = bundleInfo.RefCount.ToString();
|
label3.text = bundleInfo.RefCount.ToString();
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
StyleColor textColor;
|
StyleColor textColor;
|
||||||
if (bundleInfo.Status == AssetBundleLoader.EStatus.Fail)
|
if (bundleInfo.Status == AssetBundleLoaderBase.EStatus.Failed)
|
||||||
textColor = new StyleColor(Color.yellow);
|
textColor = new StyleColor(Color.yellow);
|
||||||
else
|
else
|
||||||
textColor = label1.style.color;
|
textColor = label1.style.color;
|
||||||
@@ -175,7 +162,7 @@ namespace YooAsset.Editor
|
|||||||
foreach (var item in objs)
|
foreach (var item in objs)
|
||||||
{
|
{
|
||||||
DebugBundleInfo bundleInfo = item as DebugBundleInfo;
|
DebugBundleInfo bundleInfo = item as DebugBundleInfo;
|
||||||
FillIncludeListView(bundleInfo);
|
FillUsingListView(bundleInfo.BundleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +188,7 @@ namespace YooAsset.Editor
|
|||||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
label.style.marginLeft = 3f;
|
label.style.marginLeft = 3f;
|
||||||
//label.style.flexGrow = 1f;
|
//label.style.flexGrow = 1f;
|
||||||
label.style.width = 100;
|
label.style.width = 150;
|
||||||
element.Add(label);
|
element.Add(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,41 +198,76 @@ namespace YooAsset.Editor
|
|||||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
label.style.marginLeft = 3f;
|
label.style.marginLeft = 3f;
|
||||||
//label.style.flexGrow = 1f;
|
//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;
|
label.style.width = 100;
|
||||||
element.Add(label);
|
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;
|
return element;
|
||||||
}
|
}
|
||||||
private void BindIncludeListViewItem(VisualElement element, int index)
|
private void BindIncludeListViewItem(VisualElement element, int index)
|
||||||
{
|
{
|
||||||
List<DebugProviderInfo> providers = _includeListView.itemsSource as List<DebugProviderInfo>;
|
List<DebugProviderInfo> providers = _usingListView.itemsSource as List<DebugProviderInfo>;
|
||||||
DebugProviderInfo providerInfo = providers[index];
|
DebugProviderInfo providerInfo = providers[index];
|
||||||
|
|
||||||
// Asset Path
|
// Asset Path
|
||||||
var label1 = element.Q<Label>("Label1");
|
var label1 = element.Q<Label>("Label1");
|
||||||
label1.text = providerInfo.AssetPath;
|
label1.text = providerInfo.AssetPath;
|
||||||
|
|
||||||
// Ref Count
|
// Spawn Scene
|
||||||
var label2 = element.Q<Label>("Label2");
|
var label2 = element.Q<Label>("Label2");
|
||||||
label2.text = providerInfo.RefCount.ToString();
|
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
|
// Status
|
||||||
var label3 = element.Q<Label>("Label3");
|
var label5 = element.Q<Label>("Label5");
|
||||||
label3.text = providerInfo.Status.ToString();
|
label5.text = providerInfo.Status.ToString();
|
||||||
}
|
}
|
||||||
private void FillIncludeListView(DebugBundleInfo bundleInfo)
|
private void FillUsingListView(string bundleName)
|
||||||
{
|
{
|
||||||
_includeListView.Clear();
|
List<DebugProviderInfo> source = new List<DebugProviderInfo>();
|
||||||
_includeListView.ClearSelection();
|
foreach (var providerInfo in _debugReport.ProviderInfos)
|
||||||
|
|
||||||
List<DebugProviderInfo> source = new List<DebugProviderInfo>();
|
|
||||||
foreach(var providerInfo in _debugReport.ProviderInfos)
|
|
||||||
{
|
{
|
||||||
if (providerInfo.BundleInfos.Contains(bundleInfo))
|
foreach (var bundleInfo in providerInfo.BundleInfos)
|
||||||
source.Add(providerInfo);
|
{
|
||||||
|
if (bundleInfo.BundleName == bundleName)
|
||||||
|
{
|
||||||
|
source.Add(providerInfo);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_includeListView.itemsSource = source;
|
|
||||||
|
_usingListView.Clear();
|
||||||
|
_usingListView.ClearSelection();
|
||||||
|
_usingListView.itemsSource = source;
|
||||||
|
_usingListView.Rebuild();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,18 +2,19 @@
|
|||||||
<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;">
|
<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: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="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||||
<uie:ToolbarButton text="Version" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left;" />
|
|
||||||
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar3" style="width: 100px; -unity-text-align: middle-left;" />
|
<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:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar4" style="width: 120px; -unity-text-align: middle-left;" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
<ui:ListView focusable="true" name="TopListView" item-height="18" style="flex-grow: 1;" />
|
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||||
</ui:VisualElement>
|
</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;">
|
<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: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="Using Assets" 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="Spawn Scene" display-tooltip-when-elided="true" name="BottomBar2" style="width: 150px; -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: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>
|
</uie:Toolbar>
|
||||||
<ui:ListView focusable="true" name="BottomListView" item-height="18" style="flex-grow: 1;" />
|
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
@@ -1,203 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using UnityEditor;
|
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
public class AssetBundleCollector
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 收集路径
|
|
||||||
/// 注意:支持文件夹或单个资源文件
|
|
||||||
/// </summary>
|
|
||||||
public string CollectPath = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 打包规则类名
|
|
||||||
/// </summary>
|
|
||||||
public string PackRuleName = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 过滤规则类名
|
|
||||||
/// </summary>
|
|
||||||
public string FilterRuleName = string.Empty;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 不写入资源列表
|
|
||||||
/// </summary>
|
|
||||||
public bool NotWriteToAssetList = false;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源分类标签
|
|
||||||
/// </summary>
|
|
||||||
public string AssetTags = string.Empty;
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检测配置错误
|
|
||||||
/// </summary>
|
|
||||||
public void CheckConfigError()
|
|
||||||
{
|
|
||||||
if (AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(CollectPath) == null)
|
|
||||||
throw new Exception($"Invalid collect path : {CollectPath}");
|
|
||||||
|
|
||||||
if (AssetBundleGrouperSettingData.HasPackRuleName(PackRuleName) == false)
|
|
||||||
throw new Exception($"Invalid {nameof(IPackRule)} class type : {PackRuleName}");
|
|
||||||
|
|
||||||
if (AssetBundleGrouperSettingData.HasFilterRuleName(FilterRuleName) == false)
|
|
||||||
throw new Exception($"Invalid {nameof(IFilterRule)} class type : {FilterRuleName}");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取打包收集的资源文件
|
|
||||||
/// </summary>
|
|
||||||
public List<CollectAssetInfo> GetAllCollectAssets(AssetBundleGrouper grouper)
|
|
||||||
{
|
|
||||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
|
|
||||||
bool isRawAsset = PackRuleName == nameof(PackRawFile);
|
|
||||||
|
|
||||||
// 如果是文件夹
|
|
||||||
if (AssetDatabase.IsValidFolder(CollectPath))
|
|
||||||
{
|
|
||||||
string collectDirectory = CollectPath;
|
|
||||||
string[] findAssets = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
|
||||||
foreach (string assetPath in findAssets)
|
|
||||||
{
|
|
||||||
if (IsValidateAsset(assetPath) == false)
|
|
||||||
continue;
|
|
||||||
if (IsCollectAsset(assetPath) == false)
|
|
||||||
continue;
|
|
||||||
if (result.ContainsKey(assetPath) == false)
|
|
||||||
{
|
|
||||||
string bundleName = GetBundleName(grouper, assetPath, isRawAsset);
|
|
||||||
List<string> assetTags = GetAssetTags(grouper);
|
|
||||||
var collectAssetInfo = new CollectAssetInfo(bundleName, assetPath, assetTags, isRawAsset, NotWriteToAssetList);
|
|
||||||
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
|
|
||||||
result.Add(assetPath, collectAssetInfo);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception($"The collecting asset file is existed : {assetPath} in collector : {CollectPath}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string assetPath = CollectPath;
|
|
||||||
if (result.ContainsKey(assetPath) == false)
|
|
||||||
{
|
|
||||||
if (isRawAsset && NotWriteToAssetList)
|
|
||||||
UnityEngine.Debug.LogWarning($"Are you sure raw file are not write to asset list : {assetPath}");
|
|
||||||
|
|
||||||
string bundleName = GetBundleName(grouper, assetPath, isRawAsset);
|
|
||||||
List<string> assetTags = GetAssetTags(grouper);
|
|
||||||
var collectAssetInfo = new CollectAssetInfo(bundleName, assetPath, assetTags, isRawAsset, NotWriteToAssetList);
|
|
||||||
result.Add(assetPath, collectAssetInfo);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception($"The collecting asset file is existed : {assetPath} in collector : {CollectPath}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 返回列表
|
|
||||||
return result.Values.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsValidateAsset(string assetPath)
|
|
||||||
{
|
|
||||||
if (assetPath.StartsWith("Assets/") == false && assetPath.StartsWith("Packages/") == false)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (AssetDatabase.IsValidFolder(assetPath))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// 注意:忽略编辑器下的类型资源
|
|
||||||
Type type = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
|
||||||
if (type == typeof(LightingDataAsset))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
string ext = System.IO.Path.GetExtension(assetPath);
|
|
||||||
if (ext == "" || ext == ".dll" || ext == ".cs" || ext == ".js" || ext == ".boo" || ext == ".meta")
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
private bool IsCollectAsset(string assetPath)
|
|
||||||
{
|
|
||||||
// 如果收集全路径着色器
|
|
||||||
if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders)
|
|
||||||
{
|
|
||||||
Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
|
||||||
if (assetType == typeof(UnityEngine.Shader))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据规则设置过滤资源文件
|
|
||||||
IFilterRule filterRuleInstance = AssetBundleGrouperSettingData.GetFilterRuleInstance(FilterRuleName);
|
|
||||||
return filterRuleInstance.IsCollectAsset(new FilterRuleData(assetPath));
|
|
||||||
}
|
|
||||||
private string GetBundleName(AssetBundleGrouper grouper, string assetPath, bool isRawAsset)
|
|
||||||
{
|
|
||||||
// 如果收集全路径着色器
|
|
||||||
if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders)
|
|
||||||
{
|
|
||||||
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
|
||||||
if (assetType == typeof(UnityEngine.Shader))
|
|
||||||
{
|
|
||||||
string bundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName;
|
|
||||||
return RevisedBundleName(bundleName, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据规则设置获取资源包名称
|
|
||||||
{
|
|
||||||
IPackRule packRuleInstance = AssetBundleGrouperSettingData.GetPackRuleInstance(PackRuleName);
|
|
||||||
string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, grouper.GrouperName));
|
|
||||||
return RevisedBundleName(bundleName, isRawAsset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private List<string> GetAssetTags(AssetBundleGrouper grouper)
|
|
||||||
{
|
|
||||||
List<string> tags = StringUtility.StringToStringList(grouper.AssetTags, ';');
|
|
||||||
List<string> temper = StringUtility.StringToStringList(AssetTags, ';');
|
|
||||||
tags.AddRange(temper);
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
private List<string> GetAllDependencies(string mainAssetPath)
|
|
||||||
{
|
|
||||||
List<string> result = new List<string>();
|
|
||||||
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
|
||||||
foreach (string assetPath in depends)
|
|
||||||
{
|
|
||||||
if (IsValidateAsset(assetPath))
|
|
||||||
{
|
|
||||||
// 注意:排除主资源对象
|
|
||||||
if (assetPath != mainAssetPath)
|
|
||||||
result.Add(assetPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 修正资源包名
|
|
||||||
/// </summary>
|
|
||||||
public static string RevisedBundleName(string bundleName, bool isRawBundle)
|
|
||||||
{
|
|
||||||
if (isRawBundle)
|
|
||||||
{
|
|
||||||
string fullName = $"{bundleName}.{YooAssetSettingsData.Setting.RawFileVariant}";
|
|
||||||
return EditorTools.GetRegularPath(fullName).ToLower();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
string fullName = $"{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
|
||||||
return EditorTools.GetRegularPath(fullName).ToLower(); ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,162 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Xml;
|
|
||||||
using System.Text;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEditor;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
|
||||||
{
|
|
||||||
public class AssetBundleGrouperConfig
|
|
||||||
{
|
|
||||||
public const string XmlShader = "Shader";
|
|
||||||
public const string XmlAutoCollectShader = "AutoCollectShader";
|
|
||||||
public const string XmlShaderBundleName = "ShaderBundleName";
|
|
||||||
public const string XmlGrouper = "Grouper";
|
|
||||||
public const string XmlGrouperName = "GrouperName";
|
|
||||||
public const string XmlGrouperDesc = "GrouperDesc";
|
|
||||||
public const string XmlCollector = "Collector";
|
|
||||||
public const string XmlDirectory = "CollectPath";
|
|
||||||
public const string XmlPackRule = "PackRule";
|
|
||||||
public const string XmlFilterRule = "FilterRule";
|
|
||||||
public const string XmlNotWriteToAssetList = "NotWriteToAssetList";
|
|
||||||
public const string XmlAssetTags = "AssetTags";
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 导入XML配置表
|
|
||||||
/// </summary>
|
|
||||||
public static void ImportXmlConfig(string filePath)
|
|
||||||
{
|
|
||||||
if (File.Exists(filePath) == false)
|
|
||||||
throw new FileNotFoundException(filePath);
|
|
||||||
|
|
||||||
if (Path.GetExtension(filePath) != ".xml")
|
|
||||||
throw new Exception($"Only support xml : {filePath}");
|
|
||||||
|
|
||||||
// 加载配置文件
|
|
||||||
XmlDocument xml = new XmlDocument();
|
|
||||||
xml.Load(filePath);
|
|
||||||
XmlElement root = xml.DocumentElement;
|
|
||||||
|
|
||||||
// 读取着色器配置
|
|
||||||
bool autoCollectShaders = false;
|
|
||||||
string shaderBundleName = string.Empty;
|
|
||||||
var shaderNodeList = root.GetElementsByTagName(XmlShader);
|
|
||||||
if (shaderNodeList.Count > 0)
|
|
||||||
{
|
|
||||||
XmlElement shaderElement = shaderNodeList[0] as XmlElement;
|
|
||||||
if (shaderElement.HasAttribute(XmlAutoCollectShader) == false)
|
|
||||||
throw new Exception($"Not found attribute {XmlAutoCollectShader} in {XmlShader}");
|
|
||||||
if (shaderElement.HasAttribute(XmlShaderBundleName) == false)
|
|
||||||
throw new Exception($"Not found attribute {XmlShaderBundleName} in {XmlShader}");
|
|
||||||
|
|
||||||
autoCollectShaders = shaderElement.GetAttribute(XmlAutoCollectShader) == "True" ? true : false;
|
|
||||||
shaderBundleName = shaderElement.GetAttribute(XmlShaderBundleName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 读取分组配置
|
|
||||||
List<AssetBundleGrouper> grouperTemper = new List<AssetBundleGrouper>();
|
|
||||||
var grouperNodeList = root.GetElementsByTagName(XmlGrouper);
|
|
||||||
foreach (var grouperNode in grouperNodeList)
|
|
||||||
{
|
|
||||||
XmlElement grouperElement = grouperNode as XmlElement;
|
|
||||||
if (grouperElement.HasAttribute(XmlGrouperName) == false)
|
|
||||||
throw new Exception($"Not found attribute {XmlGrouperName} in {XmlGrouper}");
|
|
||||||
if (grouperElement.HasAttribute(XmlGrouperDesc) == false)
|
|
||||||
throw new Exception($"Not found attribute {XmlGrouperDesc} in {XmlGrouper}");
|
|
||||||
if (grouperElement.HasAttribute(XmlAssetTags) == false)
|
|
||||||
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlGrouper}");
|
|
||||||
|
|
||||||
AssetBundleGrouper grouper = new AssetBundleGrouper();
|
|
||||||
grouper.GrouperName = grouperElement.GetAttribute(XmlGrouperName);
|
|
||||||
grouper.GrouperDesc = grouperElement.GetAttribute(XmlGrouperDesc);
|
|
||||||
grouper.AssetTags = grouperElement.GetAttribute(XmlAssetTags);
|
|
||||||
grouperTemper.Add(grouper);
|
|
||||||
|
|
||||||
// 读取收集器配置
|
|
||||||
var collectorNodeList = grouperElement.GetElementsByTagName(XmlCollector);
|
|
||||||
foreach (var collectorNode in collectorNodeList)
|
|
||||||
{
|
|
||||||
XmlElement collectorElement = collectorNode as XmlElement;
|
|
||||||
if (collectorElement.HasAttribute(XmlDirectory) == false)
|
|
||||||
throw new Exception($"Not found attribute {XmlDirectory} in {XmlCollector}");
|
|
||||||
if (collectorElement.HasAttribute(XmlPackRule) == false)
|
|
||||||
throw new Exception($"Not found attribute {XmlPackRule} in {XmlCollector}");
|
|
||||||
if (collectorElement.HasAttribute(XmlFilterRule) == false)
|
|
||||||
throw new Exception($"Not found attribute {XmlFilterRule} in {XmlCollector}");
|
|
||||||
if (collectorElement.HasAttribute(XmlNotWriteToAssetList) == false)
|
|
||||||
throw new Exception($"Not found attribute {XmlNotWriteToAssetList} in {XmlCollector}");
|
|
||||||
if (collectorElement.HasAttribute(XmlAssetTags) == false)
|
|
||||||
throw new Exception($"Not found attribute {XmlAssetTags} in {XmlCollector}");
|
|
||||||
|
|
||||||
AssetBundleCollector collector = new AssetBundleCollector();
|
|
||||||
collector.CollectPath = collectorElement.GetAttribute(XmlDirectory);
|
|
||||||
collector.PackRuleName = collectorElement.GetAttribute(XmlPackRule);
|
|
||||||
collector.FilterRuleName = collectorElement.GetAttribute(XmlFilterRule);
|
|
||||||
collector.NotWriteToAssetList = collectorElement.GetAttribute(XmlNotWriteToAssetList) == "True" ? true : false;
|
|
||||||
collector.AssetTags = collectorElement.GetAttribute(XmlAssetTags); ;
|
|
||||||
grouper.Collectors.Add(collector);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存配置数据
|
|
||||||
AssetBundleGrouperSettingData.ClearAll();
|
|
||||||
AssetBundleGrouperSettingData.Setting.AutoCollectShaders = autoCollectShaders;
|
|
||||||
AssetBundleGrouperSettingData.Setting.ShadersBundleName = shaderBundleName;
|
|
||||||
AssetBundleGrouperSettingData.Setting.Groupers.AddRange(grouperTemper);
|
|
||||||
AssetBundleGrouperSettingData.SaveFile();
|
|
||||||
Debug.Log($"导入配置完毕!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 导出XML配置表
|
|
||||||
/// </summary>
|
|
||||||
public static void ExportXmlConfig(string savePath)
|
|
||||||
{
|
|
||||||
if (File.Exists(savePath))
|
|
||||||
File.Delete(savePath);
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
||||||
sb.AppendLine("<root>");
|
|
||||||
sb.AppendLine("</root>");
|
|
||||||
|
|
||||||
XmlDocument xmlDoc = new XmlDocument();
|
|
||||||
xmlDoc.LoadXml(sb.ToString());
|
|
||||||
XmlElement root = xmlDoc.DocumentElement;
|
|
||||||
|
|
||||||
// 设置着色器配置
|
|
||||||
var shaderElement = xmlDoc.CreateElement(XmlShader);
|
|
||||||
shaderElement.SetAttribute(XmlAutoCollectShader, AssetBundleGrouperSettingData.Setting.AutoCollectShaders.ToString());
|
|
||||||
shaderElement.SetAttribute(XmlShaderBundleName, AssetBundleGrouperSettingData.Setting.ShadersBundleName);
|
|
||||||
|
|
||||||
// 设置分组配置
|
|
||||||
foreach (var grouper in AssetBundleGrouperSettingData.Setting.Groupers)
|
|
||||||
{
|
|
||||||
var grouperElement = xmlDoc.CreateElement(XmlGrouper);
|
|
||||||
grouperElement.SetAttribute(XmlGrouperName, grouper.GrouperName);
|
|
||||||
grouperElement.SetAttribute(XmlGrouperDesc, grouper.GrouperDesc);
|
|
||||||
grouperElement.SetAttribute(XmlAssetTags, grouper.AssetTags);
|
|
||||||
root.AppendChild(grouperElement);
|
|
||||||
|
|
||||||
// 设置收集器配置
|
|
||||||
foreach (var collector in grouper.Collectors)
|
|
||||||
{
|
|
||||||
var collectorElement = xmlDoc.CreateElement(XmlCollector);
|
|
||||||
collectorElement.SetAttribute(XmlDirectory, collector.CollectPath);
|
|
||||||
collectorElement.SetAttribute(XmlPackRule, collector.PackRuleName);
|
|
||||||
collectorElement.SetAttribute(XmlFilterRule, collector.FilterRuleName);
|
|
||||||
collectorElement.SetAttribute(XmlNotWriteToAssetList, collector.NotWriteToAssetList.ToString());
|
|
||||||
collectorElement.SetAttribute(XmlAssetTags, collector.AssetTags);
|
|
||||||
grouperElement.AppendChild(collectorElement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 生成配置文件
|
|
||||||
xmlDoc.Save(savePath);
|
|
||||||
Debug.Log($"导出配置完毕!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
|
||||||
{
|
|
||||||
public class AssetBundleGrouperSetting : ScriptableObject
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 自动收集着色器
|
|
||||||
/// </summary>
|
|
||||||
public bool AutoCollectShaders = true;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 自动收集的着色器资源包名称
|
|
||||||
/// </summary>
|
|
||||||
public string ShadersBundleName = "myshaders";
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 分组列表
|
|
||||||
/// </summary>
|
|
||||||
public List<AssetBundleGrouper> Groupers = new List<AssetBundleGrouper>();
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检测配置错误
|
|
||||||
/// </summary>
|
|
||||||
public void CheckConfigError()
|
|
||||||
{
|
|
||||||
foreach (var grouper in Groupers)
|
|
||||||
{
|
|
||||||
grouper.CheckConfigError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取打包收集的资源文件
|
|
||||||
/// </summary>
|
|
||||||
public List<CollectAssetInfo> GetAllCollectAssets()
|
|
||||||
{
|
|
||||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
|
||||||
foreach (var grouper in Groupers)
|
|
||||||
{
|
|
||||||
var temper = grouper.GetAllCollectAssets();
|
|
||||||
foreach (var assetInfo in temper)
|
|
||||||
{
|
|
||||||
if (result.ContainsKey(assetInfo.AssetPath) == false)
|
|
||||||
{
|
|
||||||
result.Add(assetInfo.AssetPath, assetInfo);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result.Values.ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,430 +0,0 @@
|
|||||||
#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 AssetBundleGrouperWindow : EditorWindow
|
|
||||||
{
|
|
||||||
[MenuItem("YooAsset/AssetBundle Grouper", false, 101)]
|
|
||||||
public static void ShowExample()
|
|
||||||
{
|
|
||||||
AssetBundleGrouperWindow window = GetWindow<AssetBundleGrouperWindow>();
|
|
||||||
window.titleContent = new GUIContent("资源包分组工具");
|
|
||||||
window.minSize = new Vector2(800, 600);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<string> _packRuleList;
|
|
||||||
private List<string> _filterRuleList;
|
|
||||||
private ListView _grouperListView;
|
|
||||||
private ListView _collectorListView;
|
|
||||||
private Toggle _autoCollectShaderToogle;
|
|
||||||
private TextField _shaderBundleNameTxt;
|
|
||||||
private TextField _grouperNameTxt;
|
|
||||||
private TextField _grouperDescTxt;
|
|
||||||
private TextField _grouperAssetTagsTxt;
|
|
||||||
private VisualElement _grouperContainer;
|
|
||||||
|
|
||||||
public void CreateGUI()
|
|
||||||
{
|
|
||||||
VisualElement root = this.rootVisualElement;
|
|
||||||
|
|
||||||
_packRuleList = AssetBundleGrouperSettingData.GetPackRuleNames();
|
|
||||||
_filterRuleList = AssetBundleGrouperSettingData.GetFilterRuleNames();
|
|
||||||
|
|
||||||
// 加载布局文件
|
|
||||||
string rootPath = EditorTools.GetYooAssetPath();
|
|
||||||
string uxml = $"{rootPath}/Editor/AssetBundleGrouper/{nameof(AssetBundleGrouperWindow)}.uxml";
|
|
||||||
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
|
||||||
if (visualAsset == null)
|
|
||||||
{
|
|
||||||
Debug.LogError($"Not found {nameof(AssetBundleGrouperWindow)}.uxml : {uxml}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
visualAsset.CloneTree(root);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// 导入导出按钮
|
|
||||||
var exportBtn = root.Q<Button>("ExportButton");
|
|
||||||
exportBtn.clicked += ExportBtn_clicked;
|
|
||||||
var importBtn = root.Q<Button>("ImportButton");
|
|
||||||
importBtn.clicked += ImportBtn_clicked;
|
|
||||||
|
|
||||||
// 着色器相关
|
|
||||||
_autoCollectShaderToogle = root.Q<Toggle>("AutoCollectShader");
|
|
||||||
_autoCollectShaderToogle.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
AssetBundleGrouperSettingData.ModifyShader(evt.newValue, _shaderBundleNameTxt.value);
|
|
||||||
_shaderBundleNameTxt.SetEnabled(evt.newValue);
|
|
||||||
});
|
|
||||||
_shaderBundleNameTxt = root.Q<TextField>("ShaderBundleName");
|
|
||||||
_shaderBundleNameTxt.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
AssetBundleGrouperSettingData.ModifyShader(_autoCollectShaderToogle.value, evt.newValue);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 分组列表相关
|
|
||||||
_grouperListView = root.Q<ListView>("GrouperListView");
|
|
||||||
_grouperListView.makeItem = MakeGrouperListViewItem;
|
|
||||||
_grouperListView.bindItem = BindGrouperListViewItem;
|
|
||||||
#if UNITY_2020_1_OR_NEWER
|
|
||||||
_grouperListView.onSelectionChange += GrouperListView_onSelectionChange;
|
|
||||||
#else
|
|
||||||
_grouperListView.onSelectionChanged += GrouperListView_onSelectionChange;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 分组添加删除按钮
|
|
||||||
var grouperAddContainer = root.Q("GrouperAddContainer");
|
|
||||||
{
|
|
||||||
var addBtn = grouperAddContainer.Q<Button>("AddBtn");
|
|
||||||
addBtn.clicked += AddGrouperBtn_clicked;
|
|
||||||
var removeBtn = grouperAddContainer.Q<Button>("RemoveBtn");
|
|
||||||
removeBtn.clicked += RemoveGrouperBtn_clicked;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分组容器
|
|
||||||
_grouperContainer = root.Q("GrouperContainer");
|
|
||||||
|
|
||||||
// 分组信息相关
|
|
||||||
_grouperNameTxt = root.Q<TextField>("GrouperName");
|
|
||||||
_grouperNameTxt.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
|
||||||
if (selectGrouper != null)
|
|
||||||
{
|
|
||||||
selectGrouper.GrouperName = evt.newValue;
|
|
||||||
AssetBundleGrouperSettingData.ModifyGrouper(selectGrouper);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
_grouperDescTxt = root.Q<TextField>("GrouperDesc");
|
|
||||||
_grouperDescTxt.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
|
||||||
if (selectGrouper != null)
|
|
||||||
{
|
|
||||||
selectGrouper.GrouperDesc = evt.newValue;
|
|
||||||
AssetBundleGrouperSettingData.ModifyGrouper(selectGrouper);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
_grouperAssetTagsTxt = root.Q<TextField>("GrouperAssetTags");
|
|
||||||
_grouperAssetTagsTxt.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
|
||||||
if (selectGrouper != null)
|
|
||||||
{
|
|
||||||
selectGrouper.AssetTags = evt.newValue;
|
|
||||||
AssetBundleGrouperSettingData.ModifyGrouper(selectGrouper);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 收集列表相关
|
|
||||||
_collectorListView = root.Q<ListView>("CollectorListView");
|
|
||||||
_collectorListView.makeItem = MakeCollectorListViewItem;
|
|
||||||
_collectorListView.bindItem = BindCollectorListViewItem;
|
|
||||||
#if UNITY_2020_1_OR_NEWER
|
|
||||||
_collectorListView.onSelectionChange += CollectorListView_onSelectionChange;
|
|
||||||
#else
|
|
||||||
_collectorListView.onSelectionChanged += CollectorListView_onSelectionChange;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 收集添加删除按钮
|
|
||||||
var collectorAddContainer = root.Q("CollectorAddContainer");
|
|
||||||
{
|
|
||||||
var addBtn = collectorAddContainer.Q<Button>("AddBtn");
|
|
||||||
addBtn.clicked += AddCollectorBtn_clicked;
|
|
||||||
var removeBtn = collectorAddContainer.Q<Button>("RemoveBtn");
|
|
||||||
removeBtn.clicked += RemoveCollectorBtn_clicked;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 刷新窗体
|
|
||||||
RefreshWindow();
|
|
||||||
}
|
|
||||||
catch (System.Exception e)
|
|
||||||
{
|
|
||||||
Debug.LogError(e.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 刷新窗体
|
|
||||||
private void RefreshWindow()
|
|
||||||
{
|
|
||||||
_autoCollectShaderToogle.SetValueWithoutNotify(AssetBundleGrouperSettingData.Setting.AutoCollectShaders);
|
|
||||||
_shaderBundleNameTxt.SetEnabled(AssetBundleGrouperSettingData.Setting.AutoCollectShaders);
|
|
||||||
_shaderBundleNameTxt.SetValueWithoutNotify(AssetBundleGrouperSettingData.Setting.ShadersBundleName);
|
|
||||||
_grouperContainer.visible = false;
|
|
||||||
|
|
||||||
FillGrouperViewData();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 导入导出按钮
|
|
||||||
private void ExportBtn_clicked()
|
|
||||||
{
|
|
||||||
string resultPath = EditorTools.OpenFolderPanel("Export XML", "Assets/");
|
|
||||||
if (resultPath != null)
|
|
||||||
{
|
|
||||||
AssetBundleGrouperConfig.ExportXmlConfig($"{resultPath}/{nameof(AssetBundleGrouperConfig)}.xml");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ImportBtn_clicked()
|
|
||||||
{
|
|
||||||
string resultPath = EditorTools.OpenFilePath("Import XML", "Assets/", "xml");
|
|
||||||
if (resultPath != null)
|
|
||||||
{
|
|
||||||
AssetBundleGrouperConfig.ImportXmlConfig(resultPath);
|
|
||||||
RefreshWindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分组列表相关
|
|
||||||
private void FillGrouperViewData()
|
|
||||||
{
|
|
||||||
_grouperListView.Clear();
|
|
||||||
_grouperListView.ClearSelection();
|
|
||||||
_grouperListView.itemsSource = AssetBundleGrouperSettingData.Setting.Groupers;
|
|
||||||
}
|
|
||||||
private VisualElement MakeGrouperListViewItem()
|
|
||||||
{
|
|
||||||
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 BindGrouperListViewItem(VisualElement element, int index)
|
|
||||||
{
|
|
||||||
var grouper = AssetBundleGrouperSettingData.Setting.Groupers[index];
|
|
||||||
|
|
||||||
// Grouper Name
|
|
||||||
var textField1 = element.Q<Label>("Label1");
|
|
||||||
if (string.IsNullOrEmpty(grouper.GrouperDesc))
|
|
||||||
textField1.text = grouper.GrouperName;
|
|
||||||
else
|
|
||||||
textField1.text = $"{grouper.GrouperName} ({grouper.GrouperDesc})";
|
|
||||||
}
|
|
||||||
private void GrouperListView_onSelectionChange(IEnumerable<object> objs)
|
|
||||||
{
|
|
||||||
FillCollectorViewData();
|
|
||||||
}
|
|
||||||
private void AddGrouperBtn_clicked()
|
|
||||||
{
|
|
||||||
AssetBundleGrouperSettingData.CreateGrouper("Default Grouper", string.Empty, string.Empty, true);
|
|
||||||
FillGrouperViewData();
|
|
||||||
}
|
|
||||||
private void RemoveGrouperBtn_clicked()
|
|
||||||
{
|
|
||||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
|
||||||
if (selectGrouper == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AssetBundleGrouperSettingData.RemoveGrouper(selectGrouper);
|
|
||||||
FillGrouperViewData();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 收集列表相关
|
|
||||||
private void FillCollectorViewData()
|
|
||||||
{
|
|
||||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
|
||||||
if (selectGrouper == null)
|
|
||||||
{
|
|
||||||
_grouperContainer.visible = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_grouperContainer.visible = true;
|
|
||||||
_collectorListView.Clear();
|
|
||||||
_collectorListView.ClearSelection();
|
|
||||||
_collectorListView.itemsSource = selectGrouper.Collectors;
|
|
||||||
|
|
||||||
_grouperNameTxt.SetValueWithoutNotify(selectGrouper.GrouperName);
|
|
||||||
_grouperDescTxt.SetValueWithoutNotify(selectGrouper.GrouperDesc);
|
|
||||||
_grouperAssetTagsTxt.SetValueWithoutNotify(selectGrouper.AssetTags);
|
|
||||||
}
|
|
||||||
private VisualElement MakeCollectorListViewItem()
|
|
||||||
{
|
|
||||||
VisualElement element = new VisualElement();
|
|
||||||
|
|
||||||
VisualElement elementTop = new VisualElement();
|
|
||||||
elementTop.style.flexDirection = FlexDirection.Row;
|
|
||||||
element.Add(elementTop);
|
|
||||||
|
|
||||||
VisualElement elementBottom = new VisualElement();
|
|
||||||
elementBottom.style.flexDirection = FlexDirection.Row;
|
|
||||||
element.Add(elementBottom);
|
|
||||||
|
|
||||||
// Top VisualElement
|
|
||||||
{
|
|
||||||
var objectField = new ObjectField();
|
|
||||||
objectField.name = "ObjectField1";
|
|
||||||
objectField.label = "Collect Path";
|
|
||||||
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 = 80;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bottom VisualElement
|
|
||||||
{
|
|
||||||
var label = new Label();
|
|
||||||
label.style.width = 80;
|
|
||||||
elementBottom.Add(label);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var popupField = new PopupField<string>(_packRuleList, 0);
|
|
||||||
popupField.name = "PopupField1";
|
|
||||||
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
|
||||||
popupField.style.width = 150;
|
|
||||||
elementBottom.Add(popupField);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var popupField = new PopupField<string>(_filterRuleList, 0);
|
|
||||||
popupField.name = "PopupField2";
|
|
||||||
popupField.style.unityTextAlign = TextAnchor.MiddleLeft;
|
|
||||||
popupField.style.width = 150;
|
|
||||||
elementBottom.Add(popupField);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var toggle = new Toggle();
|
|
||||||
toggle.name = "Toggle1";
|
|
||||||
toggle.label = "NotWriteToAssetList";
|
|
||||||
toggle.style.unityTextAlign = TextAnchor.MiddleLeft;
|
|
||||||
toggle.style.width = 150;
|
|
||||||
toggle.style.marginLeft = 20;
|
|
||||||
elementBottom.Add(toggle);
|
|
||||||
var label = toggle.Q<Label>();
|
|
||||||
label.style.minWidth = 130;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
var textField = new TextField();
|
|
||||||
textField.name = "TextField1";
|
|
||||||
textField.label = "Tags";
|
|
||||||
textField.style.width = 100;
|
|
||||||
textField.style.marginLeft = 20;
|
|
||||||
textField.style.flexGrow = 1;
|
|
||||||
elementBottom.Add(textField);
|
|
||||||
var label = textField.Q<Label>();
|
|
||||||
label.style.minWidth = 40;
|
|
||||||
}
|
|
||||||
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
private void BindCollectorListViewItem(VisualElement element, int index)
|
|
||||||
{
|
|
||||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
|
||||||
if (selectGrouper == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var collector = selectGrouper.Collectors[index];
|
|
||||||
var collectObject = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(collector.CollectPath);
|
|
||||||
if (collectObject != null)
|
|
||||||
collectObject.name = collector.CollectPath;
|
|
||||||
|
|
||||||
// Collect Path
|
|
||||||
var objectField1 = element.Q<ObjectField>("ObjectField1");
|
|
||||||
objectField1.SetValueWithoutNotify(collectObject);
|
|
||||||
objectField1.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
collector.CollectPath = AssetDatabase.GetAssetPath(evt.newValue);
|
|
||||||
objectField1.value.name = collector.CollectPath;
|
|
||||||
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Pack Rule
|
|
||||||
var popupField1 = element.Q<PopupField<string>>("PopupField1");
|
|
||||||
popupField1.index = GetPackRuleIndex(collector.PackRuleName);
|
|
||||||
popupField1.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
collector.PackRuleName = evt.newValue;
|
|
||||||
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Filter Rule
|
|
||||||
var popupField2 = element.Q<PopupField<string>>("PopupField2");
|
|
||||||
popupField2.index = GetFilterRuleIndex(collector.FilterRuleName);
|
|
||||||
popupField2.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
collector.FilterRuleName = evt.newValue;
|
|
||||||
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector);
|
|
||||||
});
|
|
||||||
|
|
||||||
// NotWriteToAssetList
|
|
||||||
var toggle1 = element.Q<Toggle>("Toggle1");
|
|
||||||
toggle1.SetValueWithoutNotify(collector.NotWriteToAssetList);
|
|
||||||
toggle1.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
collector.NotWriteToAssetList = evt.newValue;
|
|
||||||
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Tags
|
|
||||||
var textFiled1 = element.Q<TextField>("TextField1");
|
|
||||||
textFiled1.SetValueWithoutNotify(collector.AssetTags);
|
|
||||||
textFiled1.RegisterValueChangedCallback(evt =>
|
|
||||||
{
|
|
||||||
collector.AssetTags = evt.newValue;
|
|
||||||
AssetBundleGrouperSettingData.ModifyCollector(selectGrouper, collector);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
private void CollectorListView_onSelectionChange(IEnumerable<object> objs)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
private void AddCollectorBtn_clicked()
|
|
||||||
{
|
|
||||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
|
||||||
if (selectGrouper == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AssetBundleGrouperSettingData.CreateCollector(selectGrouper, string.Empty, nameof(PackDirectory), nameof(CollectAll), false);
|
|
||||||
FillCollectorViewData();
|
|
||||||
}
|
|
||||||
private void RemoveCollectorBtn_clicked()
|
|
||||||
{
|
|
||||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
|
||||||
if (selectGrouper == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var selectCollector = _collectorListView.selectedItem as AssetBundleCollector;
|
|
||||||
if (selectCollector == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AssetBundleGrouperSettingData.RemoveCollector(selectGrouper, selectCollector);
|
|
||||||
FillCollectorViewData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GetPackRuleIndex(string packRuleName)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _packRuleList.Count; i++)
|
|
||||||
{
|
|
||||||
if (_packRuleList[i] == packRuleName)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
private int GetFilterRuleIndex(string filterRuleName)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < _filterRuleList.Count; i++)
|
|
||||||
{
|
|
||||||
if (_filterRuleList[i] == filterRuleName)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using System.IO;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public class AssetBundleInspector
|
||||||
|
{
|
||||||
|
[CustomEditor(typeof(AssetBundle))]
|
||||||
|
internal class AssetBundleEditor : UnityEditor.Editor
|
||||||
|
{
|
||||||
|
internal bool pathFoldout = false;
|
||||||
|
internal bool advancedFoldout = false;
|
||||||
|
public override void OnInspectorGUI()
|
||||||
|
{
|
||||||
|
AssetBundle bundle = target as AssetBundle;
|
||||||
|
|
||||||
|
using (new EditorGUI.DisabledScope(true))
|
||||||
|
{
|
||||||
|
var leftStyle = new GUIStyle(GUI.skin.GetStyle("Label"));
|
||||||
|
leftStyle.alignment = TextAnchor.UpperLeft;
|
||||||
|
GUILayout.Label(new GUIContent("Name: " + bundle.name), leftStyle);
|
||||||
|
|
||||||
|
var assetNames = bundle.GetAllAssetNames();
|
||||||
|
pathFoldout = EditorGUILayout.Foldout(pathFoldout, "Source Asset Paths");
|
||||||
|
if (pathFoldout)
|
||||||
|
{
|
||||||
|
EditorGUI.indentLevel++;
|
||||||
|
foreach (var asset in assetNames)
|
||||||
|
EditorGUILayout.LabelField(asset);
|
||||||
|
EditorGUI.indentLevel--;
|
||||||
|
}
|
||||||
|
|
||||||
|
advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced Data");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (advancedFoldout)
|
||||||
|
{
|
||||||
|
EditorGUI.indentLevel++;
|
||||||
|
base.OnInspectorGUI();
|
||||||
|
EditorGUI.indentLevel--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b8016a4c13444bf45830d714ab2aa430
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public static class AssetBundleRecorder
|
||||||
|
{
|
||||||
|
private static readonly Dictionary<string, AssetBundle> _loadedAssetBundles = new Dictionary<string, AssetBundle>(1000);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取AssetBundle对象,如果没有被缓存就重新加载。
|
||||||
|
/// </summary>
|
||||||
|
public static AssetBundle GetAssetBundle(string filePath)
|
||||||
|
{
|
||||||
|
// 如果文件不存在
|
||||||
|
if (File.Exists(filePath) == false)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Not found asset bundle file : {filePath}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证文件有效性(可能文件被加密)
|
||||||
|
byte[] fileData = File.ReadAllBytes(filePath);
|
||||||
|
if (EditorTools.CheckBundleFileValid(fileData) == false)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"The asset bundle file is invalid and may be encrypted : {filePath}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_loadedAssetBundles.TryGetValue(filePath, out AssetBundle bundle))
|
||||||
|
{
|
||||||
|
return bundle;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AssetBundle newBundle = AssetBundle.LoadFromFile(filePath);
|
||||||
|
if(newBundle != null)
|
||||||
|
{
|
||||||
|
string[] assetNames = newBundle.GetAllAssetNames();
|
||||||
|
foreach (string name in assetNames)
|
||||||
|
{
|
||||||
|
newBundle.LoadAsset(name);
|
||||||
|
}
|
||||||
|
_loadedAssetBundles.Add(filePath, newBundle);
|
||||||
|
}
|
||||||
|
return newBundle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 卸载所有已经加载的AssetBundle文件
|
||||||
|
/// </summary>
|
||||||
|
public static void UnloadAll()
|
||||||
|
{
|
||||||
|
foreach(var valuePair in _loadedAssetBundles)
|
||||||
|
{
|
||||||
|
if (valuePair.Value != null)
|
||||||
|
valuePair.Value.Unload(true);
|
||||||
|
}
|
||||||
|
_loadedAssetBundles.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9b2b5e436ee882d41bf53082bf7b23a0
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#if UNITY_2019_4_OR_NEWER
|
#if UNITY_2019_4_OR_NEWER
|
||||||
|
using System;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor.UIElements;
|
using UnityEditor.UIElements;
|
||||||
@@ -11,8 +12,7 @@ namespace YooAsset.Editor
|
|||||||
[MenuItem("YooAsset/AssetBundle Reporter", false, 103)]
|
[MenuItem("YooAsset/AssetBundle Reporter", false, 103)]
|
||||||
public static void ShowExample()
|
public static void ShowExample()
|
||||||
{
|
{
|
||||||
AssetBundleReporterWindow window = GetWindow<AssetBundleReporterWindow>();
|
AssetBundleReporterWindow window = GetWindow<AssetBundleReporterWindow>("资源包报告工具", true, EditorDefine.DockedWindowTypes);
|
||||||
window.titleContent = new GUIContent("资源包报告工具");
|
|
||||||
window.minSize = new Vector2(800, 600);
|
window.minSize = new Vector2(800, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,60 +38,70 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ToolbarMenu _viewModeMenu;
|
private ToolbarMenu _viewModeMenu;
|
||||||
private SummaryReporterViewer _summaryViewer;
|
private ReporterSummaryViewer _summaryViewer;
|
||||||
private AssetListReporterViewer _assetListViewer;
|
private ReporterAssetListViewer _assetListViewer;
|
||||||
private BundleListReporterViewer _bundleListViewer;
|
private ReporterBundleListViewer _bundleListViewer;
|
||||||
|
|
||||||
private EViewMode _viewMode;
|
private EViewMode _viewMode;
|
||||||
private string _searchKeyWord;
|
|
||||||
private BuildReport _buildReport;
|
private BuildReport _buildReport;
|
||||||
|
private string _reportFilePath;
|
||||||
|
private string _searchKeyWord;
|
||||||
|
|
||||||
|
|
||||||
public void CreateGUI()
|
public void CreateGUI()
|
||||||
{
|
{
|
||||||
VisualElement root = this.rootVisualElement;
|
try
|
||||||
|
|
||||||
// 加载布局文件
|
|
||||||
string rootPath = EditorTools.GetYooAssetPath();
|
|
||||||
string uxml = $"{rootPath}/Editor/AssetBundleReporter/{nameof(AssetBundleReporterWindow)}.uxml";
|
|
||||||
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
|
||||||
if (visualAsset == null)
|
|
||||||
{
|
{
|
||||||
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml : {uxml}");
|
VisualElement root = this.rootVisualElement;
|
||||||
return;
|
|
||||||
|
// 加载布局文件
|
||||||
|
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleReporterUXML;
|
||||||
|
if (visualAsset == null)
|
||||||
|
{
|
||||||
|
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml in settings.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
visualAsset.CloneTree(root);
|
||||||
|
|
||||||
|
// 导入按钮
|
||||||
|
var importBtn = root.Q<Button>("ImportButton");
|
||||||
|
importBtn.clicked += ImportBtn_onClick;
|
||||||
|
|
||||||
|
// 视图模式菜单
|
||||||
|
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
||||||
|
_viewModeMenu.menu.AppendAction(EViewMode.Summary.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
|
||||||
|
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
|
||||||
|
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
|
||||||
|
|
||||||
|
// 搜索栏
|
||||||
|
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||||
|
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
||||||
|
|
||||||
|
// 加载视图
|
||||||
|
_summaryViewer = new ReporterSummaryViewer();
|
||||||
|
_summaryViewer.InitViewer();
|
||||||
|
|
||||||
|
// 加载视图
|
||||||
|
_assetListViewer = new ReporterAssetListViewer();
|
||||||
|
_assetListViewer.InitViewer();
|
||||||
|
|
||||||
|
// 加载视图
|
||||||
|
_bundleListViewer = new ReporterBundleListViewer();
|
||||||
|
_bundleListViewer.InitViewer();
|
||||||
|
|
||||||
|
// 显示视图
|
||||||
|
_viewMode = EViewMode.Summary;
|
||||||
|
_viewModeMenu.text = EViewMode.Summary.ToString();
|
||||||
|
_summaryViewer.AttachParent(root);
|
||||||
}
|
}
|
||||||
visualAsset.CloneTree(root);
|
catch (Exception e)
|
||||||
|
{
|
||||||
// 导入按钮
|
Debug.LogError(e.ToString());
|
||||||
var importBtn = root.Q<Button>("ImportButton");
|
}
|
||||||
importBtn.clicked += ImportBtn_onClick;
|
}
|
||||||
|
public void OnDestroy()
|
||||||
// 视图模式菜单
|
{
|
||||||
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
AssetBundleRecorder.UnloadAll();
|
||||||
_viewModeMenu.menu.AppendAction(EViewMode.Summary.ToString(), ViewModeMenuAction0, ViewModeMenuFun0);
|
|
||||||
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction1, ViewModeMenuFun1);
|
|
||||||
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction2, ViewModeMenuFun2);
|
|
||||||
|
|
||||||
// 搜索栏
|
|
||||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
|
||||||
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
|
||||||
|
|
||||||
// 加载视图
|
|
||||||
_summaryViewer = new SummaryReporterViewer();
|
|
||||||
_summaryViewer.InitViewer();
|
|
||||||
|
|
||||||
// 加载视图
|
|
||||||
_assetListViewer = new AssetListReporterViewer();
|
|
||||||
_assetListViewer.InitViewer();
|
|
||||||
|
|
||||||
// 加载视图
|
|
||||||
_bundleListViewer = new BundleListReporterViewer();
|
|
||||||
_bundleListViewer.InitViewer();
|
|
||||||
|
|
||||||
// 显示视图
|
|
||||||
_viewMode = EViewMode.Summary;
|
|
||||||
_viewModeMenu.text = EViewMode.Summary.ToString();
|
|
||||||
_summaryViewer.AttachParent(root);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ImportBtn_onClick()
|
private void ImportBtn_onClick()
|
||||||
@@ -100,19 +110,20 @@ namespace YooAsset.Editor
|
|||||||
if (string.IsNullOrEmpty(selectFilePath))
|
if (string.IsNullOrEmpty(selectFilePath))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string jsonData = FileUtility.ReadFile(selectFilePath);
|
_reportFilePath = selectFilePath;
|
||||||
|
string jsonData = FileUtility.ReadFile(_reportFilePath);
|
||||||
_buildReport = BuildReport.Deserialize(jsonData);
|
_buildReport = BuildReport.Deserialize(jsonData);
|
||||||
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||||
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord);
|
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
|
||||||
_summaryViewer.FillViewData(_buildReport);
|
_summaryViewer.FillViewData(_buildReport);
|
||||||
}
|
}
|
||||||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||||
{
|
{
|
||||||
_searchKeyWord = e.newValue;
|
_searchKeyWord = e.newValue;
|
||||||
if(_buildReport != null)
|
if (_buildReport != null)
|
||||||
{
|
{
|
||||||
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||||
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord);
|
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ViewModeMenuAction0(DropdownMenuAction action)
|
private void ViewModeMenuAction0(DropdownMenuAction action)
|
||||||
|
|||||||
@@ -1,301 +0,0 @@
|
|||||||
#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 BundleListReporterViewer
|
|
||||||
{
|
|
||||||
private VisualTreeAsset _visualAsset;
|
|
||||||
private TemplateContainer _root;
|
|
||||||
|
|
||||||
private ToolbarButton _topBar1;
|
|
||||||
private ToolbarButton _topBar2;
|
|
||||||
private ToolbarButton _topBar3;
|
|
||||||
private ToolbarButton _topBar4;
|
|
||||||
private ToolbarButton _topBar5;
|
|
||||||
private ToolbarButton _bottomBar1;
|
|
||||||
private ToolbarButton _bottomBar2;
|
|
||||||
private ToolbarButton _bottomBar3;
|
|
||||||
private ListView _bundleListView;
|
|
||||||
private ListView _includeListView;
|
|
||||||
private BuildReport _buildReport;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 初始化页面
|
|
||||||
/// </summary>
|
|
||||||
public void InitViewer()
|
|
||||||
{
|
|
||||||
// 加载布局文件
|
|
||||||
string rootPath = EditorTools.GetYooAssetPath();
|
|
||||||
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(BundleListReporterViewer)}.uxml";
|
|
||||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
|
||||||
if (_visualAsset == null)
|
|
||||||
{
|
|
||||||
Debug.LogError($"Not found {nameof(BundleListReporterViewer)}.uxml : {uxml}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_root = _visualAsset.CloneTree();
|
|
||||||
_root.style.flexGrow = 1f;
|
|
||||||
|
|
||||||
// 顶部按钮栏
|
|
||||||
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
|
|
||||||
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
|
|
||||||
_topBar3 = _root.Q<ToolbarButton>("TopBar3");
|
|
||||||
_topBar4 = _root.Q<ToolbarButton>("TopBar4");
|
|
||||||
_topBar5 = _root.Q<ToolbarButton>("TopBar5");
|
|
||||||
|
|
||||||
// 底部按钮栏
|
|
||||||
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
|
|
||||||
_bottomBar2 = _root.Q<ToolbarButton>("BottomBar2");
|
|
||||||
_bottomBar3 = _root.Q<ToolbarButton>("BottomBar3");
|
|
||||||
|
|
||||||
// 资源包列表
|
|
||||||
_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
|
|
||||||
|
|
||||||
// 包含列表
|
|
||||||
_includeListView = _root.Q<ListView>("BottomListView");
|
|
||||||
_includeListView.makeItem = MakeIncludeListViewItem;
|
|
||||||
_includeListView.bindItem = BindIncludeListViewItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 填充页面数据
|
|
||||||
/// </summary>
|
|
||||||
public void FillViewData(BuildReport buildReport, string searchKeyWord)
|
|
||||||
{
|
|
||||||
_buildReport = buildReport;
|
|
||||||
_bundleListView.Clear();
|
|
||||||
_bundleListView.itemsSource = FilterViewItems(buildReport, searchKeyWord);
|
|
||||||
_topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count})";
|
|
||||||
}
|
|
||||||
private List<ReportBundleInfo> FilterViewItems(BuildReport buildReport, string searchKeyWord)
|
|
||||||
{
|
|
||||||
List<ReportBundleInfo> result = new List<ReportBundleInfo>(buildReport.BundleInfos.Count);
|
|
||||||
foreach (var bundleInfo in buildReport.BundleInfos)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(searchKeyWord) == false)
|
|
||||||
{
|
|
||||||
if (bundleInfo.BundleName.Contains(searchKeyWord) == false)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
result.Add(bundleInfo);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 挂接到父类页面上
|
|
||||||
/// </summary>
|
|
||||||
public void AttachParent(VisualElement parent)
|
|
||||||
{
|
|
||||||
parent.Add(_root);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 从父类页面脱离开
|
|
||||||
/// </summary>
|
|
||||||
public void DetachParent()
|
|
||||||
{
|
|
||||||
_root.RemoveFromHierarchy();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 顶部列表相关
|
|
||||||
private VisualElement MakeBundleListViewItem()
|
|
||||||
{
|
|
||||||
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 = 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 = 250;
|
|
||||||
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 = 60;
|
|
||||||
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 = 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 = (bundleInfo.SizeBytes / 1024f).ToString("f1") + " KB";
|
|
||||||
|
|
||||||
// Hash
|
|
||||||
var label3 = element.Q<Label>("Label3");
|
|
||||||
label3.text = bundleInfo.Hash;
|
|
||||||
|
|
||||||
// Version
|
|
||||||
var label4 = element.Q<Label>("Label4");
|
|
||||||
label4.text = bundleInfo.Version.ToString();
|
|
||||||
|
|
||||||
// Tags
|
|
||||||
var label5 = element.Q<Label>("Label5");
|
|
||||||
label5.text = GetTagsString(bundleInfo.Tags);
|
|
||||||
}
|
|
||||||
private void BundleListView_onSelectionChange(IEnumerable<object> objs)
|
|
||||||
{
|
|
||||||
foreach (var item in objs)
|
|
||||||
{
|
|
||||||
ReportBundleInfo bundleInfo = item as ReportBundleInfo;
|
|
||||||
FillIncludeListView(bundleInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 底部列表相关
|
|
||||||
private void FillIncludeListView(ReportBundleInfo bundleInfo)
|
|
||||||
{
|
|
||||||
List<string> containsList = new List<string>();
|
|
||||||
foreach (var assetInfo in _buildReport.AssetInfos)
|
|
||||||
{
|
|
||||||
if (assetInfo.MainBundle == bundleInfo.BundleName)
|
|
||||||
containsList.Add(assetInfo.AssetPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
_includeListView.Clear();
|
|
||||||
_includeListView.ClearSelection();
|
|
||||||
_includeListView.itemsSource = containsList;
|
|
||||||
_bottomBar1.text = $"Include Assets ({containsList.Count})";
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
//assetSizeLabel.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 = 250;
|
|
||||||
element.Add(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
private void BindIncludeListViewItem(VisualElement element, int index)
|
|
||||||
{
|
|
||||||
List<string> containsList = _includeListView.itemsSource as List<string>;
|
|
||||||
string assetPath = containsList[index];
|
|
||||||
|
|
||||||
// Asset Path
|
|
||||||
var label1 = element.Q<Label>("Label1");
|
|
||||||
label1.text = assetPath;
|
|
||||||
|
|
||||||
// Size
|
|
||||||
var label2 = element.Q<Label>("Label2");
|
|
||||||
label2.text = GetAssetFileSize(assetPath);
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
var label3 = element.Q<Label>("Label3");
|
|
||||||
label3.text = AssetDatabase.AssetPathToGUID(assetPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetAssetFileSize(string assetPath)
|
|
||||||
{
|
|
||||||
string fullPath = EditorTools.GetProjectPath() + "/" + assetPath;
|
|
||||||
if (File.Exists(fullPath) == false)
|
|
||||||
return "unknown";
|
|
||||||
else
|
|
||||||
return (EditorTools.GetFileSize(fullPath) / 1024f).ToString("f1") + " KB";
|
|
||||||
}
|
|
||||||
private string GetTagsString(string[] tags)
|
|
||||||
{
|
|
||||||
string result = string.Empty;
|
|
||||||
if (tags != null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < tags.Length; i++)
|
|
||||||
{
|
|
||||||
result += tags[i];
|
|
||||||
result += ";";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#if UNITY_2019_4_OR_NEWER
|
#if UNITY_2019_4_OR_NEWER
|
||||||
using System.IO;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@@ -9,20 +9,28 @@ using UnityEngine.UIElements;
|
|||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
internal class AssetListReporterViewer
|
internal class ReporterAssetListViewer
|
||||||
{
|
{
|
||||||
|
private enum ESortMode
|
||||||
|
{
|
||||||
|
AssetPath,
|
||||||
|
BundleName
|
||||||
|
}
|
||||||
|
|
||||||
private VisualTreeAsset _visualAsset;
|
private VisualTreeAsset _visualAsset;
|
||||||
private TemplateContainer _root;
|
private TemplateContainer _root;
|
||||||
|
|
||||||
private ToolbarButton _topBar1;
|
private ToolbarButton _topBar1;
|
||||||
private ToolbarButton _topBar2;
|
private ToolbarButton _topBar2;
|
||||||
private ToolbarButton _topBar3;
|
|
||||||
private ToolbarButton _bottomBar1;
|
private ToolbarButton _bottomBar1;
|
||||||
private ToolbarButton _bottomBar2;
|
|
||||||
private ToolbarButton _bottomBar3;
|
|
||||||
private ListView _assetListView;
|
private ListView _assetListView;
|
||||||
private ListView _dependListView;
|
private ListView _dependListView;
|
||||||
|
|
||||||
private BuildReport _buildReport;
|
private BuildReport _buildReport;
|
||||||
|
private string _searchKeyWord;
|
||||||
|
private ESortMode _sortMode = ESortMode.AssetPath;
|
||||||
|
private bool _descendingSort = false;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化页面
|
/// 初始化页面
|
||||||
@@ -30,44 +38,46 @@ namespace YooAsset.Editor
|
|||||||
public void InitViewer()
|
public void InitViewer()
|
||||||
{
|
{
|
||||||
// 加载布局文件
|
// 加载布局文件
|
||||||
string rootPath = EditorTools.GetYooAssetPath();
|
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterAssetListViewerUXML;
|
||||||
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(AssetListReporterViewer)}.uxml";
|
|
||||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
|
||||||
if (_visualAsset == null)
|
if (_visualAsset == null)
|
||||||
{
|
{
|
||||||
Debug.LogError($"Not found {nameof(AssetListReporterViewer)}.uxml : {uxml}");
|
Debug.LogError($"Not found {nameof(ReporterAssetListViewer)}.uxml in settings.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_root = _visualAsset.CloneTree();
|
|
||||||
_root.style.flexGrow = 1f;
|
|
||||||
|
|
||||||
// 顶部按钮栏
|
try
|
||||||
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
|
{
|
||||||
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
|
_root = _visualAsset.CloneTree();
|
||||||
_topBar3 = _root.Q<ToolbarButton>("TopBar3");
|
_root.style.flexGrow = 1f;
|
||||||
_topBar1.clicked += TopBar1_clicked;
|
|
||||||
_topBar2.clicked += TopBar2_clicked;
|
|
||||||
_topBar3.clicked += TopBar3_clicked;
|
|
||||||
|
|
||||||
// 底部按钮栏
|
// 顶部按钮栏
|
||||||
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
|
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
|
||||||
_bottomBar2 = _root.Q<ToolbarButton>("BottomBar2");
|
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
|
||||||
_bottomBar3 = _root.Q<ToolbarButton>("BottomBar3");
|
_topBar1.clicked += TopBar1_clicked;
|
||||||
|
_topBar2.clicked += TopBar2_clicked;
|
||||||
// 资源列表
|
|
||||||
_assetListView = _root.Q<ListView>("TopListView");
|
|
||||||
_assetListView.makeItem = MakeAssetListViewItem;
|
|
||||||
_assetListView.bindItem = BindAssetListViewItem;
|
|
||||||
|
|
||||||
|
// 底部按钮栏
|
||||||
|
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
|
||||||
|
|
||||||
|
// 资源列表
|
||||||
|
_assetListView = _root.Q<ListView>("TopListView");
|
||||||
|
_assetListView.makeItem = MakeAssetListViewItem;
|
||||||
|
_assetListView.bindItem = BindAssetListViewItem;
|
||||||
#if UNITY_2020_1_OR_NEWER
|
#if UNITY_2020_1_OR_NEWER
|
||||||
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
|
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
|
||||||
#else
|
#else
|
||||||
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
|
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
|
||||||
#endif
|
#endif
|
||||||
// 依赖列表
|
|
||||||
_dependListView = _root.Q<ListView>("BottomListView");
|
// 依赖列表
|
||||||
_dependListView.makeItem = MakeDependListViewItem;
|
_dependListView = _root.Q<ListView>("BottomListView");
|
||||||
_dependListView.bindItem = BindDependListViewItem;
|
_dependListView.makeItem = MakeDependListViewItem;
|
||||||
|
_dependListView.bindItem = BindDependListViewItem;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError(e.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -76,23 +86,76 @@ namespace YooAsset.Editor
|
|||||||
public void FillViewData(BuildReport buildReport, string searchKeyWord)
|
public void FillViewData(BuildReport buildReport, string searchKeyWord)
|
||||||
{
|
{
|
||||||
_buildReport = buildReport;
|
_buildReport = buildReport;
|
||||||
_assetListView.Clear();
|
_searchKeyWord = searchKeyWord;
|
||||||
_assetListView.itemsSource = FilterViewItems(buildReport, searchKeyWord);
|
RefreshView();
|
||||||
_topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count})";
|
|
||||||
}
|
}
|
||||||
private List<ReportAssetInfo> FilterViewItems(BuildReport buildReport, string searchKeyWord)
|
private void RefreshView()
|
||||||
{
|
{
|
||||||
List<ReportAssetInfo> result = new List<ReportAssetInfo>(buildReport.AssetInfos.Count);
|
_assetListView.Clear();
|
||||||
foreach (var assetInfo in buildReport.AssetInfos)
|
_assetListView.ClearSelection();
|
||||||
|
_assetListView.itemsSource = FilterAndSortViewItems();
|
||||||
|
_assetListView.Rebuild();
|
||||||
|
RefreshSortingSymbol();
|
||||||
|
}
|
||||||
|
private List<ReportAssetInfo> FilterAndSortViewItems()
|
||||||
|
{
|
||||||
|
List<ReportAssetInfo> result = new List<ReportAssetInfo>(_buildReport.AssetInfos.Count);
|
||||||
|
|
||||||
|
// 过滤列表
|
||||||
|
foreach (var assetInfo in _buildReport.AssetInfos)
|
||||||
{
|
{
|
||||||
if(string.IsNullOrEmpty(searchKeyWord) == false)
|
if (string.IsNullOrEmpty(_searchKeyWord) == false)
|
||||||
{
|
{
|
||||||
if (assetInfo.AssetPath.Contains(searchKeyWord) == false)
|
if (assetInfo.AssetPath.Contains(_searchKeyWord) == false)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result.Add(assetInfo);
|
result.Add(assetInfo);
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
// 排序列表
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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>
|
||||||
@@ -133,18 +196,8 @@ namespace YooAsset.Editor
|
|||||||
label.name = "Label2";
|
label.name = "Label2";
|
||||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
label.style.marginLeft = 3f;
|
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.flexGrow = 1f;
|
||||||
label.style.width = 145;
|
label.style.width = 150;
|
||||||
element.Add(label);
|
element.Add(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,19 +207,15 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
var sourceData = _assetListView.itemsSource as List<ReportAssetInfo>;
|
var sourceData = _assetListView.itemsSource as List<ReportAssetInfo>;
|
||||||
var assetInfo = sourceData[index];
|
var assetInfo = sourceData[index];
|
||||||
var bundleInfo = _buildReport.GetBundleInfo(assetInfo.MainBundle);
|
var bundleInfo = _buildReport.GetBundleInfo(assetInfo.MainBundleName);
|
||||||
|
|
||||||
// Asset Path
|
// Asset Path
|
||||||
var label1 = element.Q<Label>("Label1");
|
var label1 = element.Q<Label>("Label1");
|
||||||
label1.text = assetInfo.AssetPath;
|
label1.text = assetInfo.AssetPath;
|
||||||
|
|
||||||
// Size
|
|
||||||
var label2 = element.Q<Label>("Label2");
|
|
||||||
label2.text = GetAssetFileSize(assetInfo.AssetPath);
|
|
||||||
|
|
||||||
// Main Bundle
|
// Main Bundle
|
||||||
var label3 = element.Q<Label>("Label3");
|
var label2 = element.Q<Label>("Label2");
|
||||||
label3.text = bundleInfo.BundleName;
|
label2.text = bundleInfo.BundleName;
|
||||||
}
|
}
|
||||||
private void AssetListView_onSelectionChange(IEnumerable<object> objs)
|
private void AssetListView_onSelectionChange(IEnumerable<object> objs)
|
||||||
{
|
{
|
||||||
@@ -177,22 +226,41 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void TopBar1_clicked()
|
private void TopBar1_clicked()
|
||||||
{
|
{
|
||||||
|
if (_sortMode != ESortMode.AssetPath)
|
||||||
|
{
|
||||||
|
_sortMode = ESortMode.AssetPath;
|
||||||
|
_descendingSort = false;
|
||||||
|
RefreshView();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_descendingSort = !_descendingSort;
|
||||||
|
RefreshView();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void TopBar2_clicked()
|
private void TopBar2_clicked()
|
||||||
{
|
{
|
||||||
}
|
if (_sortMode != ESortMode.BundleName)
|
||||||
private void TopBar3_clicked()
|
{
|
||||||
{
|
_sortMode = ESortMode.BundleName;
|
||||||
|
_descendingSort = false;
|
||||||
|
RefreshView();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_descendingSort = !_descendingSort;
|
||||||
|
RefreshView();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 依赖列表相关
|
// 依赖列表相关
|
||||||
private void FillDependListView(ReportAssetInfo assetInfo)
|
private void FillDependListView(ReportAssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
List<ReportBundleInfo> bundles = new List<ReportBundleInfo>();
|
List<ReportBundleInfo> bundles = new List<ReportBundleInfo>();
|
||||||
var mainBundle = _buildReport.GetBundleInfo(assetInfo.MainBundle);
|
var mainBundle = _buildReport.GetBundleInfo(assetInfo.MainBundleName);
|
||||||
bundles.Add(mainBundle);
|
bundles.Add(mainBundle);
|
||||||
foreach(string dependBundleName in assetInfo.DependBundles)
|
foreach (string dependBundleName in assetInfo.DependBundles)
|
||||||
{
|
{
|
||||||
var dependBundle = _buildReport.GetBundleInfo(dependBundleName);
|
var dependBundle = _buildReport.GetBundleInfo(dependBundleName);
|
||||||
bundles.Add(dependBundle);
|
bundles.Add(dependBundle);
|
||||||
@@ -201,6 +269,7 @@ namespace YooAsset.Editor
|
|||||||
_dependListView.Clear();
|
_dependListView.Clear();
|
||||||
_dependListView.ClearSelection();
|
_dependListView.ClearSelection();
|
||||||
_dependListView.itemsSource = bundles;
|
_dependListView.itemsSource = bundles;
|
||||||
|
_dependListView.Rebuild();
|
||||||
_bottomBar1.text = $"Depend Bundles ({bundles.Count})";
|
_bottomBar1.text = $"Depend Bundles ({bundles.Count})";
|
||||||
}
|
}
|
||||||
private VisualElement MakeDependListViewItem()
|
private VisualElement MakeDependListViewItem()
|
||||||
@@ -234,7 +303,7 @@ namespace YooAsset.Editor
|
|||||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||||
label.style.marginLeft = 3f;
|
label.style.marginLeft = 3f;
|
||||||
//label.style.flexGrow = 1f;
|
//label.style.flexGrow = 1f;
|
||||||
label.style.width = 250;
|
label.style.width = 280;
|
||||||
element.Add(label);
|
element.Add(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,21 +320,12 @@ namespace YooAsset.Editor
|
|||||||
|
|
||||||
// Size
|
// Size
|
||||||
var label2 = element.Q<Label>("Label2");
|
var label2 = element.Q<Label>("Label2");
|
||||||
label2.text = (bundleInfo.SizeBytes / 1024f).ToString("f1") + " KB";
|
label2.text = EditorUtility.FormatBytes(bundleInfo.SizeBytes);
|
||||||
|
|
||||||
// Hash
|
// Hash
|
||||||
var label3 = element.Q<Label>("Label3");
|
var label3 = element.Q<Label>("Label3");
|
||||||
label3.text = bundleInfo.Hash;
|
label3.text = bundleInfo.Hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetAssetFileSize(string assetPath)
|
|
||||||
{
|
|
||||||
string fullPath = EditorTools.GetProjectPath() + "/" + assetPath;
|
|
||||||
if (File.Exists(fullPath) == false)
|
|
||||||
return "unknown";
|
|
||||||
else
|
|
||||||
return (EditorTools.GetFileSize(fullPath) / 1024f).ToString("f1") + " KB";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2,17 +2,16 @@
|
|||||||
<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;">
|
<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: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="Asset Path" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||||
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
<uie:ToolbarButton text="Main Bundle" display-tooltip-when-elided="true" name="TopBar2" style="width: 145px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||||
<uie:ToolbarButton text="Main Bundle" display-tooltip-when-elided="true" name="TopBar3" style="width: 145px; -unity-text-align: middle-left; flex-grow: 1;" />
|
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
<ui:ListView focusable="true" name="TopListView" item-height="18" style="flex-grow: 1;" />
|
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||||
</ui:VisualElement>
|
</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;">
|
<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: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="Depend Bundles" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||||
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="BottomBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="BottomBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||||
<uie:ToolbarButton text="Hash" display-tooltip-when-elided="true" name="BottomBar3" style="width: 250px; -unity-text-align: middle-left;" />
|
<uie:ToolbarButton text="Hash" display-tooltip-when-elided="true" name="BottomBar3" style="width: 280px; -unity-text-align: middle-left;" />
|
||||||
</uie:Toolbar>
|
</uie:Toolbar>
|
||||||
<ui:ListView focusable="true" name="BottomListView" item-height="18" style="flex-grow: 1;" />
|
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
@@ -0,0 +1,398 @@
|
|||||||
|
#if UNITY_2019_4_OR_NEWER
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor.UIElements;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
internal class ReporterBundleListViewer
|
||||||
|
{
|
||||||
|
private enum ESortMode
|
||||||
|
{
|
||||||
|
BundleName,
|
||||||
|
BundleSize,
|
||||||
|
BundleTags
|
||||||
|
}
|
||||||
|
|
||||||
|
private VisualTreeAsset _visualAsset;
|
||||||
|
private TemplateContainer _root;
|
||||||
|
|
||||||
|
private ToolbarButton _topBar1;
|
||||||
|
private ToolbarButton _topBar2;
|
||||||
|
private ToolbarButton _topBar3;
|
||||||
|
private ToolbarButton _topBar4;
|
||||||
|
private ToolbarButton _bottomBar1;
|
||||||
|
private ListView _bundleListView;
|
||||||
|
private ListView _includeListView;
|
||||||
|
|
||||||
|
private BuildReport _buildReport;
|
||||||
|
private string _reportFilePath;
|
||||||
|
private string _searchKeyWord;
|
||||||
|
private ESortMode _sortMode = ESortMode.BundleName;
|
||||||
|
private bool _descendingSort = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化页面
|
||||||
|
/// </summary>
|
||||||
|
public void InitViewer()
|
||||||
|
{
|
||||||
|
// 加载布局文件
|
||||||
|
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterBundleListViewerUXML;
|
||||||
|
if (_visualAsset == null)
|
||||||
|
{
|
||||||
|
Debug.LogError($"Not found {nameof(ReporterBundleListViewer)}.uxml in settings.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_root = _visualAsset.CloneTree();
|
||||||
|
_root.style.flexGrow = 1f;
|
||||||
|
|
||||||
|
// 顶部按钮栏
|
||||||
|
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
|
||||||
|
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
|
||||||
|
_topBar3 = _root.Q<ToolbarButton>("TopBar3");
|
||||||
|
_topBar4 = _root.Q<ToolbarButton>("TopBar4");
|
||||||
|
_topBar1.clicked += TopBar1_clicked;
|
||||||
|
_topBar2.clicked += TopBar2_clicked;
|
||||||
|
_topBar3.clicked += TopBar3_clicked;
|
||||||
|
_topBar4.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
|
||||||
|
|
||||||
|
// 包含列表
|
||||||
|
_includeListView = _root.Q<ListView>("BottomListView");
|
||||||
|
_includeListView.makeItem = MakeIncludeListViewItem;
|
||||||
|
_includeListView.bindItem = BindIncludeListViewItem;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError(e.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 填充页面数据
|
||||||
|
/// </summary>
|
||||||
|
public void FillViewData( BuildReport buildReport, string reprotFilePath, string searchKeyWord)
|
||||||
|
{
|
||||||
|
_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);
|
||||||
|
|
||||||
|
// 过滤列表
|
||||||
|
foreach (var bundleInfo in _buildReport.BundleInfos)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_searchKeyWord) == false)
|
||||||
|
{
|
||||||
|
if (bundleInfo.BundleName.Contains(_searchKeyWord) == false)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result.Add(bundleInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 排序列表
|
||||||
|
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.SizeBytes).ToList();
|
||||||
|
else
|
||||||
|
return result.OrderBy(a => a.SizeBytes).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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void RefreshSortingSymbol()
|
||||||
|
{
|
||||||
|
// 刷新符号
|
||||||
|
_topBar1.text = $"Bundle Name ({_bundleListView.itemsSource.Count})";
|
||||||
|
_topBar2.text = "Size";
|
||||||
|
_topBar3.text = "Hash";
|
||||||
|
_topBar4.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)
|
||||||
|
_topBar4.text = "Tags ↓";
|
||||||
|
else
|
||||||
|
_topBar4.text = "Tags ↑";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 挂接到父类页面上
|
||||||
|
/// </summary>
|
||||||
|
public void AttachParent(VisualElement parent)
|
||||||
|
{
|
||||||
|
parent.Add(_root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从父类页面脱离开
|
||||||
|
/// </summary>
|
||||||
|
public void DetachParent()
|
||||||
|
{
|
||||||
|
_root.RemoveFromHierarchy();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 顶部列表相关
|
||||||
|
private VisualElement MakeBundleListViewItem()
|
||||||
|
{
|
||||||
|
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 = 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 = 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.SizeBytes);
|
||||||
|
|
||||||
|
// Hash
|
||||||
|
var label3 = element.Q<Label>("Label3");
|
||||||
|
label3.text = bundleInfo.Hash;
|
||||||
|
|
||||||
|
// Tags
|
||||||
|
var label5 = element.Q<Label>("Label5");
|
||||||
|
label5.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 (bundleInfo.IsRawFile())
|
||||||
|
return;
|
||||||
|
|
||||||
|
string rootDirectory = Path.GetDirectoryName(_reportFilePath);
|
||||||
|
string filePath = $"{rootDirectory}/{bundleInfo.Hash}";
|
||||||
|
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>();
|
||||||
|
foreach (var assetInfo in _buildReport.AssetInfos)
|
||||||
|
{
|
||||||
|
if (assetInfo.MainBundleName == bundleInfo.BundleName)
|
||||||
|
containsList.Add(assetInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
_includeListView.Clear();
|
||||||
|
_includeListView.ClearSelection();
|
||||||
|
_includeListView.itemsSource = containsList;
|
||||||
|
_includeListView.Rebuild();
|
||||||
|
_bottomBar1.text = $"Include Assets ({containsList.Count})";
|
||||||
|
}
|
||||||
|
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 = 280;
|
||||||
|
element.Add(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
private void BindIncludeListViewItem(VisualElement element, int index)
|
||||||
|
{
|
||||||
|
List<ReportAssetInfo> containsList = _includeListView.itemsSource as List<ReportAssetInfo>;
|
||||||
|
ReportAssetInfo assetInfo = containsList[index];
|
||||||
|
|
||||||
|
// Asset Path
|
||||||
|
var label1 = element.Q<Label>("Label1");
|
||||||
|
label1.text = assetInfo.AssetPath;
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
var label2 = element.Q<Label>("Label2");
|
||||||
|
label2.text = assetInfo.AssetGUID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user