Files
YooAsset/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs

177 lines
5.2 KiB
C#
Raw Normal View History

2022-03-13 20:29:36 +08:00
#if UNITY_2019_4_OR_NEWER
2022-03-13 20:16:52 +08:00
using UnityEditor;
using UnityEngine;
2022-03-09 21:53:01 +08:00
using UnityEditor.UIElements;
2022-03-13 20:16:52 +08:00
using UnityEngine.UIElements;
2022-03-01 10:44:12 +08:00
2022-03-09 21:53:01 +08:00
namespace YooAsset.Editor
2022-03-01 10:44:12 +08:00
{
2022-03-18 11:24:55 +08:00
public class AssetBundleReporterWindow : EditorWindow
2022-03-09 21:53:01 +08:00
{
2022-03-18 11:24:55 +08:00
[MenuItem("YooAsset/AssetBundle Reporter", false, 103)]
2022-03-13 20:16:52 +08:00
public static void ShowExample()
{
2022-03-18 11:24:55 +08:00
AssetBundleReporterWindow window = GetWindow<AssetBundleReporterWindow>();
window.titleContent = new GUIContent("资源包报告工具");
window.minSize = new Vector2(800, 600);
2022-03-13 20:16:52 +08:00
}
2022-03-01 10:44:12 +08:00
2022-03-15 22:30:46 +08:00
/// <summary>
/// 显示模式
/// </summary>
2022-03-13 20:16:52 +08:00
private enum EShowMode
{
2022-03-18 20:57:02 +08:00
/// <summary>
/// 概览
/// </summary>
Summary,
2022-03-15 22:30:46 +08:00
/// <summary>
/// 资源对象列表显示模式
/// </summary>
2022-03-13 20:16:52 +08:00
AssetList,
2022-03-15 22:30:46 +08:00
/// <summary>
/// 资源包列表显示模式
/// </summary>
2022-03-13 20:16:52 +08:00
BundleList,
}
private ToolbarMenu _showModeMenu;
2022-03-18 20:57:02 +08:00
private SummaryReporterViewer _summaryViewer;
2022-03-18 11:24:55 +08:00
private AssetListReporterViewer _assetListViewer;
private BundleListReporterViewer _bundleListViewer;
2022-03-13 20:16:52 +08:00
private EShowMode _showMode;
private string _searchKeyWord;
2022-03-18 11:24:55 +08:00
private BuildReport _buildReport;
2022-03-13 20:16:52 +08:00
public void CreateGUI()
{
VisualElement root = this.rootVisualElement;
2022-03-15 22:30:46 +08:00
// 加载布局文件
2022-03-16 00:01:09 +08:00
string rootPath = EditorTools.GetYooAssetPath();
2022-03-18 11:24:55 +08:00
string uxml = $"{rootPath}/Editor/AssetBundleReporter/AssetBundleReporter.uxml";
2022-03-13 20:16:52 +08:00
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null)
{
2022-03-18 11:24:55 +08:00
Debug.LogError($"Not found AssetBundleReporter.uxml : {uxml}");
2022-03-13 20:16:52 +08:00
return;
}
visualAsset.CloneTree(root);
2022-03-15 22:30:46 +08:00
// 导入按钮
2022-03-13 20:16:52 +08:00
var importBtn = root.Q<Button>("ImportButton");
importBtn.clicked += ImportBtn_onClick;
2022-03-15 22:30:46 +08:00
// 显示模式菜单
2022-03-13 20:16:52 +08:00
_showModeMenu = root.Q<ToolbarMenu>("ShowModeMenu");
2022-03-18 20:57:02 +08:00
_showModeMenu.menu.AppendAction(EShowMode.Summary.ToString(), ShowModeMenuAction0, ShowModeMenuFun0);
_showModeMenu.menu.AppendAction(EShowMode.AssetList.ToString(), ShowModeMenuAction1, ShowModeMenuFun1);
_showModeMenu.menu.AppendAction(EShowMode.BundleList.ToString(), ShowModeMenuAction2, ShowModeMenuFun2);
2022-03-13 20:16:52 +08:00
2022-03-15 22:30:46 +08:00
// 搜索栏
2022-03-16 00:01:09 +08:00
var searchField = root.Q<ToolbarSearchField>("SearchField");
2022-03-13 20:16:52 +08:00
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
2022-03-18 20:57:02 +08:00
// 加载页面
_summaryViewer = new SummaryReporterViewer();
_summaryViewer.InitViewer();
2022-03-15 22:30:46 +08:00
// 加载页面
2022-03-18 11:24:55 +08:00
_assetListViewer = new AssetListReporterViewer();
2022-03-13 20:16:52 +08:00
_assetListViewer.InitViewer();
2022-03-15 22:30:46 +08:00
// 加载页面
2022-03-18 11:24:55 +08:00
_bundleListViewer = new BundleListReporterViewer();
2022-03-13 20:16:52 +08:00
_bundleListViewer.InitViewer();
2022-03-15 22:30:46 +08:00
// 初始页面
2022-03-18 20:57:02 +08:00
_showMode = EShowMode.Summary;
_showModeMenu.text = EShowMode.Summary.ToString();
_summaryViewer.AttachParent(root);
2022-03-13 20:16:52 +08:00
}
private void ImportBtn_onClick()
{
2022-03-18 11:24:55 +08:00
string selectFilePath = EditorUtility.OpenFilePanel("导入报告", EditorTools.GetProjectPath(), "json");
2022-03-13 20:16:52 +08:00
if (string.IsNullOrEmpty(selectFilePath))
return;
string jsonData = FileUtility.ReadFile(selectFilePath);
2022-03-18 11:24:55 +08:00
_buildReport = BuildReport.Deserialize(jsonData);
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord);
2022-03-18 20:57:02 +08:00
_summaryViewer.FillViewData(_buildReport);
2022-03-13 20:16:52 +08:00
}
private void OnSearchKeyWordChange(ChangeEvent<string> e)
{
_searchKeyWord = e.newValue;
2022-03-18 11:24:55 +08:00
if(_buildReport != null)
2022-03-16 00:01:09 +08:00
{
2022-03-18 11:24:55 +08:00
_assetListViewer.FillViewData(_buildReport, _searchKeyWord);
_bundleListViewer.FillViewData(_buildReport, _searchKeyWord);
2022-03-16 00:01:09 +08:00
}
2022-03-13 20:16:52 +08:00
}
2022-03-18 20:57:02 +08:00
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();
}
}
2022-03-13 20:16:52 +08:00
private void ShowModeMenuAction1(DropdownMenuAction action)
{
if (_showMode != EShowMode.AssetList)
{
_showMode = EShowMode.AssetList;
VisualElement root = this.rootVisualElement;
_showModeMenu.text = EShowMode.AssetList.ToString();
2022-03-18 20:57:02 +08:00
_summaryViewer.DetachParent();
2022-03-13 20:16:52 +08:00
_assetListViewer.AttachParent(root);
2022-03-18 20:57:02 +08:00
_bundleListViewer.DetachParent();
2022-03-13 20:16:52 +08:00
}
}
private void ShowModeMenuAction2(DropdownMenuAction action)
{
if (_showMode != EShowMode.BundleList)
{
_showMode = EShowMode.BundleList;
VisualElement root = this.rootVisualElement;
_showModeMenu.text = EShowMode.BundleList.ToString();
2022-03-18 20:57:02 +08:00
_summaryViewer.DetachParent();
2022-03-13 20:16:52 +08:00
_assetListViewer.DetachParent();
_bundleListViewer.AttachParent(root);
}
}
2022-03-18 20:57:02 +08:00
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;
}
2022-03-09 21:53:01 +08:00
}
2022-03-13 20:29:36 +08:00
}
#endif