Update AssetBundleDebugger

pull/4/head
hevinci 2022-03-15 22:30:57 +08:00
parent d190bc35b4
commit 857eb1d0bb
11 changed files with 365 additions and 11 deletions

View File

@ -0,0 +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:ToolbarSearchField focusable="true" name="rSearchField" style="flex-grow: 1;" />
</uie:Toolbar>
</ui:UXML>

View File

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

View File

@ -0,0 +1,63 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor.UIElements;
namespace YooAsset.Editor
{
public class AssetBundleDebuggerWindow : EditorWindow
{
[MenuItem("YooAsset/AssetBundle Debugger", false, 104)]
public static void ShowExample()
{
AssetBundleDebuggerWindow wnd = GetWindow<AssetBundleDebuggerWindow>();
wnd.titleContent = new GUIContent("资源包调试工具");
wnd.minSize = new Vector2(800, 600);
}
private AssetListDebuggerViewer _assetListViewer;
private readonly DebugSummy _summy = new DebugSummy();
private string _searchKeyWord;
public void CreateGUI()
{
VisualElement root = rootVisualElement;
// 加载布局文件
string uxml = "Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebugger.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null)
{
Debug.LogError($"Not found AssetBundleDebugger.uxml : {uxml}");
return;
}
visualAsset.CloneTree(root);
// 采样按钮
var sampleBtn = root.Q<Button>("SampleButton");
sampleBtn.clicked += SampleBtn_onClick;
// 搜索栏
var searchField = root.Q<ToolbarPopupSearchField>("SearchField");
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
// 加载页面
_assetListViewer = new AssetListDebuggerViewer();
_assetListViewer.InitViewer();
// 初始页面
_assetListViewer.AttachParent(root);
}
private void SampleBtn_onClick()
{
YooAssets.GetDebugSummy(_summy);
_assetListViewer.FillViewData(_summy, _searchKeyWord);
}
private void OnSearchKeyWordChange(ChangeEvent<string> e)
{
_searchKeyWord = e.newValue;
_assetListViewer.FillViewData(_summy, _searchKeyWord);
}
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a034acd0035503742bc8d24b3c4068c2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,237 @@
#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 AssetListDebuggerViewer
{
private VisualTreeAsset _visualAsset;
private TemplateContainer _root;
private ListView _assetListView;
private ListView _dependListView;
private DebugSummy _summy;
/// <summary>
/// 初始化页面
/// </summary>
public void InitViewer()
{
// 加载布局文件
string uxml = "Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/AssetListDebuggerViewer.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetListDebuggerViewer)}.uxml : {uxml}");
return;
}
_root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f;
// 资源列表
_assetListView = _root.Q<ListView>("TopListView");
_assetListView.makeItem = MakeAssetListViewItem;
_assetListView.bindItem = BindAssetListViewItem;
#if UNITY_2020_1_OR_NEWER
_assetListView.onSelectionChange += AssetListView_onSelectionChange;
#else
_assetListView.onSelectionChanged += AssetListView_onSelectionChange;
#endif
// 依赖列表
_dependListView = _root.Q<ListView>("BottomListView");
_dependListView.makeItem = MakeDependListViewItem;
_dependListView.bindItem = BindDependListViewItem;
}
/// <summary>
/// 填充页面数据
/// </summary>
public void FillViewData(DebugSummy summy, string searchKeyWord)
{
_summy = summy;
_assetListView.Clear();
_assetListView.itemsSource = FilterViewItems(summy, searchKeyWord);
}
private List<DebugProviderInfo> FilterViewItems(DebugSummy summy, string searchKeyWord)
{
var result = new List<DebugProviderInfo>(summy.ProviderInfos.Count);
foreach (var providerInfo in summy.ProviderInfos)
{
if(string.IsNullOrEmpty(searchKeyWord) == false)
{
if (providerInfo.AssetPath.Contains(searchKeyWord) == false)
continue;
}
result.Add(providerInfo);
}
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 = 120;
element.Add(label);
}
return element;
}
private void BindAssetListViewItem(VisualElement element, int index)
{
var sourceData = _assetListView.itemsSource as List<DebugProviderInfo>;
var providerInfo = sourceData[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 AssetListView_onSelectionChange(IEnumerable<object> objs)
{
foreach (var item in objs)
{
DebugProviderInfo providerInfo = item as DebugProviderInfo;
FillDependListView(providerInfo);
}
}
// 依赖列表相关
private VisualElement MakeDependListViewItem()
{
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 = 250;
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 = 150;
element.Add(label);
}
return element;
}
private void BindDependListViewItem(VisualElement element, int index)
{
List<DebugBundleInfo> bundles = _dependListView.itemsSource as List<DebugBundleInfo>;
DebugBundleInfo bundleInfo = bundles[index];
// Bundle Name
var label1 = element.Q<Label>("Label1");
label1.text = bundleInfo.BundleName;
// Version
var label2 = element.Q<Label>("Label2");
label2.text = bundleInfo.Version.ToString();
// Ref Count
var label3 = element.Q<Label>("Label3");
label3.text = bundleInfo.RefCount.ToString();
// Status
var label4 = element.Q<Label>("Label4");
label4.text = bundleInfo.Status.ToString();
}
private void FillDependListView(DebugProviderInfo providerInfo)
{
_dependListView.Clear();
#if UNITY_2020_1_OR_NEWER
_dependListView.ClearSelection();
#endif
_dependListView.itemsSource = providerInfo.BundleInfos;
}
}
}
#endif

View File

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

View File

@ -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="Asset Path" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar3" 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="Depend Bundles" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Version" display-tooltip-when-elided="true" name="BottomBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<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>

View File

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

View File

@ -1,11 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset.Editor
{
public class AssetBundleProfilerWindow
{
}
}