From 9add44756665d9644d6c9759ae387be07d18e865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Mon, 20 Jan 2025 17:14:47 +0800 Subject: [PATCH] update asset bundle reporter --- .../AssetBundleReporterWindow.cs | 8 +- .../VisualViewers/ReporterAssetListViewer.cs | 457 ++++++------ .../ReporterAssetListViewer.uxml | 13 +- .../VisualViewers/ReporterBundleListViewer.cs | 650 +++++++++--------- .../ReporterBundleListViewer.uxml | 16 +- 5 files changed, 553 insertions(+), 591 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs index dd5aacda..f9709042 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs @@ -112,16 +112,16 @@ namespace YooAsset.Editor string jsonData = FileUtility.ReadAllText(_reportFilePath); _buildReport = BuildReport.Deserialize(jsonData); _summaryViewer.FillViewData(_buildReport); - _assetListViewer.FillViewData(_buildReport, _searchKeyWord); - _bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord); + _assetListViewer.FillViewData(_buildReport, _reportFilePath); + _bundleListViewer.FillViewData(_buildReport, _reportFilePath); } private void OnSearchKeyWordChange(ChangeEvent e) { _searchKeyWord = e.newValue; if (_buildReport != null) { - _assetListViewer.FillViewData(_buildReport, _searchKeyWord); - _bundleListViewer.FillViewData(_buildReport, _reportFilePath, _searchKeyWord); + _assetListViewer.RebuildView(_searchKeyWord); + _bundleListViewer.RebuildView(_searchKeyWord); } } private void ViewModeMenuAction0(DropdownMenuAction action) diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterAssetListViewer.cs b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterAssetListViewer.cs index f59e8849..2c7cc417 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterAssetListViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterAssetListViewer.cs @@ -6,30 +6,30 @@ using UnityEditor; using UnityEngine; using UnityEditor.UIElements; using UnityEngine.UIElements; +using System.IO; namespace YooAsset.Editor { internal class ReporterAssetListViewer { - private enum ESortMode + private class AssetTableData : DefaultTableData { - AssetPath, - BundleName + public ReportAssetInfo AssetInfo; + } + private class DependTableData : DefaultTableData + { + public ReportBundleInfo BundleInfo; } private VisualTreeAsset _visualAsset; private TemplateContainer _root; - private ToolbarButton _topBar1; - private ToolbarButton _topBar2; - private ToolbarButton _bottomBar1; - private ListView _assetListView; - private ListView _dependListView; + private TableView _assetTableView; + private TableView _dependTableView; private BuildReport _buildReport; - private string _searchKeyWord; - private ESortMode _sortMode = ESortMode.AssetPath; - private bool _descendingSort = false; + private string _reportFilePath; + private List _sourceDatas; /// @@ -45,113 +45,200 @@ namespace YooAsset.Editor _root = _visualAsset.CloneTree(); _root.style.flexGrow = 1f; - // 顶部按钮栏 - _topBar1 = _root.Q("TopBar1"); - _topBar2 = _root.Q("TopBar2"); - _topBar1.clicked += TopBar1_clicked; - _topBar2.clicked += TopBar2_clicked; - - // 底部按钮栏 - _bottomBar1 = _root.Q("BottomBar1"); - // 资源列表 - _assetListView = _root.Q("TopListView"); - _assetListView.makeItem = MakeAssetListViewItem; - _assetListView.bindItem = BindAssetListViewItem; -#if UNITY_2022_3_OR_NEWER - _assetListView.selectionChanged += AssetListView_onSelectionChange; -#elif UNITY_2020_1_OR_NEWER - _assetListView.onSelectionChange += AssetListView_onSelectionChange; -#else - _assetListView.onSelectionChanged += AssetListView_onSelectionChange; -#endif + _assetTableView = _root.Q("TopTableView"); + _assetTableView.SelectionChangedEvent = OnAssetTableViewSelectionChanged; + _assetTableView.ClickTableDataEvent = OnClickAssetTableView; + CreateAssetTableViewColumns(); // 依赖列表 - _dependListView = _root.Q("BottomListView"); - _dependListView.makeItem = MakeDependListViewItem; - _dependListView.bindItem = BindDependListViewItem; + _dependTableView = _root.Q("BottomTableView"); + _dependTableView.ClickTableDataEvent = OnClickBundleTableView; + CreateDependTableViewColumns(); #if UNITY_2020_3_OR_NEWER SplitView.Adjuster(_root); #endif } + private void CreateAssetTableViewColumns() + { + // AssetPath + { + var columnStyle = new ColumnStyle(); + columnStyle.Width = 300; + columnStyle.Stretchable = true; + columnStyle.Searchable = true; + columnStyle.Sortable = true; + var column = new TableColumn("AssetPath", "AssetPath", columnStyle); + column.MakeCell = () => + { + var label = new Label(); + label.style.unityTextAlign = TextAnchor.MiddleLeft; + label.style.marginLeft = 3f; + label.style.flexGrow = columnStyle.Stretchable ? 1f : 0f; + label.style.width = columnStyle.Width; + label.style.maxWidth = columnStyle.MaxWidth; + label.style.minWidth = columnStyle.MinWidth; + return label; + }; + column.BindCell = (VisualElement element, ITableData data, ITableCell cell) => + { + var infoLabel = element as Label; + infoLabel.text = (string)cell.GetDisplayObject(); + }; + _assetTableView.AddColumn(column); + } + + //MainBundle + { + var columnStyle = new ColumnStyle(); + columnStyle.Width = 150; + columnStyle.Stretchable = true; + columnStyle.Searchable = true; + columnStyle.Sortable = true; + var column = new TableColumn("MainBundle", "MainBundle", columnStyle); + column.MakeCell = () => + { + var label = new Label(); + label.style.unityTextAlign = TextAnchor.MiddleLeft; + label.style.marginLeft = 3f; + label.style.flexGrow = columnStyle.Stretchable ? 1f : 0f; + label.style.width = columnStyle.Width; + label.style.maxWidth = columnStyle.MaxWidth; + label.style.minWidth = columnStyle.MinWidth; + return label; + }; + column.BindCell = (VisualElement element, ITableData data, ITableCell cell) => + { + var infoLabel = element as Label; + infoLabel.text = (string)cell.GetDisplayObject(); + }; + _assetTableView.AddColumn(column); + } + } + private void CreateDependTableViewColumns() + { + // DependBundles + { + var columnStyle = new ColumnStyle(); + columnStyle.Width = 280; + columnStyle.Stretchable = true; + columnStyle.Searchable = true; + columnStyle.Sortable = true; + var column = new TableColumn("DependBundles", "DependBundles", columnStyle); + column.MakeCell = () => + { + var label = new Label(); + label.style.unityTextAlign = TextAnchor.MiddleLeft; + label.style.marginLeft = 3f; + label.style.flexGrow = columnStyle.Stretchable ? 1f : 0f; + label.style.width = columnStyle.Width; + label.style.maxWidth = columnStyle.MaxWidth; + label.style.minWidth = columnStyle.MinWidth; + return label; + }; + column.BindCell = (VisualElement element, ITableData data, ITableCell cell) => + { + var infoLabel = element as Label; + infoLabel.text = (string)cell.GetDisplayObject(); + }; + _dependTableView.AddColumn(column); + } + + // FileSize + { + var columnStyle = new ColumnStyle(); + columnStyle.Width = 100; + columnStyle.Stretchable = false; + columnStyle.Searchable = false; + columnStyle.Sortable = true; + var column = new TableColumn("FileSize", "FileSize", columnStyle); + column.MakeCell = () => + { + var label = new Label(); + label.style.unityTextAlign = TextAnchor.MiddleLeft; + label.style.marginLeft = 3f; + label.style.flexGrow = columnStyle.Stretchable ? 1f : 0f; + label.style.width = columnStyle.Width; + label.style.maxWidth = columnStyle.MaxWidth; + label.style.minWidth = columnStyle.MinWidth; + return label; + }; + column.BindCell = (VisualElement element, ITableData data, ITableCell cell) => + { + var infoLabel = element as Label; + long fileSize = (long)cell.CellValue; + infoLabel.text = EditorUtility.FormatBytes(fileSize); + }; + _dependTableView.AddColumn(column); + } + + // FileHash + { + var columnStyle = new ColumnStyle(); + columnStyle.Width = 250; + columnStyle.Stretchable = false; + columnStyle.Searchable = false; + columnStyle.Sortable = false; + var column = new TableColumn("FileHash", "FileHash", columnStyle); + column.MakeCell = () => + { + var label = new Label(); + label.style.unityTextAlign = TextAnchor.MiddleLeft; + label.style.marginLeft = 3f; + label.style.flexGrow = columnStyle.Stretchable ? 1f : 0f; + label.style.width = columnStyle.Width; + label.style.maxWidth = columnStyle.MaxWidth; + label.style.minWidth = columnStyle.MinWidth; + return label; + }; + column.BindCell = (VisualElement element, ITableData data, ITableCell cell) => + { + var infoLabel = element as Label; + infoLabel.text = (string)cell.GetDisplayObject(); + }; + _dependTableView.AddColumn(column); + } + } /// /// 填充页面数据 /// - public void FillViewData(BuildReport buildReport, string searchKeyWord) + public void FillViewData(BuildReport buildReport, string reprotFilePath) { _buildReport = buildReport; - _searchKeyWord = searchKeyWord; - RefreshView(); - } - private void RefreshView() - { - _assetListView.Clear(); - _assetListView.ClearSelection(); - _assetListView.itemsSource = FilterAndSortViewItems(); - _assetListView.Rebuild(); - RefreshSortingSymbol(); - } - private List FilterAndSortViewItems() - { - List result = new List(_buildReport.AssetInfos.Count); + _reportFilePath = reprotFilePath; - // 过滤列表 + // 清空旧数据 + _assetTableView.ClearAll(false, true); + _dependTableView.ClearAll(false, true); + + // 填充数据源 + _sourceDatas = new List(_buildReport.AssetInfos.Count); foreach (var assetInfo in _buildReport.AssetInfos) { - if (string.IsNullOrEmpty(_searchKeyWord) == false) - { - if (assetInfo.AssetPath.Contains(_searchKeyWord) == false) - continue; - } - result.Add(assetInfo); + var rowData = new AssetTableData(); + rowData.AssetInfo = assetInfo; + rowData.AddAssetPathCell("AssetPath", assetInfo.AssetPath); + rowData.AddStringValueCell("MainBundle", assetInfo.MainBundleName); + _sourceDatas.Add(rowData); } + _assetTableView.itemsSource = _sourceDatas; - // 排序列表 - if (_sortMode == ESortMode.AssetPath) - { - if (_descendingSort) - return result.OrderByDescending(a => a.AssetPath).ToList(); - else - return result.OrderBy(a => a.AssetPath).ToList(); - } - else if (_sortMode == ESortMode.BundleName) - { - if (_descendingSort) - return result.OrderByDescending(a => a.MainBundleName).ToList(); - else - return result.OrderBy(a => a.MainBundleName).ToList(); - } - else - { - throw new System.NotImplementedException(); - } + // 重建视图 + RebuildView(null); } - private void RefreshSortingSymbol() - { - // 刷新符号 - _topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count})"; - _topBar2.text = "Main Bundle"; - if (_sortMode == ESortMode.AssetPath) - { - if (_descendingSort) - _topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count}) ↓"; - else - _topBar1.text = $"Asset Path ({_assetListView.itemsSource.Count}) ↑"; - } - else if (_sortMode == ESortMode.BundleName) - { - if (_descendingSort) - _topBar2.text = "Main Bundle ↓"; - else - _topBar2.text = "Main Bundle ↑"; - } - else - { - throw new System.NotImplementedException(); - } + /// + /// 重建视图 + /// + public void RebuildView(string searchKeyWord) + { + // 搜索匹配 + DefaultSearchSystem.Search(_sourceDatas, searchKeyWord); + + // 重建视图 + _assetTableView.RebuildView(); } /// @@ -170,157 +257,65 @@ namespace YooAsset.Editor _root.RemoveFromHierarchy(); } - - // 资源列表相关 - private VisualElement MakeAssetListViewItem() + private void OnAssetTableViewSelectionChanged(ITableData data) { - VisualElement element = new VisualElement(); - element.style.flexDirection = FlexDirection.Row; + var assetTableData = data as AssetTableData; + ReportAssetInfo assetInfo = assetTableData.AssetInfo; - { - var label = new Label(); - label.name = "Label1"; - label.style.unityTextAlign = TextAnchor.MiddleLeft; - label.style.marginLeft = 3f; - label.style.flexGrow = 1f; - label.style.width = 280; - element.Add(label); - } - - { - var label = new Label(); - label.name = "Label2"; - label.style.unityTextAlign = TextAnchor.MiddleLeft; - label.style.marginLeft = 3f; - label.style.flexGrow = 1f; - label.style.width = 150; - element.Add(label); - } - - return element; - } - private void BindAssetListViewItem(VisualElement element, int index) - { - var sourceData = _assetListView.itemsSource as List; - var assetInfo = sourceData[index]; - var bundleInfo = _buildReport.GetBundleInfo(assetInfo.MainBundleName); - - // Asset Path - var label1 = element.Q