Optimized the loading method of the setting file

优化了配置文件的加载方式和途径。
pull/13/head
hevinci 2022-05-22 00:39:22 +08:00
parent d43d30f72f
commit a906a84721
21 changed files with 146 additions and 255 deletions

View File

@ -24,7 +24,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private static void LoadSettingData() private static void LoadSettingData()
{ {
_setting = YooAssetEditorSettingsHelper.LoadSettingData<AssetBundleBuilderSetting>(); _setting = EditorHelper.LoadSettingData<AssetBundleBuilderSetting>();
} }
/// <summary> /// <summary>

View File

@ -38,12 +38,10 @@ namespace YooAsset.Editor
VisualElement root = this.rootVisualElement; VisualElement root = this.rootVisualElement;
// 加载布局文件 // 加载布局文件
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleBuilderUXML; var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleBuilderWindow>();
if (visualAsset == null) if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleBuilderWindow)}.uxml in settings.");
return; return;
}
visualAsset.CloneTree(root); visualAsset.CloneTree(root);
_buildTarget = EditorUserBuildSettings.activeBuildTarget; _buildTarget = EditorUserBuildSettings.activeBuildTarget;

View File

@ -105,7 +105,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private static void LoadSettingData() private static void LoadSettingData()
{ {
_setting = YooAssetEditorSettingsHelper.LoadSettingData<AssetBundleCollectorSetting>(); _setting = EditorHelper.LoadSettingData<AssetBundleCollectorSetting>();
// IPackRule // IPackRule
{ {

View File

@ -54,12 +54,10 @@ namespace YooAsset.Editor
VisualElement root = this.rootVisualElement; VisualElement root = this.rootVisualElement;
// 加载布局文件 // 加载布局文件
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleCollectorUXML; var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleCollectorWindow>();
if (visualAsset == null) if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleCollectorWindow)}.uxml in settings.");
return; return;
}
visualAsset.CloneTree(root); visualAsset.CloneTree(root);
// 导入导出按钮 // 导入导出按钮

View File

@ -53,12 +53,10 @@ namespace YooAsset.Editor
VisualElement root = rootVisualElement; VisualElement root = rootVisualElement;
// 加载布局文件 // 加载布局文件
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleDebuggerUXML; var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleDebuggerWindow>();
if (visualAsset == null) if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleDebuggerWindow)}.uxml in settings.");
return; return;
}
visualAsset.CloneTree(root); visualAsset.CloneTree(root);
// 采样按钮 // 采样按钮

View File

@ -24,12 +24,10 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
_visualAsset = YooAssetEditorSettingsData.Setting.DebuggerAssetListViewerUXML; _visualAsset = EditorHelper.LoadWindowUXML<DebuggerAssetListViewer>();
if (_visualAsset == null) if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(DebuggerAssetListViewer)}.uxml in settings.");
return; return;
}
_root = _visualAsset.CloneTree(); _root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f; _root.style.flexGrow = 1f;

View File

@ -24,12 +24,10 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
_visualAsset = YooAssetEditorSettingsData.Setting.DebuggerBundleListViewerUXML; _visualAsset = EditorHelper.LoadWindowUXML<DebuggerBundleListViewer>();
if (_visualAsset == null) if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(DebuggerBundleListViewer)}.uxml in settings.");
return; return;
}
_root = _visualAsset.CloneTree(); _root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f; _root.style.flexGrow = 1f;
@ -37,12 +35,12 @@ namespace YooAsset.Editor
_bundleListView = _root.Q<ListView>("TopListView"); _bundleListView = _root.Q<ListView>("TopListView");
_bundleListView.makeItem = MakeAssetListViewItem; _bundleListView.makeItem = MakeAssetListViewItem;
_bundleListView.bindItem = BindAssetListViewItem; _bundleListView.bindItem = BindAssetListViewItem;
#if UNITY_2020_1_OR_NEWER #if UNITY_2020_1_OR_NEWER
_bundleListView.onSelectionChange += BundleListView_onSelectionChange; _bundleListView.onSelectionChange += BundleListView_onSelectionChange;
#else #else
_bundleListView.onSelectionChanged += BundleListView_onSelectionChange; _bundleListView.onSelectionChanged += BundleListView_onSelectionChange;
#endif #endif
// 使用列表 // 使用列表
_usingListView = _root.Q<ListView>("BottomListView"); _usingListView = _root.Q<ListView>("BottomListView");
_usingListView.makeItem = MakeIncludeListViewItem; _usingListView.makeItem = MakeIncludeListViewItem;

