Compare commits

..

2 Commits

Author SHA1 Message Date
何冠峰 d9c911d89b update asset bundle reporter 2025-02-20 18:50:26 +08:00
何冠峰 a3ceb3dcb6 update asset bundle builder 2025-02-20 12:04:42 +08:00
17 changed files with 264 additions and 186 deletions

View File

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

View File

@ -53,7 +53,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 怀旧版依赖模式 /// 怀旧版依赖模式
/// 说明兼容YooAssets1.5.x版本 /// 说明兼容YooAsset1.5.x版本
/// </summary> /// </summary>
public bool LegacyDependency = false; public bool LegacyDependency = false;

View File

@ -18,11 +18,7 @@ namespace YooAsset.Editor
// 概述信息 // 概述信息
{ {
#if UNITY_2019_4_OR_NEWER buildReport.Summary.YooVersion = EditorTools.GetPackageManagerYooVersion();
UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(BuildReport).Assembly);
if (packageInfo != null)
buildReport.Summary.YooVersion = packageInfo.version;
#endif
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion; buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
buildReport.Summary.BuildDate = DateTime.Now.ToString(); buildReport.Summary.BuildDate = DateTime.Now.ToString();
buildReport.Summary.BuildSeconds = BuildRunner.TotalSeconds; buildReport.Summary.BuildSeconds = BuildRunner.TotalSeconds;
@ -38,37 +34,35 @@ namespace YooAsset.Editor
buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable; buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable;
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower; buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID; buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
buildReport.Summary.IgnoreRuleName = buildMapContext.Command.IgnoreRule.GetType().FullName;
buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders; buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
buildReport.Summary.IgnoreRuleName = buildMapContext.Command.IgnoreRule.GetType().FullName;
// 构建参数 // 构建参数
buildReport.Summary.LegacyDependency = buildParameters.LegacyDependency; buildReport.Summary.LegacyDependency = buildParameters.LegacyDependency;
buildReport.Summary.ClearBuildCacheFiles = buildParameters.ClearBuildCacheFiles; buildReport.Summary.ClearBuildCacheFiles = buildParameters.ClearBuildCacheFiles;
buildReport.Summary.UseAssetDependencyDB = buildParameters.UseAssetDependencyDB; buildReport.Summary.UseAssetDependencyDB = buildParameters.UseAssetDependencyDB;
buildReport.Summary.EnableSharePackRule = buildParameters.EnableSharePackRule; buildReport.Summary.EnableSharePackRule = buildParameters.EnableSharePackRule;
buildReport.Summary.SingleReferencedPackAlone = buildParameters.SingleReferencedPackAlone;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.EncryptionClassName = buildParameters.EncryptionServices == null ? "null" : buildParameters.EncryptionServices.GetType().FullName; buildReport.Summary.EncryptionClassName = buildParameters.EncryptionServices == null ? "null" : buildParameters.EncryptionServices.GetType().FullName;
if (buildParameters.BuildPipeline == nameof(BuiltinBuildPipeline)) if (buildParameters is BuiltinBuildParameters)
{ {
var builtinBuildParameters = buildParameters as BuiltinBuildParameters; var builtinBuildParameters = buildParameters as BuiltinBuildParameters;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.CompressOption = builtinBuildParameters.CompressOption; buildReport.Summary.CompressOption = builtinBuildParameters.CompressOption;
buildReport.Summary.DisableWriteTypeTree = builtinBuildParameters.DisableWriteTypeTree; buildReport.Summary.DisableWriteTypeTree = builtinBuildParameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = builtinBuildParameters.IgnoreTypeTreeChanges; buildReport.Summary.IgnoreTypeTreeChanges = builtinBuildParameters.IgnoreTypeTreeChanges;
} }
else if (buildParameters.BuildPipeline == nameof(ScriptableBuildPipeline)) else if (buildParameters is ScriptableBuildParameters)
{ {
var scriptableBuildParameters = buildParameters as ScriptableBuildParameters; var scriptableBuildParameters = buildParameters as ScriptableBuildParameters;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle;
buildReport.Summary.CompressOption = scriptableBuildParameters.CompressOption; buildReport.Summary.CompressOption = scriptableBuildParameters.CompressOption;
buildReport.Summary.DisableWriteTypeTree = scriptableBuildParameters.DisableWriteTypeTree; buildReport.Summary.DisableWriteTypeTree = scriptableBuildParameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = scriptableBuildParameters.IgnoreTypeTreeChanges; buildReport.Summary.IgnoreTypeTreeChanges = scriptableBuildParameters.IgnoreTypeTreeChanges;
} buildReport.Summary.WriteLinkXML = scriptableBuildParameters.WriteLinkXML;
else buildReport.Summary.CacheServerHost = scriptableBuildParameters.CacheServerHost;
{ buildReport.Summary.CacheServerPort = scriptableBuildParameters.CacheServerPort;
buildReport.Summary.FileNameStyle = buildParameters.FileNameStyle; buildReport.Summary.BuiltinShadersBundleName = scriptableBuildParameters.BuiltinShadersBundleName;
buildReport.Summary.CompressOption = ECompressOption.Uncompressed; buildReport.Summary.MonoScriptsBundleName = scriptableBuildParameters.MonoScriptsBundleName;
buildReport.Summary.DisableWriteTypeTree = false;
buildReport.Summary.IgnoreTypeTreeChanges = false;
} }
// 构建结果 // 构建结果
@ -92,7 +86,8 @@ namespace YooAsset.Editor
reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(packageAsset.AssetPath); reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(packageAsset.AssetPath);
reportAssetInfo.MainBundleName = mainBundle.BundleName; reportAssetInfo.MainBundleName = mainBundle.BundleName;
reportAssetInfo.MainBundleSize = mainBundle.FileSize; reportAssetInfo.MainBundleSize = mainBundle.FileSize;
reportAssetInfo.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, packageAsset.AssetPath); reportAssetInfo.DependAssets = GetAssetDependAssets(buildMapContext, mainBundle.BundleName, packageAsset.AssetPath);
reportAssetInfo.DependBundles = GetAssetDependBundles(manifest, packageAsset);
buildReport.AssetInfos.Add(reportAssetInfo); buildReport.AssetInfos.Add(reportAssetInfo);
} }
@ -108,8 +103,9 @@ namespace YooAsset.Editor
reportBundleInfo.FileSize = packageBundle.FileSize; reportBundleInfo.FileSize = packageBundle.FileSize;
reportBundleInfo.Encrypted = packageBundle.Encrypted; reportBundleInfo.Encrypted = packageBundle.Encrypted;
reportBundleInfo.Tags = packageBundle.Tags; reportBundleInfo.Tags = packageBundle.Tags;
reportBundleInfo.DependBundles = GetDependBundles(manifest, packageBundle); reportBundleInfo.DependBundles = GetBundleDependBundles(manifest, packageBundle);
reportBundleInfo.AllBuiltinAssets = GetAllBuiltinAssets(buildMapContext, packageBundle.BundleName); reportBundleInfo.ReferenceBundles = GetBundleReferenceBundles(manifest, packageBundle);
reportBundleInfo.BundleContents = GetBundleContents(buildMapContext, packageBundle.BundleName);
buildReport.BundleInfos.Add(reportBundleInfo); buildReport.BundleInfos.Add(reportBundleInfo);
} }
@ -124,9 +120,40 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取资源对象依赖的所有资源 /// 获取资源对象依赖的其它所有资源
/// </summary> /// </summary>
private List<string> GetDependBundles(PackageManifest manifest, PackageBundle packageBundle) private List<AssetInfo> GetAssetDependAssets(BuildMapContext buildMapContext, string bundleName, string assetPath)
{
List<AssetInfo> result = new List<AssetInfo>();
var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
var assetInfo = bundleInfo.GetPackAssetInfo(assetPath);
foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
{
result.Add(dependAssetInfo.AssetInfo);
}
result.Sort();
return result;
}
/// <summary>
/// 获取资源对象依赖的资源包集合
/// </summary>
private List<string> GetAssetDependBundles(PackageManifest manifest, PackageAsset packageAsset)
{
List<string> dependBundles = new List<string>(packageAsset.DependBundleIDs.Length);
foreach (int index in packageAsset.DependBundleIDs)
{
string dependBundleName = manifest.BundleList[index].BundleName;
dependBundles.Add(dependBundleName);
}
dependBundles.Sort();
return dependBundles;
}
/// <summary>
/// 获取资源包依赖的资源包集合
/// </summary>
private List<string> GetBundleDependBundles(PackageManifest manifest, PackageBundle packageBundle)
{ {
List<string> dependBundles = new List<string>(packageBundle.DependIDs.Length); List<string> dependBundles = new List<string>(packageBundle.DependIDs.Length);
foreach (int index in packageBundle.DependIDs) foreach (int index in packageBundle.DependIDs)
@ -139,42 +166,27 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取资源对象依赖的其它所有资源 /// 获取引用该资源包的资源包集合
/// </summary> /// </summary>
private List<string> GetDependAssets(BuildMapContext buildMapContext, string bundleName, string assetPath) private List<string> GetBundleReferenceBundles(PackageManifest manifest, PackageBundle packageBundle)
{ {
List<string> result = new List<string>(); List<string> referenceBundles = new List<string>(packageBundle.ReferenceBundleIDs.Length);
var bundleInfo = buildMapContext.GetBundleInfo(bundleName); foreach (int index in packageBundle.ReferenceBundleIDs)
{ {
BuildAssetInfo findAssetInfo = null; string dependBundleName = manifest.BundleList[index].BundleName;
foreach (var buildAsset in bundleInfo.MainAssets) referenceBundles.Add(dependBundleName);
{
if (buildAsset.AssetInfo.AssetPath == assetPath)
{
findAssetInfo = buildAsset;
break;
} }
} referenceBundles.Sort();
if (findAssetInfo == null) return referenceBundles;
{
throw new Exception($"Should never get here ! Not found asset {assetPath} in bunlde {bundleName}");
}
foreach (var dependAssetInfo in findAssetInfo.AllDependAssetInfos)
{
result.Add(dependAssetInfo.AssetInfo.AssetPath);
}
}
result.Sort();
return result;
} }
/// <summary> /// <summary>
/// 获取该资源包内的所有资源 /// 获取资源包内部所有资产
/// </summary> /// </summary>
private List<string> GetAllBuiltinAssets(BuildMapContext buildMapContext, string bundleName) private List<AssetInfo> GetBundleContents(BuildMapContext buildMapContext, string bundleName)
{ {
var bundleInfo = buildMapContext.GetBundleInfo(bundleName); var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
List<string> result = bundleInfo.GetAllBuiltinAssetPaths(); List<AssetInfo> result = bundleInfo.GetBundleContents();
result.Sort(); result.Sort();
return result; return result;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -71,11 +71,19 @@ namespace YooAsset.Editor
public bool ClearBuildCacheFiles; public bool ClearBuildCacheFiles;
public bool UseAssetDependencyDB; public bool UseAssetDependencyDB;
public bool EnableSharePackRule; public bool EnableSharePackRule;
public bool SingleReferencedPackAlone;
public string EncryptionClassName; public string EncryptionClassName;
public EFileNameStyle FileNameStyle; public EFileNameStyle FileNameStyle;
// 引擎参数
public ECompressOption CompressOption; public ECompressOption CompressOption;
public bool DisableWriteTypeTree; public bool DisableWriteTypeTree;
public bool IgnoreTypeTreeChanges; public bool IgnoreTypeTreeChanges;
public bool WriteLinkXML = true;
public string CacheServerHost;
public int CacheServerPort;
public string BuiltinShadersBundleName;
public string MonoScriptsBundleName;
// 构建结果 // 构建结果
public int AssetFileTotalCount; public int AssetFileTotalCount;

View File

@ -116,6 +116,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true; columnStyle.Stretchable = true;
columnStyle.Searchable = true; columnStyle.Searchable = true;
columnStyle.Sortable = true; columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("DependBundles", "Depend Bundles", columnStyle); var column = new TableColumn("DependBundles", "Depend Bundles", columnStyle);
column.MakeCell = () => column.MakeCell = () =>
{ {

View File

@ -320,15 +320,15 @@ namespace YooAsset.Editor
sourceDatas.Add(rowData); sourceDatas.Add(rowData);
} }
} }
foreach (string assetPath in bundleInfo.AllBuiltinAssets) foreach (var assetInfo in bundleInfo.BundleContents)
{ {
if (mainAssetDic.Contains(assetPath) == false) if (mainAssetDic.Contains(assetInfo.AssetPath) == false)
{ {
var rowData = new IncludeTableData(); var rowData = new IncludeTableData();
rowData.AssetInfo = null; rowData.AssetInfo = null;
rowData.AddAssetPathCell("IncludeAssets", assetPath); rowData.AddAssetPathCell("IncludeAssets", assetInfo.AssetPath);
rowData.AddStringValueCell("AssetSource", "BuiltinAsset"); rowData.AddStringValueCell("AssetSource", "BuiltinAsset");
rowData.AddStringValueCell("AssetGUID", "--"); rowData.AddStringValueCell("AssetGUID", assetInfo.AssetGUID);
sourceDatas.Add(rowData); sourceDatas.Add(rowData);
} }
} }

View File

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

View File

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

View File

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

View File

@ -129,6 +129,21 @@ namespace YooAsset.Editor
} }
#endregion #endregion
#region PackageManager
public static string GetPackageManagerYooVersion()
{
#if UNITY_2019_4_OR_NEWER
UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(YooAssets).Assembly);
if (packageInfo != null)
return packageInfo.version;
else
return string.Empty;
#else
return string.Empty;
#endif
}
#endregion
#region EditorUtility #region EditorUtility
/// <summary> /// <summary>
/// 搜集资源 /// 搜集资源

View File

@ -41,6 +41,11 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool Sortable = false; public bool Sortable = false;
/// <summary>
/// 统计数量
/// </summary>
public bool Counter = false;
public ColumnStyle(Length width) public ColumnStyle(Length width)
{ {
if (width.value > MaxValue) if (width.value > MaxValue)

View File

@ -191,6 +191,16 @@ namespace YooAsset.Editor
_listView.ClearSelection(); _listView.ClearSelection();
_listView.itemsSource = itemsSource.ToList(); _listView.itemsSource = itemsSource.ToList();
_listView.Rebuild(); _listView.Rebuild();
// 动态设置元素数量
foreach (var column in _columns)
{
if (column.ColumnStyle.Counter)
{
var toobarButton = GetHeaderElement(column.ElementName) as ToolbarButton;
toobarButton.text = $"{column.HeaderTitle} ({itemsSource.Count()})";
}
}
} }
/// <summary> /// <summary>