Update AssetBundleDebugger
parent
bcd53cf834
commit
2d39b9ab2b
|
@ -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="Sample" display-tooltip-when-elided="true" name="SampleButton" style="width: 70px; background-color: rgb(20, 134, 171); -unity-text-align: middle-center;" />
|
||||
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ShowModeMenu" text="ShowMode" style="width: 100px; flex-grow: 0;" />
|
||||
<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:Toolbar>
|
||||
</ui:UXML>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using UnityEditor;
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor.UIElements;
|
||||
|
@ -15,7 +16,32 @@ namespace YooAsset.Editor
|
|||
wnd.minSize = new Vector2(800, 600);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 视图模式
|
||||
/// </summary>
|
||||
private enum EViewMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 内存视图
|
||||
/// </summary>
|
||||
MemoryView,
|
||||
|
||||
/// <summary>
|
||||
/// 资源对象视图
|
||||
/// </summary>
|
||||
AssetView,
|
||||
|
||||
/// <summary>
|
||||
/// 资源包视图
|
||||
/// </summary>
|
||||
BundleView,
|
||||
}
|
||||
|
||||
private ToolbarMenu _viewModeMenu;
|
||||
private AssetListDebuggerViewer _assetListViewer;
|
||||
private BundleListDebuggerViewer _bundleListViewer;
|
||||
|
||||
private EViewMode _viewMode;
|
||||
private readonly DebugReport _debugReport = new DebugReport();
|
||||
private string _searchKeyWord;
|
||||
|
||||
|
@ -39,26 +65,77 @@ namespace YooAsset.Editor
|
|||
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()
|
||||
{
|
||||
YooAssets.GetDebugReport(_debugReport);
|
||||
_assetListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
}
|
||||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||
{
|
||||
_searchKeyWord = e.newValue;
|
||||
_assetListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
}
|
||||
private void ViewModeMenuAction1(DropdownMenuAction action)
|
||||
{
|
||||
if (_viewMode != EViewMode.AssetView)
|
||||
{
|
||||
_viewMode = EViewMode.AssetView;
|
||||
VisualElement root = this.rootVisualElement;
|
||||
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
||||
_assetListViewer.AttachParent(root);
|
||||
_bundleListViewer.DetachParent();
|
||||
}
|
||||
}
|
||||
private void ViewModeMenuAction2(DropdownMenuAction action)
|
||||
{
|
||||
if (_viewMode != EViewMode.BundleView)
|
||||
{
|
||||
_viewMode = EViewMode.BundleView;
|
||||
VisualElement root = this.rootVisualElement;
|
||||
_viewModeMenu.text = EViewMode.BundleView.ToString();
|
||||
_assetListViewer.DetachParent();
|
||||
_bundleListViewer.AttachParent(root);
|
||||
}
|
||||
}
|
||||
private DropdownMenuAction.Status ViewModeMenuFun1(DropdownMenuAction action)
|
||||
{
|
||||
if (_viewMode == EViewMode.AssetView)
|
||||
return DropdownMenuAction.Status.Checked;
|
||||
else
|
||||
return DropdownMenuAction.Status.Normal;
|
||||
}
|
||||
private DropdownMenuAction.Status ViewModeMenuFun2(DropdownMenuAction action)
|
||||
{
|
||||
if (_viewMode == EViewMode.BundleView)
|
||||
return DropdownMenuAction.Status.Checked;
|
||||
else
|
||||
return DropdownMenuAction.Status.Normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,258 @@
|
|||
#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 BundleListDebuggerViewer
|
||||
{
|
||||
private VisualTreeAsset _visualAsset;
|
||||
private TemplateContainer _root;
|
||||
|
||||
private ListView _bundleListView;
|
||||
private ListView _includeListView;
|
||||
private DebugReport _debugReport;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化页面
|
||||
/// </summary>
|
||||
public void InitViewer()
|
||||
{
|
||||
// 加载布局文件
|
||||
string rootPath = EditorTools.GetYooAssetPath();
|
||||
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/BundleListDebuggerViewer.uxml";
|
||||
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
|
||||
if (_visualAsset == null)
|
||||
{
|
||||
Debug.LogError($"Not found {nameof(BundleListDebuggerViewer)}.uxml : {uxml}");
|
||||
return;
|
||||
}
|
||||
_root = _visualAsset.CloneTree();
|
||||
_root.style.flexGrow = 1f;
|
||||
|
||||
// 资源列表
|
||||
_bundleListView = _root.Q<ListView>("TopListView");
|
||||
_bundleListView.makeItem = MakeAssetListViewItem;
|
||||
_bundleListView.bindItem = BindAssetListViewItem;
|
||||
|
||||
#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(DebugReport debugReport, string searchKeyWord)
|
||||
{
|
||||
_debugReport = debugReport;
|
||||
_bundleListView.Clear();
|
||||
_bundleListView.itemsSource = FilterViewItems(debugReport, searchKeyWord);
|
||||
}
|
||||
private List<DebugBundleInfo> FilterViewItems(DebugReport debugReport, string searchKeyWord)
|
||||
{
|
||||
var result = new List<DebugBundleInfo>(debugReport.ProviderInfos.Count);
|
||||
foreach (var providerInfo in debugReport.ProviderInfos)
|
||||
{
|
||||
foreach(var bundleInfo in providerInfo.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 MakeAssetListViewItem()
|
||||
{
|
||||
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 = 100;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
{
|
||||
var label = new Label();
|
||||
label.name = "Label4";
|
||||
label.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
label.style.marginLeft = 3f;
|
||||
//label.style.flexGrow = 1f;
|
||||
label.style.width = 120;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
private void BindAssetListViewItem(VisualElement element, int index)
|
||||
{
|
||||
var sourceData = _bundleListView.itemsSource as List<DebugBundleInfo>;
|
||||
var bundleInfo = sourceData[index];
|
||||
|
||||
StyleColor textColor;
|
||||
if (bundleInfo.Status == AssetBundleLoader.EStatus.Fail)
|
||||
textColor = new StyleColor(Color.yellow);
|
||||
else
|
||||
textColor = new StyleColor(StyleKeyword.Initial);
|
||||
|
||||
// Bundle Name
|
||||
var label1 = element.Q<Label>("Label1");
|
||||
label1.text = bundleInfo.BundleName;
|
||||
label1.style.color = textColor;
|
||||
|
||||
// Version
|
||||
var label2 = element.Q<Label>("Label2");
|
||||
label2.text = bundleInfo.Version.ToString();
|
||||
label2.style.color = textColor;
|
||||
|
||||
// Ref Count
|
||||
var label3 = element.Q<Label>("Label3");
|
||||
label3.text = bundleInfo.RefCount.ToString();
|
||||
label3.style.color = textColor;
|
||||
|
||||
// Status
|
||||
var label4 = element.Q<Label>("Label4");
|
||||
label4.text = bundleInfo.Status.ToString();
|
||||
label4.style.color = textColor;
|
||||
}
|
||||
private void BundleListView_onSelectionChange(IEnumerable<object> objs)
|
||||
{
|
||||
foreach (var item in objs)
|
||||
{
|
||||
DebugBundleInfo bundleInfo = item as DebugBundleInfo;
|
||||
FillIncludeListView(bundleInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// 底部列表相关
|
||||
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 = 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 = 100;
|
||||
element.Add(label);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
private void BindIncludeListViewItem(VisualElement element, int index)
|
||||
{
|
||||
List<DebugProviderInfo> providers = _includeListView.itemsSource as List<DebugProviderInfo>;
|
||||
DebugProviderInfo providerInfo = providers[index];
|
||||
|
||||
// Asset Path
|
||||
var label1 = element.Q<Label>("Label1");
|
||||
label1.text = providerInfo.AssetPath;
|
||||
|
||||
// Ref Count
|
||||
var label2 = element.Q<Label>("Label2");
|
||||
label2.text = providerInfo.RefCount.ToString();
|
||||
|
||||
// Status
|
||||
var label3 = element.Q<Label>("Label3");
|
||||
label3.text = providerInfo.Status.ToString();
|
||||
}
|
||||
private void FillIncludeListView(DebugBundleInfo bundleInfo)
|
||||
{
|
||||
_includeListView.Clear();
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
_includeListView.ClearSelection();
|
||||
#endif
|
||||
|
||||
List<DebugProviderInfo> source = new List<DebugProviderInfo>();
|
||||
foreach(var providerInfo in _debugReport.ProviderInfos)
|
||||
{
|
||||
if (providerInfo.BundleInfos.Contains(bundleInfo))
|
||||
source.Add(providerInfo);
|
||||
}
|
||||
_includeListView.itemsSource = source;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 61de6d9d221a97247ac52dd5a68b74af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,19 @@
|
|||
<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="Bundle Name" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="Version" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left;" />
|
||||
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar3" style="width: 100px; -unity-text-align: middle-left;" />
|
||||
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar4" style="width: 120px; -unity-text-align: middle-left;" />
|
||||
</uie:Toolbar>
|
||||
<ui:ListView focusable="true" name="TopListView" item-height="18" 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="Using Assets" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
|
||||
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="BottomBar4" style="width: 120px; -unity-text-align: middle-left;" />
|
||||
</uie:Toolbar>
|
||||
<ui:ListView focusable="true" name="BottomListView" item-height="18" style="flex-grow: 1;" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 932a25ffd05c13c47994d66e9d73bc37
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
Loading…
Reference in New Issue