View File

@ -55,12 +55,10 @@ namespace YooAsset.Editor
VisualElement root = this.rootVisualElement; VisualElement root = this.rootVisualElement;
// 加载布局文件 // 加载布局文件
var visualAsset = YooAssetEditorSettingsData.Setting.AssetBundleReporterUXML; var visualAsset = EditorHelper.LoadWindowUXML<AssetBundleReporterWindow>();
if (visualAsset == null) if (visualAsset == null)
{
Debug.LogError($"Not found {nameof(AssetBundleReporterWindow)}.uxml in settings.");
return; return;
}
visualAsset.CloneTree(root); visualAsset.CloneTree(root);
// 导入按钮 // 导入按钮

View File

@ -38,15 +38,10 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterAssetListViewerUXML; _visualAsset = EditorHelper.LoadWindowUXML<ReporterAssetListViewer>();
if (_visualAsset == null) if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(ReporterAssetListViewer)}.uxml in settings.");
return; return;
}
try
{
_root = _visualAsset.CloneTree(); _root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f; _root.style.flexGrow = 1f;
@ -74,11 +69,6 @@ namespace YooAsset.Editor
_dependListView.makeItem = MakeDependListViewItem; _dependListView.makeItem = MakeDependListViewItem;
_dependListView.bindItem = BindDependListViewItem; _dependListView.bindItem = BindDependListViewItem;
} }
catch (Exception e)
{
Debug.LogError(e.ToString());
}
}
/// <summary> /// <summary>
/// 填充页面数据 /// 填充页面数据

View File

