Optimized the loading method of the setting file

优化了配置文件的加载方式和途径。
This commit is contained in:
hevinci
2022-05-13 23:53:19 +08:00
parent a054740de6
commit 8dc0560537
38 changed files with 308 additions and 265 deletions

View File

@@ -1,4 +1,5 @@
#if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
@@ -37,9 +38,9 @@ namespace YooAsset.Editor
}
private ToolbarMenu _viewModeMenu;
private SummaryReporterViewer _summaryViewer;
private AssetListReporterViewer _assetListViewer;
private BundleListReporterViewer _bundleListViewer;
private ReporterSummaryViewer _summaryViewer;
private ReporterAssetListViewer _assetListViewer;
private ReporterBundleListViewer _bundleListViewer;
private EViewMode _viewMode;
private BuildReport _buildReport;
@@ -49,49 +50,54 @@ namespace YooAsset.Editor
public void CreateGUI()
{
VisualElement root = this.rootVisualElement;
// 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/{nameof(AssetBundleReporterWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null)
try
{
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml : {uxml}");
return;
VisualElement root = this.rootVisualElement;
// 加载布局文件
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleReporterUXML;
if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml in settings.");
return;
}
visualAsset.CloneTree(root);
// 导入按钮
var importBtn = root.Q<Button>("ImportButton");
importBtn.clicked += ImportBtn_onClick;
// 视图模式菜单
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
_viewModeMenu.menu.AppendAction(EViewMode.Summary.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);
// 加载视图
_summaryViewer = new ReporterSummaryViewer();
_summaryViewer.InitViewer();
// 加载视图
_assetListViewer = new ReporterAssetListViewer();
_assetListViewer.InitViewer();
// 加载视图
_bundleListViewer = new ReporterBundleListViewer();
_bundleListViewer.InitViewer();
// 显示视图
_viewMode = EViewMode.Summary;
_viewModeMenu.text = EViewMode.Summary.ToString();
_summaryViewer.AttachParent(root);
}
catch (Exception e)
{
Debug.LogError(e.ToString());
}
visualAsset.CloneTree(root);
// 导入按钮
var importBtn = root.Q<Button>("ImportButton");
importBtn.clicked += ImportBtn_onClick;
// 视图模式菜单
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
_viewModeMenu.menu.AppendAction(EViewMode.Summary.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);
// 加载视图
_summaryViewer = new SummaryReporterViewer();
_summaryViewer.InitViewer();
// 加载视图
_assetListViewer = new AssetListReporterViewer();
_assetListViewer.InitViewer();
// 加载视图
_bundleListViewer = new BundleListReporterViewer();
_bundleListViewer.InitViewer();
// 显示视图
_viewMode = EViewMode.Summary;
_viewModeMenu.text = EViewMode.Summary.ToString();
_summaryViewer.AttachParent(root);
}
public void OnDestroy()
{

View File

@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor
{
internal class AssetListReporterViewer
internal class ReporterAssetListViewer
{
private enum ESortMode
{
@@ -38,12 +38,10 @@ namespace YooAsset.Editor
public void InitViewer()
{
// 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(AssetListReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterAssetListViewerUXML;
if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetListReporterViewer)}.uxml : {uxml}");
Debug.LogError($"Not found {nameof(ReporterAssetListViewer)}.uxml in settings.");
return;
}

View File

@@ -10,7 +10,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor
{
internal class BundleListReporterViewer
internal class ReporterBundleListViewer
{
private enum ESortMode
{
@@ -42,12 +42,10 @@ namespace YooAsset.Editor
public void InitViewer()
{
// 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(BundleListReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterBundleListViewerUXML;
if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(BundleListReporterViewer)}.uxml : {uxml}");
Debug.LogError($"Not found {nameof(ReporterBundleListViewer)}.uxml in settings.");
return;
}

View File

@@ -9,7 +9,7 @@ using UnityEngine.UIElements;
namespace YooAsset.Editor
{
internal class SummaryReporterViewer
internal class ReporterSummaryViewer
{
private class ItemWrapper
{
@@ -37,12 +37,10 @@ namespace YooAsset.Editor
public void InitViewer()
{
// 加载布局文件
string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(SummaryReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterSummaryViewerUXML;
if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(SummaryReporterViewer)}.uxml : {uxml}");
Debug.LogError($"Not found {nameof(ReporterSummaryViewer)}.uxml in settings.");
return;
}
_root = _visualAsset.CloneTree();