From 3689a39a471a5b4f9906f0d1c8aa05011908c68d Mon Sep 17 00:00:00 2001 From: hevinci Date: Fri, 18 Mar 2022 20:57:02 +0800 Subject: [PATCH] Update AssetBundleReporter --- .../AssetBundleReporterWindow.cs | 59 ++++++- .../VisualViewers/SummaryReporterViewer.cs | 146 ++++++++++++++++++ .../SummaryReporterViewer.cs.meta | 11 ++ .../VisualViewers/SummaryReporterViewer.uxml | 9 ++ .../SummaryReporterViewer.uxml.meta | 10 ++ 5 files changed, 229 insertions(+), 6 deletions(-) create mode 100644 Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs create mode 100644 Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs.meta create mode 100644 Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.uxml create mode 100644 Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.uxml.meta diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs index f2b4fb8..2e64bd0 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs @@ -21,6 +21,11 @@ namespace YooAsset.Editor /// private enum EShowMode { + /// + /// 概览 + /// + Summary, + /// /// 资源对象列表显示模式 /// @@ -33,6 +38,7 @@ namespace YooAsset.Editor } private ToolbarMenu _showModeMenu; + private SummaryReporterViewer _summaryViewer; private AssetListReporterViewer _assetListViewer; private BundleListReporterViewer _bundleListViewer; @@ -62,13 +68,18 @@ namespace YooAsset.Editor // 显示模式菜单 _showModeMenu = root.Q("ShowModeMenu"); - _showModeMenu.menu.AppendAction(EShowMode.AssetList.ToString(), ShowModeMenuAction1); - _showModeMenu.menu.AppendAction(EShowMode.BundleList.ToString(), ShowModeMenuAction2); + _showModeMenu.menu.AppendAction(EShowMode.Summary.ToString(), ShowModeMenuAction0, ShowModeMenuFun0); + _showModeMenu.menu.AppendAction(EShowMode.AssetList.ToString(), ShowModeMenuAction1, ShowModeMenuFun1); + _showModeMenu.menu.AppendAction(EShowMode.BundleList.ToString(), ShowModeMenuAction2, ShowModeMenuFun2); // 搜索栏 var searchField = root.Q("SearchField"); searchField.RegisterValueChangedCallback(OnSearchKeyWordChange); + // 加载页面 + _summaryViewer = new SummaryReporterViewer(); + _summaryViewer.InitViewer(); + // 加载页面 _assetListViewer = new AssetListReporterViewer(); _assetListViewer.InitViewer(); @@ -78,9 +89,9 @@ namespace YooAsset.Editor _bundleListViewer.InitViewer(); // 初始页面 - _showMode = EShowMode.AssetList; - _showModeMenu.text = EShowMode.AssetList.ToString(); - _assetListViewer.AttachParent(root); + _showMode = EShowMode.Summary; + _showModeMenu.text = EShowMode.Summary.ToString(); + _summaryViewer.AttachParent(root); } private void ImportBtn_onClick() @@ -93,6 +104,7 @@ namespace YooAsset.Editor _buildReport = BuildReport.Deserialize(jsonData); _assetListViewer.FillViewData(_buildReport, _searchKeyWord); _bundleListViewer.FillViewData(_buildReport, _searchKeyWord); + _summaryViewer.FillViewData(_buildReport); } private void OnSearchKeyWordChange(ChangeEvent e) { @@ -103,6 +115,18 @@ namespace YooAsset.Editor _bundleListViewer.FillViewData(_buildReport, _searchKeyWord); } } + private void ShowModeMenuAction0(DropdownMenuAction action) + { + if (_showMode != EShowMode.Summary) + { + _showMode = EShowMode.Summary; + VisualElement root = this.rootVisualElement; + _showModeMenu.text = EShowMode.Summary.ToString(); + _summaryViewer.AttachParent(root); + _assetListViewer.DetachParent(); + _bundleListViewer.DetachParent(); + } + } private void ShowModeMenuAction1(DropdownMenuAction action) { if (_showMode != EShowMode.AssetList) @@ -110,8 +134,9 @@ namespace YooAsset.Editor _showMode = EShowMode.AssetList; VisualElement root = this.rootVisualElement; _showModeMenu.text = EShowMode.AssetList.ToString(); - _bundleListViewer.DetachParent(); + _summaryViewer.DetachParent(); _assetListViewer.AttachParent(root); + _bundleListViewer.DetachParent(); } } private void ShowModeMenuAction2(DropdownMenuAction action) @@ -121,10 +146,32 @@ namespace YooAsset.Editor _showMode = EShowMode.BundleList; VisualElement root = this.rootVisualElement; _showModeMenu.text = EShowMode.BundleList.ToString(); + _summaryViewer.DetachParent(); _assetListViewer.DetachParent(); _bundleListViewer.AttachParent(root); } } + private DropdownMenuAction.Status ShowModeMenuFun0(DropdownMenuAction action) + { + if (_showMode == EShowMode.Summary) + return DropdownMenuAction.Status.Checked; + else + return DropdownMenuAction.Status.Normal; + } + private DropdownMenuAction.Status ShowModeMenuFun1(DropdownMenuAction action) + { + if (_showMode == EShowMode.AssetList) + return DropdownMenuAction.Status.Checked; + else + return DropdownMenuAction.Status.Normal; + } + private DropdownMenuAction.Status ShowModeMenuFun2(DropdownMenuAction action) + { + if (_showMode == EShowMode.BundleList) + return DropdownMenuAction.Status.Checked; + else + return DropdownMenuAction.Status.Normal; + } } } #endif \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs new file mode 100644 index 0000000..9315d79 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs @@ -0,0 +1,146 @@ +#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 SummaryReporterViewer + { + private class ItemWrapper + { + public string Title { private set; get; } + public string Value { private set; get; } + + public ItemWrapper(string title, string value) + { + Title = title; + Value = value; + } + } + + private VisualTreeAsset _visualAsset; + private TemplateContainer _root; + + private ListView _listView; + private BuildReport _buildReport; + private readonly List _items = new List(); + + + /// + /// 初始化页面 + /// + public void InitViewer() + { + // 加载布局文件 + string rootPath = EditorTools.GetYooAssetPath(); + string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.uxml"; + _visualAsset = AssetDatabase.LoadAssetAtPath(uxml); + if (_visualAsset == null) + { + Debug.LogError($"Not found {nameof(SummaryReporterViewer)}.uxml : {uxml}"); + return; + } + _root = _visualAsset.CloneTree(); + _root.style.flexGrow = 1f; + + // 概述列表 + _listView = _root.Q("ListView"); + _listView.makeItem = MakeListViewItem; + _listView.bindItem = BindListViewItem; + } + + /// + /// 填充页面数据 + /// + public void FillViewData(BuildReport buildReport) + { + _buildReport = buildReport; + _listView.Clear(); + _items.Clear(); + + _items.Add(new ItemWrapper("引擎版本", buildReport.Summary.UnityVersion)); + _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.BuildVersion}")); + + _items.Add(new ItemWrapper("开启自动分包", $"{buildReport.Summary.ApplyRedundancy}")); + _items.Add(new ItemWrapper("开启资源包后缀名", $"{buildReport.Summary.AppendFileExtension}")); + + _items.Add(new ItemWrapper("自动收集着色器", $"{buildReport.Summary.IsCollectAllShaders}")); + _items.Add(new ItemWrapper("着色器资源包名称", $"{buildReport.Summary.ShadersBundleName}")); + + _items.Add(new ItemWrapper("高级构建选项", $"---------------------------------")); + _items.Add(new ItemWrapper("IsForceRebuild", $"{buildReport.Summary.IsForceRebuild}")); + _items.Add(new ItemWrapper("BuildinTags", $"{buildReport.Summary.BuildinTags}")); + _items.Add(new ItemWrapper("CompressOption", $"{buildReport.Summary.CompressOption}")); + _items.Add(new ItemWrapper("IsAppendHash", $"{buildReport.Summary.IsAppendHash}")); + _items.Add(new ItemWrapper("IsDisableWriteTypeTree", $"{buildReport.Summary.IsDisableWriteTypeTree}")); + _items.Add(new ItemWrapper("IsIgnoreTypeTreeChanges", $"{buildReport.Summary.IsIgnoreTypeTreeChanges}")); + _items.Add(new ItemWrapper("IsDisableLoadAssetByFileName", $"{buildReport.Summary.IsDisableLoadAssetByFileName}")); + } + + /// + /// 挂接到父类页面上 + /// + public void AttachParent(VisualElement parent) + { + parent.Add(_root); + } + + /// + /// 从父类页面脱离开 + /// + public void DetachParent() + { + _root.RemoveFromHierarchy(); + } + + // 列表相关 + private VisualElement MakeListViewItem() + { + VisualElement element = new VisualElement(); + element.style.flexDirection = FlexDirection.Row; + + { + var label = new Label(); + label.name = "Label1"; + label.style.unityTextAlign = TextAnchor.MiddleLeft; + label.style.marginLeft = 3f; + //label.style.flexGrow = 1f; + label.style.width = 100; + element.Add(label); + } + + { + var label = new Label(); + label.name = "Label2"; + label.style.unityTextAlign = TextAnchor.MiddleLeft; + label.style.marginLeft = 3f; + label.style.flexGrow = 1f; + label.style.width = 150; + element.Add(label); + } + + return element; + } + private void BindListViewItem(VisualElement element, int index) + { + var itemWrapper = _items[index]; + + // Title + var label1 = element.Q