@ -42,15 +42,10 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterBundleListViewerUXML; _visualAsset = EditorHelper.LoadWindowUXML<ReporterBundleListViewer>();
if (_visualAsset == null) if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(ReporterBundleListViewer)}.uxml in settings.");
return; return;
}
try
{
_root = _visualAsset.CloneTree(); _root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f; _root.style.flexGrow = 1f;
@ -82,16 +77,11 @@ namespace YooAsset.Editor
_includeListView.makeItem = MakeIncludeListViewItem; _includeListView.makeItem = MakeIncludeListViewItem;
_includeListView.bindItem = BindIncludeListViewItem; _includeListView.bindItem = BindIncludeListViewItem;
} }
catch (Exception e)
{
Debug.LogError(e.ToString());
}
}
/// <summary> /// <summary>
/// 填充页面数据 /// 填充页面数据
/// </summary> /// </summary>
public void FillViewData( BuildReport buildReport, string reprotFilePath, string searchKeyWord) public void FillViewData(BuildReport buildReport, string reprotFilePath, string searchKeyWord)
{ {
_buildReport = buildReport; _buildReport = buildReport;
_reportFilePath = reprotFilePath; _reportFilePath = reprotFilePath;

View File

@ -37,12 +37,10 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
_visualAsset = YooAssetEditorSettingsData.Setting.ReporterSummaryViewerUXML; _visualAsset = EditorHelper.LoadWindowUXML<ReporterSummaryViewer>();
if (_visualAsset == null) if (_visualAsset == null)
{
Debug.LogError($"Not found {nameof(ReporterSummaryViewer)}.uxml in settings.");
return; return;
}
_root = _visualAsset.CloneTree(); _root = _visualAsset.CloneTree();
_root.style.flexGrow = 1f; _root.style.flexGrow = 1f;

View File

@ -0,0 +1,83 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class EditorHelper
{
private readonly static Dictionary<System.Type, string> _uxmlDic = new Dictionary<System.Type, string>();
static EditorHelper()
{
// 资源包收集
_uxmlDic.Add(typeof(AssetBundleCollectorWindow), "355c4ac5cdebddc4c8362bed6f17a79e");
// 资源包构建
_uxmlDic.Add(typeof(AssetBundleBuilderWindow), "28ba29adb4949284e8c48893218b0d9a");
// 资源包调试
_uxmlDic.Add(typeof(AssetBundleDebuggerWindow), "790db12999afd334e8fb6ba70ef0a947");
_uxmlDic.Add(typeof(DebuggerAssetListViewer), "31c6096c1cb29b4469096b7b4942a322");
_uxmlDic.Add(typeof(DebuggerBundleListViewer), "932a25ffd05c13c47994d66e9d73bc37");
// 构建报告
_uxmlDic.Add(typeof(AssetBundleReporterWindow), "9052b72c383e95043a0c7e7f369b1ad7");
_uxmlDic.Add(typeof(ReporterSummaryViewer), "f8929271050855e42a1ccc6b14993a04");
_uxmlDic.Add(typeof(ReporterAssetListViewer), "5f81bc15a55ee0a49a266f9d71e2372b");
_uxmlDic.Add(typeof(ReporterBundleListViewer), "56d6dbe0d65ce334a8996beb19612989");
}
/// <summary>
/// 加载窗口的布局文件
/// </summary>
public static VisualTreeAsset LoadWindowUXML<TWindow>() where TWindow : class
{
var windowType = typeof(TWindow);
if (_uxmlDic.TryGetValue(windowType, out string uxmlGUID))
{
string assetPath = AssetDatabase.GUIDToAssetPath(uxmlGUID);
if (string.IsNullOrEmpty(assetPath))
throw new System.Exception($"Invalid YooAsset uxml guid : {uxmlGUID}");
var visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(assetPath);
if (visualTreeAsset == null)
throw new System.Exception($"Failed to load {windowType}.uxml");
return visualTreeAsset;
}
else
{
throw new System.Exception($"Invalid YooAsset window type : {windowType}");
}
}
/// <summary>
/// 加载相关的配置文件
/// </summary>
public static TSetting LoadSettingData<TSetting>() where TSetting : ScriptableObject
{
var settingType = typeof(TSetting);
var guids = AssetDatabase.FindAssets($"t:{settingType.Name}");
if (guids.Length == 0)
{
Debug.LogWarning($"Create new {settingType.Name}.asset");
var setting = ScriptableObject.CreateInstance<TSetting>();
string filePath = $"Assets/{settingType.Name}.asset";
AssetDatabase.CreateAsset(setting, filePath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
return setting;
}
else
{
if (guids.Length != 1)
throw new System.Exception($"Found multiple {settingType.Name} files !");
string filePath = AssetDatabase.GUIDToAssetPath(guids[0]);
var setting = AssetDatabase.LoadAssetAtPath<TSetting>(filePath);
return setting;
}
}
}
}

View File

@ -25,7 +25,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private static void LoadSettingData() private static void LoadSettingData()
{ {
_setting = YooAssetEditorSettingsHelper.LoadSettingData<ShaderVariantCollectorSetting>(); _setting = EditorHelper.LoadSettingData<ShaderVariantCollectorSetting>();
} }
/// <summary> /// <summary>

View File

@ -1,32 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4eff45040ac501b4fa978c46f72f2e64, type: 3}
m_Name: YooAssetEditorSettings
m_EditorClassIdentifier:
AssetBundleCollectorUXML: {fileID: 9197481963319205126, guid: 355c4ac5cdebddc4c8362bed6f17a79e,
type: 3}
AssetBundleBuilderUXML: {fileID: 9197481963319205126, guid: 28ba29adb4949284e8c48893218b0d9a,
type: 3}
AssetBundleDebuggerUXML: {fileID: 9197481963319205126, guid: 790db12999afd334e8fb6ba70ef0a947,
type: 3}
DebuggerAssetListViewerUXML: {fileID: 9197481963319205126, guid: 31c6096c1cb29b4469096b7b4942a322,
type: 3}
DebuggerBundleListViewerUXML: {fileID: 9197481963319205126, guid: 932a25ffd05c13c47994d66e9d73bc37,
type: 3}
AssetBundleReporterUXML: {fileID: 9197481963319205126, guid: 9052b72c383e95043a0c7e7f369b1ad7,
type: 3}
ReporterSummaryViewerUXML: {fileID: 9197481963319205126, guid: f8929271050855e42a1ccc6b14993a04,
type: 3}
ReporterAssetListViewerUXML: {fileID: 9197481963319205126, guid: 5f81bc15a55ee0a49a266f9d71e2372b,
type: 3}
ReporterBundleListViewerUXML: {fileID: 9197481963319205126, guid: 56d6dbe0d65ce334a8996beb19612989,
type: 3}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: b0b43f68477734743a5f2fc507b5bda6
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,25 +0,0 @@
using UnityEngine;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class YooAssetEditorSettings : ScriptableObject
{
// 资源包收集
public VisualTreeAsset AssetBundleCollectorUXML;
// 资源包构建
public VisualTreeAsset AssetBundleBuilderUXML;
// 资源包调试
public VisualTreeAsset AssetBundleDebuggerUXML;
public VisualTreeAsset DebuggerAssetListViewerUXML;
public VisualTreeAsset DebuggerBundleListViewerUXML;
// 构建报告
public VisualTreeAsset AssetBundleReporterUXML;
public VisualTreeAsset ReporterSummaryViewerUXML;
public VisualTreeAsset ReporterAssetListViewerUXML;
public VisualTreeAsset ReporterBundleListViewerUXML;
}
}

