Update AssetBundleReporter

pull/4/head
hevinci 2022-03-18 20:57:02 +08:00
parent 512093b0ba
commit 3689a39a47
5 changed files with 229 additions and 6 deletions

View File

@ -21,6 +21,11 @@ namespace YooAsset.Editor
/// </summary>
private enum EShowMode
{
/// <summary>
/// 概览
/// </summary>
Summary,
/// <summary>
/// 资源对象列表显示模式
/// </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<ToolbarMenu>("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<ToolbarSearchField>("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<string> 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

View File

@ -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<ItemWrapper> _items = new List<ItemWrapper>();
/// <summary>
/// 初始化页面
/// </summary>
public void InitViewer()
{
// 加载布局文件
string rootPath = EditorTools.GetYooAssetPath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(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");
_listView.makeItem = MakeListViewItem;
_listView.bindItem = BindListViewItem;
}
/// <summary>
/// 填充页面数据
/// </summary>
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}"));
}
/// <summary>
/// 挂接到父类页面上
/// </summary>
public void AttachParent(VisualElement parent)
{
parent.Add(_root);
}
/// <summary>
/// 从父类页面脱离开
/// </summary>
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<Label>("Label1");
label1.text = itemWrapper.Title;
// Value
var label2 = element.Q<Label>("Label2");
label2.text = itemWrapper.Value;
}
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d3aba580c6b1c3447a3336a478717965
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<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="概览" display-tooltip-when-elided="true" name="TopBar1" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="参数" 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" style="flex-grow: 1;" />
</ui:VisualElement>
</ui:UXML>

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f8929271050855e42a1ccc6b14993a04
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}