mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-14 19:40:47 +00:00
Compare commits
78 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 | ||
|
|
9b3839ac0b | ||
|
|
ff74dcdd8b |
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
|
||||
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:
|
||||
@@ -1,6 +1,140 @@
|
||||
# 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
|
||||
|
||||
|
||||
@@ -26,7 +26,12 @@ namespace YooAsset.Editor
|
||||
public BuildParametersContext(BuildParameters parameters)
|
||||
{
|
||||
Parameters = parameters;
|
||||
|
||||
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget);
|
||||
if (parameters.BuildMode == EBuildMode.DryRunBuild)
|
||||
PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}";
|
||||
else if (parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -48,7 +53,10 @@ namespace YooAsset.Editor
|
||||
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
|
||||
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
|
||||
|
||||
if (Parameters.DryRunBuild)
|
||||
if (Parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
if (Parameters.BuildMode == EBuildMode.DryRunBuild)
|
||||
{
|
||||
opt |= BuildAssetBundleOptions.DryRunBuild;
|
||||
return opt;
|
||||
@@ -59,19 +67,15 @@ namespace YooAsset.Editor
|
||||
else if (Parameters.CompressOption == ECompressOption.LZ4)
|
||||
opt |= BuildAssetBundleOptions.ChunkBasedCompression;
|
||||
|
||||
if (Parameters.ForceRebuild)
|
||||
if (Parameters.BuildMode == EBuildMode.ForceRebuild)
|
||||
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
|
||||
if (Parameters.AppendHash)
|
||||
opt |= BuildAssetBundleOptions.AppendHashToAssetBundleName; //Append the hash to the assetBundle name
|
||||
if (Parameters.DisableWriteTypeTree)
|
||||
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
|
||||
if (Parameters.IgnoreTypeTreeChanges)
|
||||
opt |= BuildAssetBundleOptions.IgnoreTypeTreeChanges; //Ignore the type tree changes when doing the incremental build check.
|
||||
if (Parameters.DisableLoadAssetByFileName)
|
||||
{
|
||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
|
||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
|
||||
}
|
||||
|
||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileName; //Disables Asset Bundle LoadAsset by file name.
|
||||
opt |= BuildAssetBundleOptions.DisableLoadAssetByFileNameWithExtension; //Disables Asset Bundle LoadAsset by file name with extension.
|
||||
|
||||
return opt;
|
||||
}
|
||||
@@ -79,9 +83,9 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取构建的耗时(单位:秒)
|
||||
/// </summary>
|
||||
public int GetBuildingSeconds()
|
||||
public float GetBuildingSeconds()
|
||||
{
|
||||
int seconds = (int)(_buildWatch.ElapsedMilliseconds / 1000);
|
||||
float seconds = _buildWatch.ElapsedMilliseconds / 1000f;
|
||||
return seconds;
|
||||
}
|
||||
public void BeginWatch()
|
||||
@@ -122,11 +126,16 @@ namespace YooAsset.Editor
|
||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||
};
|
||||
|
||||
if (buildParameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
BuildRunner.EnableLog = false;
|
||||
else
|
||||
BuildRunner.EnableLog = true;
|
||||
|
||||
bool succeed = BuildRunner.Run(pipeline, _buildContext);
|
||||
if (succeed)
|
||||
Debug.Log($"构建成功!");
|
||||
Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !");
|
||||
else
|
||||
Debug.LogWarning($"构建失败!");
|
||||
Debug.LogWarning($"{buildParameters.BuildMode} pipeline build failed !");
|
||||
return succeed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,16 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public int BuildVersion = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 构建模式
|
||||
/// </summary>
|
||||
public EBuildMode BuildMode = EBuildMode.ForceRebuild;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源标签
|
||||
/// </summary>
|
||||
public string BuildTags = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 压缩方式
|
||||
/// </summary>
|
||||
@@ -24,15 +34,5 @@ namespace YooAsset.Editor
|
||||
/// 附加后缀格式
|
||||
/// </summary>
|
||||
public bool AppendExtension = false;
|
||||
|
||||
/// <summary>
|
||||
/// 强制构建
|
||||
/// </summary>
|
||||
public bool ForceRebuild = false;
|
||||
|
||||
/// <summary>
|
||||
/// 内置标签
|
||||
/// </summary>
|
||||
public string BuildTags = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -24,21 +24,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private static void LoadSettingData()
|
||||
{
|
||||
// 加载配置文件
|
||||
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleBuilderSetting>(EditorDefine.AssetBundleBuilderSettingFilePath);
|
||||
if (_setting == null)
|
||||
{
|
||||
Debug.LogWarning($"Create new {nameof(AssetBundleBuilderSetting)}.asset : {EditorDefine.AssetBundleBuilderSettingFilePath}");
|
||||
_setting = ScriptableObject.CreateInstance<AssetBundleBuilderSetting>();
|
||||
EditorTools.CreateFileDirectory(EditorDefine.AssetBundleBuilderSettingFilePath);
|
||||
AssetDatabase.CreateAsset(Setting, EditorDefine.AssetBundleBuilderSettingFilePath);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"Load {nameof(AssetBundleBuilderSetting)}.asset ok");
|
||||
}
|
||||
_setting = YooAssetEditorSettingsHelper.LoadSettingData<AssetBundleBuilderSetting>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -14,8 +14,7 @@ namespace YooAsset.Editor
|
||||
[MenuItem("YooAsset/AssetBundle Builder", false, 102)]
|
||||
public static void ShowExample()
|
||||
{
|
||||
AssetBundleBuilderWindow window = GetWindow<AssetBundleBuilderWindow>();
|
||||
window.titleContent = new GUIContent("资源包构建工具");
|
||||
AssetBundleBuilderWindow window = GetWindow<AssetBundleBuilderWindow>("资源包构建工具", true, EditorDefine.DockedWindowTypes);
|
||||
window.minSize = new Vector2(800, 600);
|
||||
}
|
||||
|
||||
@@ -23,32 +22,29 @@ namespace YooAsset.Editor
|
||||
private List<Type> _encryptionServicesClassTypes;
|
||||
private List<string> _encryptionServicesClassNames;
|
||||
|
||||
private TextField _buildOutputTxt;
|
||||
private TextField _buildOutputField;
|
||||
private IntegerField _buildVersionField;
|
||||
private EnumField _compressionField;
|
||||
private EnumField _buildModeField;
|
||||
private TextField _buildTagsField;
|
||||
private PopupField<string> _encryptionField;
|
||||
private EnumField _compressionField;
|
||||
private Toggle _appendExtensionToggle;
|
||||
private Toggle _forceRebuildToggle;
|
||||
private TextField _buildTagsTxt;
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
|
||||
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
|
||||
@@ -56,9 +52,9 @@ namespace YooAsset.Editor
|
||||
// 输出目录
|
||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||
string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(defaultOutputRoot, _buildTarget);
|
||||
_buildOutputTxt = root.Q<TextField>("BuildOutput");
|
||||
_buildOutputTxt.SetValueWithoutNotify(pipelineOutputDirectory);
|
||||
_buildOutputTxt.SetEnabled(false);
|
||||
_buildOutputField = root.Q<TextField>("BuildOutput");
|
||||
_buildOutputField.SetValueWithoutNotify(pipelineOutputDirectory);
|
||||
_buildOutputField.SetEnabled(false);
|
||||
|
||||
// 构建版本
|
||||
_buildVersionField = root.Q<IntegerField>("BuildVersion");
|
||||
@@ -68,29 +64,30 @@ namespace YooAsset.Editor
|
||||
AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
|
||||
});
|
||||
|
||||
// 压缩方式
|
||||
_compressionField = root.Q<EnumField>("Compression");
|
||||
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||
_compressionField.style.width = 300;
|
||||
_compressionField.RegisterValueChangedCallback(evt =>
|
||||
// 构建模式
|
||||
_buildModeField = root.Q<EnumField>("BuildMode");
|
||||
_buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode);
|
||||
_buildModeField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildMode);
|
||||
_buildModeField.style.width = 300;
|
||||
_buildModeField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
|
||||
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");
|
||||
if (_encryptionServicesClassNames.Count > 0)
|
||||
{
|
||||
int defaultIndex = 0;
|
||||
for (int index = 0; index < _encryptionServicesClassNames.Count; index++)
|
||||
{
|
||||
if (_encryptionServicesClassNames[index] == AssetBundleBuilderSettingData.Setting.EncyptionClassName)
|
||||
{
|
||||
defaultIndex = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int defaultIndex = GetEncryptionDefaultIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName);
|
||||
_encryptionField = new PopupField<string>(_encryptionServicesClassNames, defaultIndex);
|
||||
_encryptionField.label = "Encryption";
|
||||
_encryptionField.style.width = 300;
|
||||
@@ -108,6 +105,16 @@ namespace YooAsset.Editor
|
||||
encryptionContainer.Add(_encryptionField);
|
||||
}
|
||||
|
||||
// 压缩方式
|
||||
_compressionField = root.Q<EnumField>("Compression");
|
||||
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
|
||||
_compressionField.style.width = 300;
|
||||
_compressionField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
|
||||
});
|
||||
|
||||
// 附加后缀格式
|
||||
_appendExtensionToggle = root.Q<Toggle>("AppendExtension");
|
||||
_appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension);
|
||||
@@ -116,27 +123,11 @@ namespace YooAsset.Editor
|
||||
AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value;
|
||||
});
|
||||
|
||||
// 强制构建
|
||||
_forceRebuildToggle = root.Q<Toggle>("ForceRebuild");
|
||||
_forceRebuildToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.ForceRebuild);
|
||||
_forceRebuildToggle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSettingData.Setting.ForceRebuild = _forceRebuildToggle.value;
|
||||
_buildTagsTxt.SetEnabled(_forceRebuildToggle.value);
|
||||
});
|
||||
|
||||
// 内置标签
|
||||
_buildTagsTxt = root.Q<TextField>("BuildinTags");
|
||||
_buildTagsTxt.SetEnabled(_forceRebuildToggle.value);
|
||||
_buildTagsTxt.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
|
||||
_buildTagsTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSettingData.Setting.BuildTags = _buildTagsTxt.value;
|
||||
});
|
||||
|
||||
// 构建按钮
|
||||
var buildButton = root.Q<Button>("Build");
|
||||
buildButton.clicked += BuildButton_clicked; ;
|
||||
|
||||
RefreshWindow();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -148,21 +139,18 @@ namespace YooAsset.Editor
|
||||
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()
|
||||
{
|
||||
string title;
|
||||
string content;
|
||||
if (_forceRebuildToggle.value)
|
||||
{
|
||||
title = "警告";
|
||||
content = "确定开始强制构建吗,这样会删除所有已有构建的文件";
|
||||
}
|
||||
else
|
||||
{
|
||||
title = "提示";
|
||||
content = "确定开始增量构建吗";
|
||||
}
|
||||
if (EditorUtility.DisplayDialog(title, content, "Yes", "No"))
|
||||
var buildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
|
||||
if (EditorUtility.DisplayDialog("提示", $"通过构建模式【{buildMode}】来构建!", "Yes", "No"))
|
||||
{
|
||||
EditorTools.ClearUnityConsole();
|
||||
EditorApplication.delayCall += ExecuteBuild;
|
||||
@@ -180,33 +168,37 @@ namespace YooAsset.Editor
|
||||
{
|
||||
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
|
||||
BuildParameters buildParameters = new BuildParameters();
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.OutputRoot = defaultOutputRoot;
|
||||
buildParameters.BuildTarget = _buildTarget;
|
||||
buildParameters.BuildMode = (EBuildMode)_buildModeField.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.EncryptionServices = CreateEncryptionServicesInstance();
|
||||
buildParameters.ForceRebuild = _forceRebuildToggle.value;
|
||||
buildParameters.BuildinTags = _buildTagsTxt.value;
|
||||
buildParameters.CompressOption = (ECompressOption)_compressionField.value;
|
||||
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
builder.Run(buildParameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加密类的类型列表
|
||||
/// </summary>
|
||||
private List<Type> GetEncryptionServicesClassTypes()
|
||||
{
|
||||
TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom<IEncryptionServices>();
|
||||
List<Type> classTypes = collection.ToList();
|
||||
return classTypes;
|
||||
// 加密类相关
|
||||
private int GetEncryptionDefaultIndex(string className)
|
||||
{
|
||||
for (int index = 0; index < _encryptionServicesClassNames.Count; index++)
|
||||
{
|
||||
if (_encryptionServicesClassNames[index] == className)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private List<Type> GetEncryptionServicesClassTypes()
|
||||
{
|
||||
return EditorTools.GetAssignableTypes(typeof(IEncryptionServices));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建加密类的实例
|
||||
/// </summary>
|
||||
private IEncryptionServices CreateEncryptionServicesInstance()
|
||||
{
|
||||
if (_encryptionField.index < 0)
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
<ui:VisualElement name="BuildContainer">
|
||||
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
|
||||
<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;" />
|
||||
<uie:EnumField label="Compression" value="Center" name="Compression" />
|
||||
<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:Button text="构建" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
|
||||
</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.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class BuildAssetInfo
|
||||
{
|
||||
private string _mainBundleName;
|
||||
private string _shareBundleName;
|
||||
private readonly HashSet<string> _referenceBundleNames = new HashSet<string>();
|
||||
private bool _isAddAssetTags = false;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// 收集器类型
|
||||
/// </summary>
|
||||
public string BundleName { private set; get; }
|
||||
public ECollectorType CollectorType { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 可寻址地址
|
||||
/// </summary>
|
||||
public string Address { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
@@ -21,31 +32,21 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IsRawAsset { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 不写入资源列表
|
||||
/// </summary>
|
||||
public bool NotWriteToAssetList { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主动收集资源
|
||||
/// </summary>
|
||||
public bool IsCollectAsset { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为着色器资源
|
||||
/// </summary>
|
||||
public bool IsShaderAsset { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 被依赖次数
|
||||
/// </summary>
|
||||
public int DependCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 资源分类标签列表
|
||||
/// 资源的分类标签
|
||||
/// </summary>
|
||||
public readonly List<string> AssetTags = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 资源包的分类标签
|
||||
/// </summary>
|
||||
public readonly List<string> BundleTags = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 依赖的所有资源
|
||||
/// 注意:包括零依赖资源和冗余资源(资源包名无效)
|
||||
@@ -53,12 +54,13 @@ namespace YooAsset.Editor
|
||||
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;
|
||||
IsRawAsset = isRawAsset;
|
||||
NotWriteToAssetList = notWriteToAssetList;
|
||||
IsCollectAsset = true;
|
||||
|
||||
System.Type assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader))
|
||||
@@ -66,12 +68,12 @@ namespace YooAsset.Editor
|
||||
else
|
||||
IsShaderAsset = false;
|
||||
}
|
||||
public BuildAssetInfo(string assetPath)
|
||||
public BuildAssetInfo(ECollectorType collectorType, string assetPath)
|
||||
{
|
||||
CollectorType = collectorType;
|
||||
Address = string.Empty;
|
||||
AssetPath = assetPath;
|
||||
IsRawAsset = false;
|
||||
NotWriteToAssetList = true;
|
||||
IsCollectAsset = false;
|
||||
|
||||
System.Type assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader))
|
||||
@@ -80,6 +82,7 @@ namespace YooAsset.Editor
|
||||
IsShaderAsset = false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置所有依赖的资源
|
||||
/// </summary>
|
||||
@@ -92,47 +95,117 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置资源包名称
|
||||
/// </summary>
|
||||
public void SetBundleName(string bundleName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(BundleName) == false)
|
||||
throw new System.Exception("Should never get here !");
|
||||
|
||||
BundleName = bundleName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加资源分类标签
|
||||
/// 添加资源的分类标签
|
||||
/// 说明:原始定义的资源分类标签
|
||||
/// </summary>
|
||||
public void AddAssetTags(List<string> tags)
|
||||
{
|
||||
if (_isAddAssetTags)
|
||||
throw new Exception("Should never get here !");
|
||||
_isAddAssetTags = true;
|
||||
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
AddAssetTag(tag);
|
||||
if (AssetTags.Contains(tag) == false)
|
||||
{
|
||||
AssetTags.Add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <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>
|
||||
public bool BundleNameIsValid()
|
||||
public bool HasBundleName()
|
||||
{
|
||||
if (string.IsNullOrEmpty(BundleName))
|
||||
string bundleName = GetBundleName();
|
||||
if (string.IsNullOrEmpty(bundleName))
|
||||
return false;
|
||||
else
|
||||
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>
|
||||
public string[] GetAssetTags()
|
||||
public string[] GetBundleTags()
|
||||
{
|
||||
List<string> result = new List<string>(BuildinAssets.Count);
|
||||
foreach (var assetInfo in BuildinAssets)
|
||||
{
|
||||
foreach (var assetTag in assetInfo.AssetTags)
|
||||
foreach (var assetTag in assetInfo.BundleTags)
|
||||
{
|
||||
if (result.Contains(assetTag) == false)
|
||||
result.Add(assetTag);
|
||||
@@ -105,7 +105,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public BuildAssetInfo[] GetAllPatchAssetInfos()
|
||||
{
|
||||
return BuildinAssets.Where(t => t.IsCollectAsset && t.NotWriteToAssetList == false).ToArray();
|
||||
return BuildinAssets.Where(t => t.CollectorType == ECollectorType.MainAssetCollector).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -25,13 +25,17 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
BuildBundleInfo newBundleInfo = new BuildBundleInfo(assetInfo.BundleName);
|
||||
BuildBundleInfo newBundleInfo = new BuildBundleInfo(bundleName);
|
||||
newBundleInfo.PackAsset(assetInfo);
|
||||
BundleInfos.Add(newBundleInfo);
|
||||
}
|
||||
@@ -51,13 +55,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取AssetBundle内包含的标记列表
|
||||
/// 获取资源包的分类标签列表
|
||||
/// </summary>
|
||||
public string[] GetAssetTags(string bundleName)
|
||||
public string[] GetBundleTags(string bundleName)
|
||||
{
|
||||
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
|
||||
{
|
||||
return bundleInfo.GetAssetTags();
|
||||
return bundleInfo.GetBundleTags();
|
||||
}
|
||||
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,128 +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 (AssetBundleGrouperSettingData.Setting.AutoCollectShaders)
|
||||
{
|
||||
if (buildAssetInfo.IsShaderAsset)
|
||||
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 shaderBundleName = AssetBundleCollector.CollectShaderBundleName(buildAssetInfo.AssetPath);
|
||||
if (string.IsNullOrEmpty(shaderBundleName) == false)
|
||||
{
|
||||
buildAssetInfo.SetBundleName(shaderBundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
string bundleName = defaultPackRule.GetBundleName(new PackRuleData(buildAssetInfo.AssetPath));
|
||||
bundleName = AssetBundleCollector.CorrectBundleName(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>
|
||||
public class BuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 验证构建结果
|
||||
/// </summary>
|
||||
public bool VerifyBuildingResult = false;
|
||||
|
||||
/// <summary>
|
||||
/// 输出的根目录
|
||||
/// </summary>
|
||||
@@ -24,53 +19,48 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public BuildTarget BuildTarget;
|
||||
|
||||
/// <summary>
|
||||
/// 构建模式
|
||||
/// </summary>
|
||||
public EBuildMode BuildMode;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的版本(资源版本号)
|
||||
/// </summary>
|
||||
public int BuildVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 启用自动分包机制
|
||||
/// 说明:自动分包机制可以实现资源零冗余
|
||||
/// </summary>
|
||||
public bool EnableAutoCollect = true;
|
||||
|
||||
/// <summary>
|
||||
/// 追加文件扩展名
|
||||
/// </summary>
|
||||
public bool AppendFileExtension = false;
|
||||
|
||||
/// <summary>
|
||||
/// 加密类
|
||||
/// </summary>
|
||||
public IEncryptionServices EncryptionServices;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 演练构建模式
|
||||
/// </summary>
|
||||
public bool DryRunBuild;
|
||||
|
||||
/// <summary>
|
||||
/// 强制重新构建整个项目,如果为FALSE则是增量打包
|
||||
/// </summary>
|
||||
public bool ForceRebuild;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源的标记列表
|
||||
/// 注意:分号为分隔符
|
||||
/// </summary>
|
||||
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>
|
||||
public ECompressOption CompressOption;
|
||||
|
||||
/// <summary>
|
||||
/// 文件名附加上哈希值
|
||||
/// </summary>
|
||||
public bool AppendHash = false;
|
||||
public ECompressOption CompressOption = ECompressOption.Uncompressed;
|
||||
|
||||
/// <summary>
|
||||
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
|
||||
@@ -82,11 +72,6 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IgnoreTypeTreeChanges = true;
|
||||
|
||||
/// <summary>
|
||||
/// 禁用名称查找资源(可以降内存并提高加载效率)
|
||||
/// </summary>
|
||||
public bool DisableLoadAssetByFileName = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取内置标记列表
|
||||
|
||||
@@ -7,15 +7,36 @@ namespace YooAsset.Editor
|
||||
[Serializable]
|
||||
public class ReportAssetInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 可寻址地址
|
||||
/// </summary>
|
||||
public string Address;
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
public string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源GUID
|
||||
/// 说明:Meta文件记录的GUID
|
||||
/// </summary>
|
||||
public string AssetGUID;
|
||||
|
||||
/// <summary>
|
||||
/// 资源的分类标签
|
||||
/// </summary>
|
||||
public string[] AssetTags;
|
||||
|
||||
/// <summary>
|
||||
/// 所属资源包名称
|
||||
/// </summary>
|
||||
public string MainBundle;
|
||||
public string MainBundleName;
|
||||
|
||||
/// <summary>
|
||||
/// 所属资源包的大小
|
||||
/// </summary>
|
||||
public long MainBundleSize;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖的资源包名称列表
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -7,6 +8,21 @@ namespace YooAsset.Editor
|
||||
[Serializable]
|
||||
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>
|
||||
@@ -36,5 +52,44 @@ namespace YooAsset.Editor
|
||||
/// Flags
|
||||
/// </summary>
|
||||
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>
|
||||
public BuildTarget BuildTarget;
|
||||
|
||||
/// <summary>
|
||||
/// 构建模式
|
||||
/// </summary>
|
||||
public EBuildMode BuildMode;
|
||||
|
||||
/// <summary>
|
||||
/// 构建版本
|
||||
/// </summary>
|
||||
public int BuildVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 启用自动分包机制
|
||||
/// 内置资源标签
|
||||
/// </summary>
|
||||
public bool EnableAutoCollect;
|
||||
public string BuildinTags;
|
||||
|
||||
/// <summary>
|
||||
/// 启用可寻址资源定位
|
||||
/// </summary>
|
||||
public bool EnableAddressable;
|
||||
|
||||
/// <summary>
|
||||
/// 追加文件扩展名
|
||||
@@ -59,14 +69,9 @@ namespace YooAsset.Editor
|
||||
public string EncryptionServicesClassName;
|
||||
|
||||
// 构建参数
|
||||
public bool DryRunBuild;
|
||||
public bool ForceRebuild;
|
||||
public string BuildinTags;
|
||||
public ECompressOption CompressOption;
|
||||
public bool AppendHash;
|
||||
public bool DisableWriteTypeTree;
|
||||
public bool IgnoreTypeTreeChanges;
|
||||
public bool DisableLoadAssetByFileName;
|
||||
|
||||
// 构建结果
|
||||
public int AssetFileTotalCount;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class BuildRunner
|
||||
{
|
||||
public static bool EnableLog = true;
|
||||
|
||||
/// <summary>
|
||||
/// 执行构建流程
|
||||
/// </summary>
|
||||
@@ -24,12 +27,14 @@ namespace YooAsset.Editor
|
||||
IBuildTask task = pipeline[i];
|
||||
try
|
||||
{
|
||||
var taskAttribute = task.GetType().GetCustomAttribute<TaskAttribute>();
|
||||
Log($"---------------------------------------->{taskAttribute.Desc}");
|
||||
task.Run(context);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"Build task {task.GetType().Name} failed !");
|
||||
Debug.LogError($"Detail error : {e}");
|
||||
Debug.LogError($"Build error : {e}");
|
||||
succeed = false;
|
||||
break;
|
||||
}
|
||||
@@ -38,5 +43,24 @@ namespace YooAsset.Editor
|
||||
// 返回运行结果
|
||||
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
|
||||
{
|
||||
[TaskAttribute("资源构建内容打包")]
|
||||
public class TaskBuilding : IBuildTask
|
||||
{
|
||||
public class UnityManifestContext : IContextObject
|
||||
@@ -20,18 +21,23 @@ namespace YooAsset.Editor
|
||||
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
|
||||
Debug.Log($"开始构建......");
|
||||
// 模拟构建模式下跳过引擎构建
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return;
|
||||
|
||||
BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions();
|
||||
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(buildParametersContext.PipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), opt, buildParametersContext.Parameters.BuildTarget);
|
||||
if (unityManifest == null)
|
||||
throw new Exception("构建过程中发生错误!");
|
||||
|
||||
BuildRunner.Log("Unity引擎打包成功!");
|
||||
UnityManifestContext unityManifestContext = new UnityManifestContext();
|
||||
unityManifestContext.UnityManifest = unityManifest;
|
||||
context.SetContextObject(unityManifestContext);
|
||||
|
||||
// 拷贝原生文件
|
||||
if (buildParametersContext.Parameters.DryRunBuild == false)
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
CopyRawBundle(buildMapContext, buildParametersContext);
|
||||
}
|
||||
|
||||
@@ -6,16 +6,14 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 拷贝内置文件到StreamingAssets
|
||||
/// </summary>
|
||||
[TaskAttribute("拷贝内置文件到流目录")]
|
||||
public class TaskCopyBuildinFiles : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
// 注意:我们只有在强制重建的时候才会拷贝
|
||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||
if (buildParameters.Parameters.DryRunBuild == false && buildParameters.Parameters.ForceRebuild)
|
||||
if (buildParameters.Parameters.BuildMode == EBuildMode.ForceRebuild)
|
||||
{
|
||||
// 清空流目录
|
||||
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
|
||||
@@ -38,7 +36,6 @@ namespace YooAsset.Editor
|
||||
|
||||
string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}";
|
||||
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{patchBundle.Hash}";
|
||||
Debug.Log($"拷贝内置文件到流目录:{patchBundle.BundleName}");
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
}
|
||||
|
||||
@@ -65,6 +62,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 刷新目录
|
||||
AssetDatabase.Refresh();
|
||||
BuildRunner.Log($"内置文件拷贝完成:{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建补丁清单文件
|
||||
/// </summary>
|
||||
[TaskAttribute("创建补丁清单文件")]
|
||||
public class TaskCreatePatchManifest : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
@@ -28,26 +26,27 @@ namespace YooAsset.Editor
|
||||
|
||||
// 创建新补丁清单
|
||||
PatchManifest patchManifest = new PatchManifest();
|
||||
patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable;
|
||||
patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion;
|
||||
patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||
patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
|
||||
patchManifest.AssetList = GetAllPatchAsset(buildMapContext, patchManifest);
|
||||
patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest);
|
||||
|
||||
// 创建补丁清单文件
|
||||
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||
UnityEngine.Debug.Log($"创建补丁清单文件:{manifestFilePath}");
|
||||
BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}");
|
||||
PatchManifest.Serialize(manifestFilePath, patchManifest);
|
||||
|
||||
// 创建补丁清单哈希文件
|
||||
string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
|
||||
string manifestHash = HashUtility.FileMD5(manifestFilePath);
|
||||
UnityEngine.Debug.Log($"创建补丁清单哈希文件:{manifestHashFilePath}");
|
||||
BuildRunner.Log($"创建补丁清单哈希文件:{manifestHashFilePath}");
|
||||
FileUtility.CreateFile(manifestHashFilePath, manifestHash);
|
||||
|
||||
// 创建静态版本文件
|
||||
string staticVersionFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
|
||||
string staticVersion = resourceVersion.ToString();
|
||||
UnityEngine.Debug.Log($"创建静态版本文件:{staticVersionFilePath}");
|
||||
BuildRunner.Log($"创建静态版本文件:{staticVersionFilePath}");
|
||||
FileUtility.CreateFile(staticVersionFilePath, staticVersion);
|
||||
}
|
||||
|
||||
@@ -62,15 +61,16 @@ namespace YooAsset.Editor
|
||||
// 内置标记列表
|
||||
List<string> buildinTags = buildParameters.Parameters.GetBuildinTags();
|
||||
|
||||
bool dryRunBuild = buildParameters.Parameters.DryRunBuild;
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
bool standardBuild = buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild;
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
var bundleName = bundleInfo.BundleName;
|
||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
|
||||
string hash = GetFileHash(filePath, dryRunBuild);
|
||||
string crc32 = GetFileCRC(filePath, dryRunBuild);
|
||||
long size = GetFileSize(filePath, dryRunBuild);
|
||||
string[] tags = buildMapContext.GetAssetTags(bundleName);
|
||||
string hash = GetFileHash(filePath, standardBuild);
|
||||
string crc32 = GetFileCRC(filePath, standardBuild);
|
||||
long size = GetFileSize(filePath, standardBuild);
|
||||
string[] tags = buildMapContext.GetBundleTags(bundleName);
|
||||
bool isEncrypted = encryptionContext.IsEncryptFile(bundleName);
|
||||
bool isBuildin = IsBuildinBundle(tags, buildinTags);
|
||||
bool isRawFile = bundleInfo.IsRawFile;
|
||||
@@ -101,32 +101,33 @@ namespace YooAsset.Editor
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private string GetFileHash(string filePath, bool dryRunBuild)
|
||||
private string GetFileHash(string filePath, bool standardBuild)
|
||||
{
|
||||
if (dryRunBuild)
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
else
|
||||
if (standardBuild)
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
private string GetFileCRC(string filePath, bool dryRunBuild)
|
||||
{
|
||||
if (dryRunBuild)
|
||||
return "00000000"; //8位
|
||||
else
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
}
|
||||
private string GetFileCRC(string filePath, bool standardBuild)
|
||||
{
|
||||
if (standardBuild)
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
}
|
||||
private long GetFileSize(string filePath, bool dryRunBuild)
|
||||
{
|
||||
if (dryRunBuild)
|
||||
return 0;
|
||||
else
|
||||
return "00000000"; //8位
|
||||
}
|
||||
private long GetFileSize(string filePath, bool standardBuild)
|
||||
{
|
||||
if (standardBuild)
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <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);
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
@@ -135,8 +136,13 @@ namespace YooAsset.Editor
|
||||
foreach (var assetInfo in assetInfos)
|
||||
{
|
||||
PatchAsset patchAsset = new PatchAsset();
|
||||
if (buildParameters.Parameters.EnableAddressable)
|
||||
patchAsset.Address = assetInfo.Address;
|
||||
else
|
||||
patchAsset.Address = string.Empty;
|
||||
patchAsset.AssetPath = assetInfo.AssetPath;
|
||||
patchAsset.BundleID = GetAssetBundleID(assetInfo.BundleName, patchManifest);
|
||||
patchAsset.AssetTags = assetInfo.AssetTags.ToArray();
|
||||
patchAsset.BundleID = GetAssetBundleID(assetInfo.GetBundleName(), patchManifest);
|
||||
patchAsset.DependIDs = GetAssetBundleDependIDs(patchAsset.BundleID, assetInfo, patchManifest);
|
||||
result.Add(patchAsset);
|
||||
}
|
||||
@@ -148,13 +154,14 @@ namespace YooAsset.Editor
|
||||
List<int> result = new List<int>();
|
||||
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
|
||||
{
|
||||
if (dependAssetInfo.BundleNameIsValid() == false)
|
||||
continue;
|
||||
int bundleID = GetAssetBundleID(dependAssetInfo.BundleName, patchManifest);
|
||||
if (mainBundleID != bundleID)
|
||||
if (dependAssetInfo.HasBundleName())
|
||||
{
|
||||
if (result.Contains(bundleID) == false)
|
||||
result.Add(bundleID);
|
||||
int bundleID = GetAssetBundleID(dependAssetInfo.GetBundleName(), patchManifest);
|
||||
if (mainBundleID != bundleID)
|
||||
{
|
||||
if (result.Contains(bundleID) == false)
|
||||
result.Add(bundleID);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.ToArray();
|
||||
|
||||
@@ -3,15 +3,14 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 制作补丁包
|
||||
/// </summary>
|
||||
[TaskAttribute("制作补丁包")]
|
||||
public class TaskCreatePatchPackage : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||
if (buildParameters.Parameters.DryRunBuild == false)
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
CopyPatchFiles(buildParameters);
|
||||
}
|
||||
@@ -24,14 +23,14 @@ namespace YooAsset.Editor
|
||||
{
|
||||
int resourceVersion = buildParameters.Parameters.BuildVersion;
|
||||
string packageDirectory = buildParameters.GetPackageDirectory();
|
||||
UnityEngine.Debug.Log($"准备开始拷贝补丁文件到补丁包目录:{packageDirectory}");
|
||||
BuildRunner.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}");
|
||||
|
||||
// 拷贝Report文件
|
||||
{
|
||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.ReportFileName}";
|
||||
string destPath = $"{packageDirectory}/{YooAssetSettings.ReportFileName}";
|
||||
string reportFileName = YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion);
|
||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{reportFileName}";
|
||||
string destPath = $"{packageDirectory}/{reportFileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
UnityEngine.Debug.Log($"拷贝构建报告文件到:{destPath}");
|
||||
}
|
||||
|
||||
// 拷贝补丁清单文件
|
||||
@@ -39,7 +38,6 @@ namespace YooAsset.Editor
|
||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||
string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
UnityEngine.Debug.Log($"拷贝补丁清单文件到:{destPath}");
|
||||
}
|
||||
|
||||
// 拷贝补丁清单哈希文件
|
||||
@@ -47,7 +45,6 @@ namespace YooAsset.Editor
|
||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
|
||||
string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
UnityEngine.Debug.Log($"拷贝补丁清单哈希文件到:{destPath}");
|
||||
}
|
||||
|
||||
// 拷贝静态版本文件
|
||||
@@ -55,7 +52,6 @@ namespace YooAsset.Editor
|
||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
|
||||
string destPath = $"{packageDirectory}/{YooAssetSettings.VersionFileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
UnityEngine.Debug.Log($"拷贝静态版本文件到:{destPath}");
|
||||
}
|
||||
|
||||
// 拷贝UnityManifest序列化文件
|
||||
@@ -63,7 +59,6 @@ namespace YooAsset.Editor
|
||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
|
||||
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
UnityEngine.Debug.Log($"拷贝UnityManifest文件到:{destPath}");
|
||||
}
|
||||
|
||||
// 拷贝UnityManifest文本文件
|
||||
@@ -82,7 +77,6 @@ namespace YooAsset.Editor
|
||||
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}";
|
||||
string destPath = $"{packageDirectory}/{patchBundle.Hash}";
|
||||
EditorTools.CopyFile(sourcePath, destPath, true);
|
||||
UnityEngine.Debug.Log($"拷贝补丁文件到补丁包:{patchBundle.BundleName}");
|
||||
EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
@@ -1,50 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建报告文件
|
||||
/// </summary>
|
||||
[TaskAttribute("创建构建报告文件")]
|
||||
public class TaskCreateReport : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||
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)
|
||||
{
|
||||
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion);
|
||||
BuildReport buildReport = new BuildReport();
|
||||
buildParameters.StopWatch();
|
||||
BuildReport buildReport = new BuildReport();
|
||||
|
||||
// 概述信息
|
||||
{
|
||||
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
|
||||
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.BuildMode = buildParameters.Parameters.BuildMode;
|
||||
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.AutoCollectShaders = AssetBundleGrouperSettingData.Setting.AutoCollectShaders;
|
||||
buildReport.Summary.ShadersBundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName;
|
||||
buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
|
||||
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
|
||||
buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ?
|
||||
"null" : buildParameters.Parameters.EncryptionServices.GetType().FullName;
|
||||
|
||||
// 构建参数
|
||||
buildReport.Summary.DryRunBuild = buildParameters.Parameters.DryRunBuild;
|
||||
buildReport.Summary.ForceRebuild = buildParameters.Parameters.ForceRebuild;
|
||||
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption;
|
||||
buildReport.Summary.AppendHash = buildParameters.Parameters.AppendHash;
|
||||
buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree;
|
||||
buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges;
|
||||
buildReport.Summary.DisableLoadAssetByFileName = buildParameters.Parameters.DisableLoadAssetByFileName;
|
||||
|
||||
// 构建结果
|
||||
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
|
||||
@@ -64,8 +70,12 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var mainBundle = patchManifest.BundleList[patchAsset.BundleID];
|
||||
ReportAssetInfo reportAssetInfo = new ReportAssetInfo();
|
||||
reportAssetInfo.Address = patchAsset.Address;
|
||||
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.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, patchAsset.AssetPath);
|
||||
buildReport.AssetInfos.Add(reportAssetInfo);
|
||||
@@ -86,12 +96,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 删除旧文件
|
||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.ReportFileName}";
|
||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion)}";
|
||||
if (File.Exists(filePath))
|
||||
File.Delete(filePath);
|
||||
|
||||
// 序列化文件
|
||||
BuildReport.Serialize(filePath, buildReport);
|
||||
BuildRunner.Log($"资源构建报告文件创建完成:{filePath}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("资源包加密")]
|
||||
public class TaskEncryption : IBuildTask
|
||||
{
|
||||
public class EncryptionContext : IContextObject
|
||||
@@ -26,16 +27,17 @@ namespace YooAsset.Editor
|
||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
|
||||
if (buildParameters.Parameters.DryRunBuild)
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
EncryptionContext encryptionContext = new EncryptionContext();
|
||||
encryptionContext.EncryptList = new List<string>();
|
||||
encryptionContext.EncryptList = EncryptFiles(buildParameters, buildMapContext);
|
||||
context.SetContextObject(encryptionContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
EncryptionContext encryptionContext = new EncryptionContext();
|
||||
encryptionContext.EncryptList = EncryptFiles(buildParameters, buildMapContext);
|
||||
encryptionContext.EncryptList = new List<string>();
|
||||
context.SetContextObject(encryptionContext);
|
||||
}
|
||||
}
|
||||
@@ -54,7 +56,6 @@ namespace YooAsset.Editor
|
||||
if (encryptionServices == null)
|
||||
return encryptList;
|
||||
|
||||
UnityEngine.Debug.Log($"开始加密资源文件");
|
||||
int progressValue = 0;
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
@@ -75,7 +76,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
byte[] bytes = encryptionServices.Encrypt(fileData);
|
||||
File.WriteAllBytes(filePath, bytes);
|
||||
UnityEngine.Debug.Log($"文件加密完成:{filePath}");
|
||||
BuildRunner.Log($"文件加密完成:{filePath}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +85,8 @@ namespace YooAsset.Editor
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
if(encryptList.Count == 0)
|
||||
UnityEngine.Debug.LogWarning($"没有发现需要加密的文件!");
|
||||
return encryptList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,15 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("获取资源构建内容")]
|
||||
public class TaskGetBuildMap : IBuildTask
|
||||
{
|
||||
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);
|
||||
BuildRunner.Log("构建内容准备完毕!");
|
||||
|
||||
// 检测构建结果
|
||||
CheckBuildMapContent(buildMapContext);
|
||||
@@ -30,7 +33,7 @@ namespace YooAsset.Editor
|
||||
if (isRawFile)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("资源构建准备工作")]
|
||||
public class TaskPrepare : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
@@ -26,7 +27,8 @@ namespace YooAsset.Editor
|
||||
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)
|
||||
@@ -49,20 +51,20 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 如果是强制重建
|
||||
if (buildParameters.Parameters.ForceRebuild)
|
||||
if (buildMode == EBuildMode.ForceRebuild)
|
||||
{
|
||||
// 删除平台总目录
|
||||
string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}";
|
||||
if (EditorTools.DeleteDirectory(platformDirectory))
|
||||
{
|
||||
UnityEngine.Debug.Log($"删除平台总目录:{platformDirectory}");
|
||||
BuildRunner.Log($"删除平台总目录:{platformDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
// 如果输出目录不存在
|
||||
if (EditorTools.CreateDirectory(buildParameters.PipelineOutputDirectory))
|
||||
{
|
||||
UnityEngine.Debug.Log($"创建输出目录:{buildParameters.PipelineOutputDirectory}");
|
||||
BuildRunner.Log($"创建输出目录:{buildParameters.PipelineOutputDirectory}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,21 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("验证构建结果")]
|
||||
public class TaskVerifyBuildResult : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||
var unityManifestContext = context.GetContextObject<TaskBuilding.UnityManifestContext>();
|
||||
|
||||
// 模拟构建模式下跳过验证
|
||||
if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
return;
|
||||
|
||||
// 验证构建结果
|
||||
if (buildParametersContext.Parameters.VerifyBuildingResult)
|
||||
{
|
||||
var unityManifestContext = context.GetContextObject<TaskBuilding.UnityManifestContext>();
|
||||
VerifyingBuildingResult(context, unityManifestContext.UnityManifest);
|
||||
}
|
||||
}
|
||||
@@ -79,7 +84,8 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 5. 验证Asset
|
||||
if(buildParameters.Parameters.DryRunBuild == false)
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
int progressValue = 0;
|
||||
foreach (var buildedBundle in buildedBundles)
|
||||
@@ -132,7 +138,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 卸载所有加载的Bundle
|
||||
Debug.Log("构建结果验证成功!");
|
||||
BuildRunner.Log("构建结果验证成功!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
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
|
||||
{
|
||||
[Serializable]
|
||||
public class AssetBundleGrouper
|
||||
public class AssetBundleCollectorGroup
|
||||
{
|
||||
/// <summary>
|
||||
/// 分组名称
|
||||
/// </summary>
|
||||
public string GrouperName = string.Empty;
|
||||
public string GroupName = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 分组描述
|
||||
/// </summary>
|
||||
public string GrouperDesc = string.Empty;
|
||||
public string GroupDesc = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 资源分类标签
|
||||
@@ -36,7 +36,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public void CheckConfigError()
|
||||
{
|
||||
foreach(var collector in Collectors)
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
collector.CheckConfigError();
|
||||
}
|
||||
@@ -48,21 +48,38 @@ namespace YooAsset.Editor
|
||||
public List<CollectAssetInfo> GetAllCollectAssets()
|
||||
{
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
|
||||
foreach(var collector in Collectors)
|
||||
|
||||
// 收集打包资源
|
||||
foreach (var collector in Collectors)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,11 @@ using UnityEditor;
|
||||
|
||||
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, IPackRule> _cachePackRuleInstance = new Dictionary<string, IPackRule>();
|
||||
|
||||
@@ -21,8 +24,8 @@ namespace YooAsset.Editor
|
||||
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
|
||||
{
|
||||
@@ -32,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()
|
||||
{
|
||||
if (_setting == null)
|
||||
@@ -56,6 +71,15 @@ namespace YooAsset.Editor
|
||||
}
|
||||
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)
|
||||
{
|
||||
foreach (var pair in _cachePackRuleTypes)
|
||||
@@ -75,26 +99,13 @@ namespace YooAsset.Editor
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载配置文件
|
||||
/// </summary>
|
||||
private static void LoadSettingData()
|
||||
{
|
||||
// 加载配置文件
|
||||
_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");
|
||||
}
|
||||
_setting = YooAssetEditorSettingsHelper.LoadSettingData<AssetBundleCollectorSetting>();
|
||||
|
||||
// IPackRule
|
||||
{
|
||||
@@ -107,13 +118,13 @@ namespace YooAsset.Editor
|
||||
{
|
||||
typeof(PackSeparately),
|
||||
typeof(PackDirectory),
|
||||
typeof(PackTopDirectory),
|
||||
typeof(PackCollector),
|
||||
typeof(PackGrouper),
|
||||
typeof(PackGroup),
|
||||
typeof(PackRawFile),
|
||||
};
|
||||
|
||||
TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom<IPackRule>();
|
||||
var customTypes = collection.ToList();
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
@@ -138,8 +149,7 @@ namespace YooAsset.Editor
|
||||
typeof(CollectSprite)
|
||||
};
|
||||
|
||||
TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom<IFilterRule>();
|
||||
var customTypes = collection.ToList();
|
||||
var customTypes = EditorTools.GetAssignableTypes(typeof(IFilterRule));
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
@@ -148,6 +158,30 @@ namespace YooAsset.Editor
|
||||
_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>
|
||||
@@ -160,7 +194,7 @@ namespace YooAsset.Editor
|
||||
IsDirty = false;
|
||||
EditorUtility.SetDirty(Setting);
|
||||
AssetDatabase.SaveAssets();
|
||||
Debug.Log($"{nameof(AssetBundleGrouperSetting)}.asset is saved!");
|
||||
Debug.Log($"{nameof(AssetBundleCollectorSetting)}.asset is saved!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,11 +205,28 @@ namespace YooAsset.Editor
|
||||
{
|
||||
Setting.AutoCollectShaders = false;
|
||||
Setting.ShadersBundleName = string.Empty;
|
||||
Setting.Groupers.Clear();
|
||||
Setting.Groups.Clear();
|
||||
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)
|
||||
{
|
||||
if (_cachePackRuleInstance.TryGetValue(ruleName, out IPackRule instance))
|
||||
@@ -211,6 +262,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
// 可寻址编辑相关
|
||||
public static void ModifyAddressable(bool enableAddressable)
|
||||
{
|
||||
Setting.EnableAddressable = enableAddressable;
|
||||
IsDirty = true;
|
||||
}
|
||||
|
||||
// 着色器编辑相关
|
||||
public static void ModifyShader(bool isCollectAllShaders, string shadersBundleName)
|
||||
{
|
||||
@@ -220,48 +278,43 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 资源分组编辑相关
|
||||
public static void CreateGrouper(string grouperName, string grouperDesc, string assetTags)
|
||||
public static void CreateGroup(string groupName)
|
||||
{
|
||||
AssetBundleGrouper grouper = new AssetBundleGrouper();
|
||||
grouper.GrouperName = grouperName;
|
||||
grouper.GrouperDesc = grouperDesc;
|
||||
grouper.AssetTags = assetTags;
|
||||
Setting.Groupers.Add(grouper);
|
||||
AssetBundleCollectorGroup group = new AssetBundleCollectorGroup();
|
||||
group.GroupName = groupName;
|
||||
Setting.Groups.Add(group);
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void RemoveGrouper(AssetBundleGrouper grouper)
|
||||
public static void RemoveGroup(AssetBundleCollectorGroup group)
|
||||
{
|
||||
if (Setting.Groupers.Remove(grouper))
|
||||
if (Setting.Groups.Remove(group))
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Failed remove grouper : {grouper.GrouperName}");
|
||||
Debug.LogWarning($"Failed remove group : {group.GroupName}");
|
||||
}
|
||||
}
|
||||
public static void ModifyGrouper(AssetBundleGrouper grouper)
|
||||
public static void ModifyGroup(AssetBundleCollectorGroup group)
|
||||
{
|
||||
if (grouper != null)
|
||||
if (group != null)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 资源收集器编辑相关
|
||||
public static void CreateCollector(AssetBundleGrouper grouper, string collectPath, string packRuleName, string filterRuleName, bool notWriteToAssetList)
|
||||
public static void CreateCollector(AssetBundleCollectorGroup group, string collectPath)
|
||||
{
|
||||
AssetBundleCollector collector = new AssetBundleCollector();
|
||||
collector.CollectPath = collectPath;
|
||||
collector.PackRuleName = packRuleName;
|
||||
collector.FilterRuleName = filterRuleName;
|
||||
collector.NotWriteToAssetList = notWriteToAssetList;
|
||||
grouper.Collectors.Add(collector);
|
||||
group.Collectors.Add(collector);
|
||||
IsDirty = true;
|
||||
}
|
||||
public static void RemoveCollector(AssetBundleGrouper grouper, AssetBundleCollector collector)
|
||||
public static void RemoveCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||
{
|
||||
if (grouper.Collectors.Remove(collector))
|
||||
if (group.Collectors.Remove(collector))
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
@@ -270,9 +323,9 @@ namespace YooAsset.Editor
|
||||
Debug.LogWarning($"Failed remove collector : {collector.CollectPath}");
|
||||
}
|
||||
}
|
||||
public static void ModifyCollector(AssetBundleGrouper grouper, AssetBundleCollector collector)
|
||||
public static void ModifyCollector(AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||
{
|
||||
if (grouper != null && collector != null)
|
||||
if (group != null && collector != null)
|
||||
{
|
||||
IsDirty = true;
|
||||
}
|
||||
@@ -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,26 +1,26 @@
|
||||
<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:ToolbarSearchField focusable="true" name="SearchField" style="width: 300px; flex-grow: 1;" />
|
||||
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
|
||||
<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);" />
|
||||
</uie:Toolbar>
|
||||
<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:ListView focusable="true" name="GrouperListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||
<ui:VisualElement name="GrouperAddContainer" style="height: 20px; flex-direction: row; justify-content: center;">
|
||||
<ui:ListView focusable="true" name="GroupListView" item-height="20" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||
<ui:VisualElement name="GroupAddContainer" style="height: 20px; flex-direction: row; justify-content: center;">
|
||||
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
|
||||
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
<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:TextField picking-mode="Ignore" label="Shader Bundle Name" name="ShaderBundleName" style="flex-grow: 1; -unity-text-align: middle-left;" />
|
||||
</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:TextField picking-mode="Ignore" label="Grouper Name" name="GrouperName" />
|
||||
<ui:TextField picking-mode="Ignore" label="Grouper Desc" name="GrouperDesc" />
|
||||
<ui:TextField picking-mode="Ignore" label="Grouper Asset Tags" name="GrouperAssetTags" />
|
||||
<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="Group Name" name="GroupName" />
|
||||
<ui:TextField picking-mode="Ignore" label="Group Desc" name="GroupDesc" />
|
||||
<ui:TextField picking-mode="Ignore" label="Group Asset Tags" name="GroupAssetTags" />
|
||||
<ui:VisualElement name="CollectorAddContainer" style="height: 20px; flex-direction: row-reverse;">
|
||||
<ui:Button text="[ + ]" display-tooltip-when-elided="true" name="AddBtn" />
|
||||
</ui:VisualElement>
|
||||
@@ -5,11 +5,21 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class CollectAssetInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集器类型
|
||||
/// </summary>
|
||||
public ECollectorType CollectorType { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// </summary>
|
||||
public string BundleName { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 可寻址地址
|
||||
/// </summary>
|
||||
public string Address { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源路径
|
||||
/// </summary>
|
||||
@@ -25,32 +35,20 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IsRawAsset { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 不写入资源列表
|
||||
/// </summary>
|
||||
public bool NotWriteToAssetList { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 依赖的资源列表
|
||||
/// </summary>
|
||||
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;
|
||||
Address = address;
|
||||
AssetPath = assetPath;
|
||||
AssetTags = assetTags;
|
||||
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>
|
||||
/// 以文件路径作为资源包名
|
||||
/// 注意:每个文件独自打资源包
|
||||
/// 例如:收集器路径为 "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>
|
||||
public class PackSeparately : IPackRule
|
||||
{
|
||||
string IPackRule.GetBundleName(PackRuleData data)
|
||||
{
|
||||
return StringUtility.RemoveExtension(data.AssetPath); //"Assets/Config/test.txt" --> "Assets/Config/test"
|
||||
return StringUtility.RemoveExtension(data.AssetPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public class PackDirectory : IPackRule
|
||||
{
|
||||
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>
|
||||
public class PackCollector : IPackRule
|
||||
{
|
||||
@@ -42,13 +76,13 @@ namespace YooAsset.Editor
|
||||
|
||||
/// <summary>
|
||||
/// 以分组名称作为资源包名
|
||||
/// 注意:分组内所有文件打进一个资源包
|
||||
/// 注意:收集的所有文件打进一个资源包
|
||||
/// </summary>
|
||||
public class PackGrouper : IPackRule
|
||||
public class PackGroup : IPackRule
|
||||
{
|
||||
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 CollectPath;
|
||||
public string GrouperName;
|
||||
public string GroupName;
|
||||
|
||||
public PackRuleData(string assetPath)
|
||||
{
|
||||
AssetPath = assetPath;
|
||||
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;
|
||||
CollectPath = collectPath;
|
||||
GrouperName = grouperName;
|
||||
GroupName = groupName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
@@ -11,8 +12,7 @@ namespace YooAsset.Editor
|
||||
[MenuItem("YooAsset/AssetBundle Debugger", false, 104)]
|
||||
public static void ShowExample()
|
||||
{
|
||||
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>();
|
||||
wnd.titleContent = new GUIContent("资源包调试工具");
|
||||
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>("资源包调试工具", true, EditorDefine.DockedWindowTypes);
|
||||
wnd.minSize = new Vector2(800, 600);
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
private ToolbarMenu _viewModeMenu;
|
||||
private AssetListDebuggerViewer _assetListViewer;
|
||||
private BundleListDebuggerViewer _bundleListViewer;
|
||||
private DebuggerAssetListViewer _assetListViewer;
|
||||
private DebuggerBundleListViewer _bundleListViewer;
|
||||
|
||||
private EViewMode _viewMode;
|
||||
private readonly DebugReport _debugReport = new DebugReport();
|
||||
@@ -48,45 +48,50 @@ namespace YooAsset.Editor
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
VisualElement root = rootVisualElement;
|
||||
try
|
||||
{
|
||||
VisualElement root = rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetPath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/{nameof(AssetBundleDebuggerWindow)}.uxml";
|
||||
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
if (visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleDebuggerWindow)}.uxml : {uxml}");
|
||||
return;
|
||||
// 加载布局文件
|
||||
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleDebuggerUXML;
|
||||
if (visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleDebuggerWindow)}.uxml in settings.");
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||
<uie:Toolbar name="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: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>
|
||||
</ui:UXML>
|
||||
|
||||
@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class AssetListDebuggerViewer
|
||||
internal class DebuggerAssetListViewer
|
||||
{
|
||||
private VisualTreeAsset _visualAsset;
|
||||
private TemplateContainer _root;
|
||||
@@ -23,13 +23,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetPath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(AssetListDebuggerViewer)}.uxml";
|
||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
// 加载布局文件
|
||||
_visualAsset = YooAssetEditorSettingsData.Setting.DebuggerAssetListViewerUXML;
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetListDebuggerViewer)}.uxml : {uxml}");
|
||||
Debug.LogError($"Not found {nameof(DebuggerAssetListViewer)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
_root = _visualAsset.CloneTree();
|
||||
@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class BundleListDebuggerViewer
|
||||
internal class DebuggerBundleListViewer
|
||||
{
|
||||
private VisualTreeAsset _visualAsset;
|
||||
private TemplateContainer _root;
|
||||
@@ -24,12 +24,10 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetPath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(BundleListDebuggerViewer)}.uxml";
|
||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
_visualAsset = YooAssetEditorSettingsData.Setting.DebuggerBundleListViewerUXML;
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(BundleListDebuggerViewer)}.uxml : {uxml}");
|
||||
Debug.LogError($"Not found {nameof(DebuggerBundleListViewer)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
_root = _visualAsset.CloneTree();
|
||||
@@ -1,217 +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;
|
||||
|
||||
[NonSerialized]
|
||||
public object UserData;
|
||||
|
||||
|
||||
/// <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);
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(assetPath);
|
||||
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" || ext == ".cginc")
|
||||
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)
|
||||
{
|
||||
string shaderBundleName = CollectShaderBundleName(assetPath);
|
||||
if (string.IsNullOrEmpty(shaderBundleName) == false)
|
||||
return shaderBundleName;
|
||||
|
||||
// 根据规则设置获取资源包名称
|
||||
{
|
||||
IPackRule packRuleInstance = AssetBundleGrouperSettingData.GetPackRuleInstance(PackRuleName);
|
||||
string bundleName = packRuleInstance.GetBundleName(new PackRuleData(assetPath, CollectPath, grouper.GrouperName));
|
||||
return CorrectBundleName(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 CollectShaderBundleName(string assetPath)
|
||||
{
|
||||
// 如果自动收集所有的着色器
|
||||
if (AssetBundleGrouperSettingData.Setting.AutoCollectShaders)
|
||||
{
|
||||
System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
|
||||
if (assetType == typeof(UnityEngine.Shader))
|
||||
{
|
||||
string bundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName;
|
||||
return CorrectBundleName(bundleName, false);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修正资源包名称
|
||||
/// </summary>
|
||||
public static string CorrectBundleName(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,457 +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 ScrollView _collectorScrollView;
|
||||
private Toggle _autoCollectShaderToogle;
|
||||
private TextField _shaderBundleNameTxt;
|
||||
private TextField _grouperNameTxt;
|
||||
private TextField _grouperDescTxt;
|
||||
private TextField _grouperAssetTagsTxt;
|
||||
private VisualElement _grouperContainer;
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
Undo.undoRedoPerformed -= RefreshWindow;
|
||||
Undo.undoRedoPerformed += RefreshWindow;
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
// 收集列表相关
|
||||
_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 (AssetBundleGrouperSettingData.IsDirty)
|
||||
AssetBundleGrouperSettingData.SaveFile();
|
||||
}
|
||||
|
||||
// 刷新窗体
|
||||
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;
|
||||
_grouperListView.Rebuild();
|
||||
}
|
||||
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()
|
||||
{
|
||||
Undo.RecordObject(AssetBundleGrouperSettingData.Setting, "YooAsset AddGrouper");
|
||||
AssetBundleGrouperSettingData.CreateGrouper("Default Grouper", string.Empty, string.Empty);
|
||||
FillGrouperViewData();
|
||||
}
|
||||
private void RemoveGrouperBtn_clicked()
|
||||
{
|
||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
||||
if (selectGrouper == null)
|
||||
return;
|
||||
|
||||
Undo.RecordObject(AssetBundleGrouperSettingData.Setting, "YooAsset RemoveGrouper");
|
||||
|
||||
AssetBundleGrouperSettingData.RemoveGrouper(selectGrouper);
|
||||
FillGrouperViewData();
|
||||
}
|
||||
|
||||
// 收集列表相关
|
||||
private void FillCollectorViewData()
|
||||
{
|
||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
||||
if (selectGrouper == null)
|
||||
{
|
||||
_grouperContainer.visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_grouperContainer.visible = true;
|
||||
_grouperNameTxt.SetValueWithoutNotify(selectGrouper.GrouperName);
|
||||
_grouperDescTxt.SetValueWithoutNotify(selectGrouper.GrouperDesc);
|
||||
_grouperAssetTagsTxt.SetValueWithoutNotify(selectGrouper.AssetTags);
|
||||
|
||||
// 填充数据
|
||||
_collectorScrollView.Clear();
|
||||
for (int i = 0; i < selectGrouper.Collectors.Count; i++)
|
||||
{
|
||||
var collector = selectGrouper.Collectors[i];
|
||||
VisualElement element = MakeCollectorListViewItem();
|
||||
collector.UserData = element;
|
||||
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 elementFold = new VisualElement();
|
||||
elementFold.style.flexDirection = FlexDirection.Row;
|
||||
element.Add(elementFold);
|
||||
|
||||
// Top VisualElement
|
||||
{
|
||||
var objectField = new ObjectField();
|
||||
objectField.name = "ObjectField1";
|
||||
objectField.label = "Collecter";
|
||||
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;
|
||||
}
|
||||
{
|
||||
var button = new Button();
|
||||
button.name = "Button1";
|
||||
button.text = "[ - ]";
|
||||
button.style.unityTextAlign = TextAnchor.MiddleCenter;
|
||||
button.style.flexGrow = 0f;
|
||||
elementTop.Add(button);
|
||||
}
|
||||
|
||||
// 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];
|
||||
collector.UserData = element;
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
// Remove Button
|
||||
var removeBtn = element.Q<Button>("Button1");
|
||||
removeBtn.clicked += ()=>
|
||||
{
|
||||
RemoveCollectorBtn_clicked(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 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(AssetBundleCollector selectCollector)
|
||||
{
|
||||
var selectGrouper = _grouperListView.selectedItem as AssetBundleGrouper;
|
||||
if (selectGrouper == null)
|
||||
return;
|
||||
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
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
@@ -11,8 +12,7 @@ namespace YooAsset.Editor
|
||||
[MenuItem("YooAsset/AssetBundle Reporter", false, 103)]
|
||||
public static void ShowExample()
|
||||
{
|
||||
AssetBundleReporterWindow window = GetWindow<AssetBundleReporterWindow>();
|
||||
window.titleContent = new GUIContent("资源包报告工具");
|
||||
AssetBundleReporterWindow window = GetWindow<AssetBundleReporterWindow>("资源包报告工具", true, EditorDefine.DockedWindowTypes);
|
||||
window.minSize = new Vector2(800, 600);
|
||||
}
|
||||
|
||||
@@ -38,60 +38,70 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
private ToolbarMenu _viewModeMenu;
|
||||
private SummaryReporterViewer _summaryViewer;
|
||||
private AssetListReporterViewer _assetListViewer;
|
||||
private BundleListReporterViewer _bundleListViewer;
|
||||
private ReporterSummaryViewer _summaryViewer;
|
||||
private ReporterAssetListViewer _assetListViewer;
|
||||
private ReporterBundleListViewer _bundleListViewer;
|
||||
|
||||
private EViewMode _viewMode;
|
||||
private string _searchKeyWord;
|
||||
private BuildReport _buildReport;
|
||||
private string _reportFilePath;
|
||||
private string _searchKeyWord;
|
||||
|
||||
|
||||
public void CreateGUI()
|
||||
{
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetPath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleReporter/{nameof(AssetBundleReporterWindow)}.uxml";
|
||||
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
if (visualAsset == null)
|
||||
try
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml : {uxml}");
|
||||
return;
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
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);
|
||||
|
||||
// 导入按钮
|
||||
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 SummaryReporterViewer();
|
||||
_summaryViewer.InitViewer();
|
||||
|
||||
// 加载视图
|
||||
_assetListViewer = new AssetListReporterViewer();
|
||||
_assetListViewer.InitViewer();
|
||||
|
||||
// 加载视图
|
||||
_bundleListViewer = new BundleListReporterViewer();
|
||||
_bundleListViewer.InitViewer();
|
||||
|
||||
// 显示视图
|
||||
_viewMode = EViewMode.Summary;
|
||||
_viewModeMenu.text = EViewMode.Summary.ToString();
|
||||
_summaryViewer.AttachParent(root);
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
}
|
||||
public void OnDestroy()
|
||||
{
|
||||
AssetBundleRecorder.UnloadAll();
|
||||
}
|
||||
|
||||
private void ImportBtn_onClick()
|
||||
@@ -100,19 +110,20 @@ namespace YooAsset.Editor
|
||||
if (string.IsNullOrEmpty(selectFilePath))
|
||||
return;
|
||||
|
||||
string jsonData = FileUtility.ReadFile(selectFilePath);
|
||||
_reportFilePath = selectFilePath;
|
||||
string jsonData = FileUtility.ReadFile(_reportFilePath);
|
||||
_buildReport = BuildReport.Deserialize(jsonData);
|
||||
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
|
||||
_summaryViewer.FillViewData(_buildReport);
|
||||
}
|
||||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||
{
|
||||
_searchKeyWord = e.newValue;
|
||||
if(_buildReport != null)
|
||||
if (_buildReport != null)
|
||||
{
|
||||
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord);
|
||||
}
|
||||
}
|
||||
private void ViewModeMenuAction0(DropdownMenuAction action)
|
||||
|
||||
@@ -1,290 +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.ClearSelection();
|
||||
_bundleListView.itemsSource = FilterViewItems(buildReport, searchKeyWord);
|
||||
_bundleListView.Rebuild();
|
||||
_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 = 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 = (bundleInfo.SizeBytes / 1024f).ToString("f1") + " KB";
|
||||
|
||||
// Hash
|
||||
var label3 = element.Q<Label>("Label3");
|
||||
label3.text = bundleInfo.Hash;
|
||||
|
||||
// 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;
|
||||
_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;
|
||||
//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 = 280;
|
||||
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
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
@@ -9,20 +9,28 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class AssetListReporterViewer
|
||||
internal class ReporterAssetListViewer
|
||||
{
|
||||
private enum ESortMode
|
||||
{
|
||||
AssetPath,
|
||||
BundleName
|
||||
}
|
||||
|
||||
private VisualTreeAsset _visualAsset;
|
||||
private TemplateContainer _root;
|
||||
|
||||
private ToolbarButton _topBar1;
|
||||
private ToolbarButton _topBar2;
|
||||
private ToolbarButton _topBar3;
|
||||
private ToolbarButton _bottomBar1;
|
||||
private ToolbarButton _bottomBar2;
|
||||
private ToolbarButton _bottomBar3;
|
||||
private ListView _assetListView;
|
||||
private ListView _dependListView;
|
||||
|
||||
private BuildReport _buildReport;
|
||||
private string _searchKeyWord;
|
||||
private ESortMode _sortMode = ESortMode.AssetPath;
|
||||
private bool _descendingSort = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 初始化页面
|
||||
@@ -30,44 +38,46 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetPath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(AssetListReporterViewer)}.uxml";
|
||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterAssetListViewerUXML;
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(AssetListReporterViewer)}.uxml : {uxml}");
|
||||
Debug.LogError($"Not found {nameof(ReporterAssetListViewer)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
// 顶部按钮栏
|
||||
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
|
||||
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
|
||||
_topBar3 = _root.Q<ToolbarButton>("TopBar3");
|
||||
_topBar1.clicked += TopBar1_clicked;
|
||||
_topBar2.clicked += TopBar2_clicked;
|
||||
_topBar3.clicked += TopBar3_clicked;
|
||||
try
|
||||
{
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
// 底部按钮栏
|
||||
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
|
||||
_bottomBar2 = _root.Q<ToolbarButton>("BottomBar2");
|
||||
_bottomBar3 = _root.Q<ToolbarButton>("BottomBar3");
|
||||
|
||||
// 资源列表
|
||||
_assetListView = _root.Q<ListView>("TopListView");
|
||||
_assetListView.makeItem = MakeAssetListViewItem;
|
||||
_assetListView.bindItem = BindAssetListViewItem;
|
||||
// 顶部按钮栏
|
||||
_topBar1 = _root.Q<ToolbarButton>("TopBar1");
|
||||
_topBar2 = _root.Q<ToolbarButton>("TopBar2");
|
||||
_topBar1.clicked += TopBar1_clicked;
|
||||
_topBar2.clicked += TopBar2_clicked;
|
||||
|
||||
// 底部按钮栏
|
||||
_bottomBar1 = _root.Q<ToolbarButton>("BottomBar1");
|
||||
|
||||
// 资源列表
|
||||
_assetListView = _root.Q<ListView>("TopListView");
|
||||
_assetListView.makeItem = MakeAssetListViewItem;
|
||||
_assetListView.bindItem = BindAssetListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
|
||||
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
|
||||
#else
|
||||
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
|
||||
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
|
||||
#endif
|
||||
// 依赖列表
|
||||
_dependListView = _root.Q<ListView>("BottomListView");
|
||||
_dependListView.makeItem = MakeDependListViewItem;
|
||||
_dependListView.bindItem = BindDependListViewItem;
|
||||
|
||||
// 依赖列表
|
||||
_dependListView = _root.Q<ListView>("BottomListView");
|
||||
_dependListView.makeItem = MakeDependListViewItem;
|
||||
_dependListView.bindItem = BindDependListViewItem;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,25 +86,76 @@ namespace YooAsset.Editor
|
||||
public void FillViewData(BuildReport buildReport, string searchKeyWord)
|
||||
{
|
||||
_buildReport = buildReport;
|
||||
_searchKeyWord = searchKeyWord;
|
||||
RefreshView();
|
||||
}
|
||||
private void RefreshView()
|
||||
{
|
||||
_assetListView.Clear();
|
||||
_assetListView.ClearSelection();
|
||||
_assetListView.itemsSource = FilterViewItems(buildReport, searchKeyWord);
|
||||
_assetListView.itemsSource = FilterAndSortViewItems();
|
||||
_assetListView.Rebuild();
|
||||
_topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count})";
|
||||
RefreshSortingSymbol();
|
||||
}
|
||||
private List<ReportAssetInfo> FilterViewItems(BuildReport buildReport, string searchKeyWord)
|
||||
private List<ReportAssetInfo> FilterAndSortViewItems()
|
||||
{
|
||||
List<ReportAssetInfo> result = new List<ReportAssetInfo>(buildReport.AssetInfos.Count);
|
||||
foreach (var assetInfo in buildReport.AssetInfos)
|
||||
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)
|
||||
continue;
|
||||
if (assetInfo.AssetPath.Contains(_searchKeyWord) == false)
|
||||
continue;
|
||||
}
|
||||
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>
|
||||
@@ -135,18 +196,8 @@ namespace YooAsset.Editor
|
||||
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 = 145;
|
||||
label.style.width = 150;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
@@ -156,19 +207,15 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var sourceData = _assetListView.itemsSource as List<ReportAssetInfo>;
|
||||
var assetInfo = sourceData[index];
|
||||
var bundleInfo = _buildReport.GetBundleInfo(assetInfo.MainBundle);
|
||||
var bundleInfo = _buildReport.GetBundleInfo(assetInfo.MainBundleName);
|
||||
|
||||
// Asset Path
|
||||
var label1 = element.Q<Label>("Label1");
|
||||
label1.text = assetInfo.AssetPath;
|
||||
|
||||
// Size
|
||||
var label2 = element.Q<Label>("Label2");
|
||||
label2.text = GetAssetFileSize(assetInfo.AssetPath);
|
||||
|
||||
// Main Bundle
|
||||
var label3 = element.Q<Label>("Label3");
|
||||
label3.text = bundleInfo.BundleName;
|
||||
var label2 = element.Q<Label>("Label2");
|
||||
label2.text = bundleInfo.BundleName;
|
||||
}
|
||||
private void AssetListView_onSelectionChange(IEnumerable<object> objs)
|
||||
{
|
||||
@@ -179,22 +226,41 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
private void TopBar1_clicked()
|
||||
{
|
||||
{
|
||||
if (_sortMode != ESortMode.AssetPath)
|
||||
{
|
||||
_sortMode = ESortMode.AssetPath;
|
||||
_descendingSort = false;
|
||||
RefreshView();
|
||||
}
|
||||
else
|
||||
{
|
||||
_descendingSort = !_descendingSort;
|
||||
RefreshView();
|
||||
}
|
||||
}
|
||||
private void TopBar2_clicked()
|
||||
{
|
||||
}
|
||||
private void TopBar3_clicked()
|
||||
{
|
||||
if (_sortMode != ESortMode.BundleName)
|
||||
{
|
||||
_sortMode = ESortMode.BundleName;
|
||||
_descendingSort = false;
|
||||
RefreshView();
|
||||
}
|
||||
else
|
||||
{
|
||||
_descendingSort = !_descendingSort;
|
||||
RefreshView();
|
||||
}
|
||||
}
|
||||
|
||||
// 依赖列表相关
|
||||
private void FillDependListView(ReportAssetInfo assetInfo)
|
||||
{
|
||||
List<ReportBundleInfo> bundles = new List<ReportBundleInfo>();
|
||||
var mainBundle = _buildReport.GetBundleInfo(assetInfo.MainBundle);
|
||||
var mainBundle = _buildReport.GetBundleInfo(assetInfo.MainBundleName);
|
||||
bundles.Add(mainBundle);
|
||||
foreach(string dependBundleName in assetInfo.DependBundles)
|
||||
foreach (string dependBundleName in assetInfo.DependBundles)
|
||||
{
|
||||
var dependBundle = _buildReport.GetBundleInfo(dependBundleName);
|
||||
bundles.Add(dependBundle);
|
||||
@@ -254,21 +320,12 @@ namespace YooAsset.Editor
|
||||
|
||||
// Size
|
||||
var label2 = element.Q<Label>("Label2");
|
||||
label2.text = (bundleInfo.SizeBytes / 1024f).ToString("f1") + " KB";
|
||||
label2.text = EditorUtility.FormatBytes(bundleInfo.SizeBytes);
|
||||
|
||||
// Hash
|
||||
var label3 = element.Q<Label>("Label3");
|
||||
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
|
||||
@@ -2,8 +2,7 @@
|
||||
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
|
||||
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
|
||||
<uie:ToolbarButton text="Asset Path" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="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="TopBar3" style="width: 145px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="Main Bundle" display-tooltip-when-elided="true" name="TopBar2" style="width: 145px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
</uie:Toolbar>
|
||||
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||
</ui:VisualElement>
|
||||
@@ -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
|
||||
@@ -5,15 +5,14 @@
|
||||
<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="Size" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
|
||||
<uie:ToolbarButton text="Hash" display-tooltip-when-elided="true" name="TopBar3" style="width: 280px; -unity-text-align: middle-left;" />
|
||||
<uie:ToolbarButton text="Tags" display-tooltip-when-elided="true" name="TopBar5" style="width: 80px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="Tags" display-tooltip-when-elided="true" name="TopBar4" style="width: 80px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
</uie:Toolbar>
|
||||
<ui:ListView focusable="true" name="TopListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="BottomGroup" style="height: 200px; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 1px; margin-bottom: 1px; display: flex;">
|
||||
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
|
||||
<uie:ToolbarButton text="Include Assets" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="Size" display-tooltip-when-elided="true" name="BottomBar2" style="width: 100px; -unity-text-align: middle-left;" />
|
||||
<uie:ToolbarButton text="GUID" display-tooltip-when-elided="true" name="BottomBar3" style="width: 280px; -unity-text-align: middle-left;" />
|
||||
<uie:ToolbarButton text="GUID" display-tooltip-when-elided="true" name="BottomBar2" style="width: 280px; -unity-text-align: middle-left;" />
|
||||
</uie:Toolbar>
|
||||
<ui:ListView focusable="true" name="BottomListView" item-height="18" virtualization-method="DynamicHeight" style="flex-grow: 1;" />
|
||||
</ui:VisualElement>
|
||||
@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class SummaryReporterViewer
|
||||
internal class ReporterSummaryViewer
|
||||
{
|
||||
private class ItemWrapper
|
||||
{
|
||||
@@ -37,12 +37,10 @@ namespace YooAsset.Editor
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetPath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(SummaryReporterViewer)}.uxml";
|
||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterSummaryViewerUXML;
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(SummaryReporterViewer)}.uxml : {uxml}");
|
||||
Debug.LogError($"Not found {nameof(ReporterSummaryViewer)}.uxml in settings.");
|
||||
return;
|
||||
}
|
||||
_root = _visualAsset.CloneTree();
|
||||
@@ -66,8 +64,11 @@ namespace YooAsset.Editor
|
||||
_items.Add(new ItemWrapper("构建时间", buildReport.Summary.BuildTime));
|
||||
_items.Add(new ItemWrapper("构建耗时", $"{buildReport.Summary.BuildSeconds}秒"));
|
||||
_items.Add(new ItemWrapper("构建平台", $"{buildReport.Summary.BuildTarget}"));
|
||||
_items.Add(new ItemWrapper("构建模式", $"{buildReport.Summary.BuildMode}"));
|
||||
_items.Add(new ItemWrapper("构建版本", $"{buildReport.Summary.BuildVersion}"));
|
||||
_items.Add(new ItemWrapper("启用自动分包机制", $"{buildReport.Summary.EnableAutoCollect}"));
|
||||
_items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}"));
|
||||
|
||||
_items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}"));
|
||||
_items.Add(new ItemWrapper("追加文件扩展名", $"{buildReport.Summary.AppendFileExtension}"));
|
||||
_items.Add(new ItemWrapper("自动收集着色器", $"{buildReport.Summary.AutoCollectShaders}"));
|
||||
_items.Add(new ItemWrapper("着色器资源包名称", $"{buildReport.Summary.ShadersBundleName}"));
|
||||
@@ -75,14 +76,9 @@ namespace YooAsset.Editor
|
||||
|
||||
_items.Add(new ItemWrapper(string.Empty, string.Empty));
|
||||
_items.Add(new ItemWrapper("构建参数", string.Empty));
|
||||
_items.Add(new ItemWrapper("DryRunBuild", $"{buildReport.Summary.DryRunBuild}"));
|
||||
_items.Add(new ItemWrapper("ForceRebuild", $"{buildReport.Summary.ForceRebuild}"));
|
||||
_items.Add(new ItemWrapper("BuildinTags", $"{buildReport.Summary.BuildinTags}"));
|
||||
_items.Add(new ItemWrapper("CompressOption", $"{buildReport.Summary.CompressOption}"));
|
||||
_items.Add(new ItemWrapper("AppendHash", $"{buildReport.Summary.AppendHash}"));
|
||||
_items.Add(new ItemWrapper("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}"));
|
||||
_items.Add(new ItemWrapper("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}"));
|
||||
_items.Add(new ItemWrapper("DisableLoadAssetByFileName", $"{buildReport.Summary.DisableLoadAssetByFileName}"));
|
||||
|
||||
_items.Add(new ItemWrapper(string.Empty, string.Empty));
|
||||
_items.Add(new ItemWrapper("构建结果", string.Empty));
|
||||
@@ -1,17 +1,15 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class EditorDefine
|
||||
{
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
/// <summary>
|
||||
/// 资源包构建工具的配置文件存储路径
|
||||
/// 停靠窗口类型集合
|
||||
/// </summary>
|
||||
public const string AssetBundleBuilderSettingFilePath = "Assets/YooAssetSetting/AssetBundleBuilderSetting.asset";
|
||||
|
||||
/// <summary>
|
||||
/// 资源包分组工具的配置文件存储路径
|
||||
/// </summary>
|
||||
public const string AssetBundleGrouperSettingFilePath = "Assets/YooAssetSetting/AssetBundleGrouperSetting.asset";
|
||||
public static readonly Type[] DockedWindowTypes = { typeof(AssetBundleBuilderWindow), typeof(AssetBundleCollectorWindow), typeof(AssetBundleDebuggerWindow), typeof(AssetBundleReporterWindow)};
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,16 +41,16 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public enum EAssetFileExtension
|
||||
{
|
||||
prefab, //预制体
|
||||
unity, //场景
|
||||
fbx, //模型
|
||||
anim, //动画
|
||||
controller, //控制器
|
||||
png, //图片
|
||||
jpg, //图片
|
||||
mat, //材质球
|
||||
shader, //着色器
|
||||
ttf, //字体
|
||||
cs, //脚本
|
||||
prefab,
|
||||
unity,
|
||||
fbx,
|
||||
anim,
|
||||
controller,
|
||||
png,
|
||||
jpg,
|
||||
mat,
|
||||
shader,
|
||||
ttf,
|
||||
cs,
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
#if UNITY_2019
|
||||
public static partial class UnityEngine_UIElements_ListView_Extension
|
||||
{
|
||||
@@ -20,4 +21,5 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user