View File

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

View File

@ -1,35 +0,0 @@
using UnityEngine;
using UnityEditor;
namespace YooAsset.Editor
{
public class YooAssetEditorSettingsData
{
private static YooAssetEditorSettings _setting = null;
public static YooAssetEditorSettings Setting
{
get
{
if (_setting == null)
LoadEditorSettingData();
return _setting;
}
}
/// <summary>
/// 加载配置文件
/// </summary>
private static void LoadEditorSettingData()
{
var guids = AssetDatabase.FindAssets($"t:{nameof(YooAssetEditorSettings)}", new[] { "Assets", "Packages" });
if (guids.Length == 0)
throw new System.Exception($"Not found {nameof(YooAssetEditorSettings)} file !");
if (guids.Length != 1)
throw new System.Exception($"Found multiple {nameof(YooAssetEditorSettings)} files !");
string settingFilePath = AssetDatabase.GUIDToAssetPath(guids[0]);
_setting = AssetDatabase.LoadAssetAtPath<YooAssetEditorSettings>(settingFilePath);
Debug.Log($"Load {nameof(YooAssetEditorSettings)}.asset ok !");
}
}
}

View File

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

View File

@ -1,36 +0,0 @@
using UnityEngine;
using UnityEditor;
namespace YooAsset.Editor
{
public class YooAssetEditorSettingsHelper
{
/// <summary>
/// 加载相关的配置文件
/// </summary>
public static TSetting LoadSettingData<TSetting>() where TSetting : ScriptableObject
{
var settingType = typeof(TSetting);
var guids = AssetDatabase.FindAssets($"t:{settingType.Name}");
if (guids.Length == 0)
{
Debug.LogWarning($"Create new {settingType.Name}.asset");
var setting = ScriptableObject.CreateInstance<TSetting>();
string filePath = $"Assets/{settingType.Name}.asset";
AssetDatabase.CreateAsset(setting, filePath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
return setting;
}
else
{
if (guids.Length != 1)
throw new System.Exception($"Found multiple {settingType.Name} files !");
string filePath = AssetDatabase.GUIDToAssetPath(guids[0]);
var setting = AssetDatabase.LoadAssetAtPath<TSetting>(filePath);
return setting;
}
}
}
}