Update EditorHelper.cs

pull/13/head
hevinci 2022-05-22 15:03:40 +08:00
parent ddb35620cb
commit b1ca47fc14
1 changed files with 4 additions and 3 deletions

View File

@ -2,12 +2,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using UnityEngine.UIElements;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class EditorHelper public class EditorHelper
{ {
#if UNITY_2019_4_OR_NEWER
private readonly static Dictionary<System.Type, string> _uxmlDic = new Dictionary<System.Type, string>(); private readonly static Dictionary<System.Type, string> _uxmlDic = new Dictionary<System.Type, string>();
static EditorHelper() static EditorHelper()
@ -33,7 +33,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 加载窗口的布局文件 /// 加载窗口的布局文件
/// </summary> /// </summary>
public static VisualTreeAsset LoadWindowUXML<TWindow>() where TWindow : class public static UnityEngine.UIElements.VisualTreeAsset LoadWindowUXML<TWindow>() where TWindow : class
{ {
var windowType = typeof(TWindow); var windowType = typeof(TWindow);
if (_uxmlDic.TryGetValue(windowType, out string uxmlGUID)) if (_uxmlDic.TryGetValue(windowType, out string uxmlGUID))
@ -41,7 +41,7 @@ namespace YooAsset.Editor
string assetPath = AssetDatabase.GUIDToAssetPath(uxmlGUID); string assetPath = AssetDatabase.GUIDToAssetPath(uxmlGUID);
if (string.IsNullOrEmpty(assetPath)) if (string.IsNullOrEmpty(assetPath))
throw new System.Exception($"Invalid YooAsset uxml guid : {uxmlGUID}"); throw new System.Exception($"Invalid YooAsset uxml guid : {uxmlGUID}");
var visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(assetPath); var visualTreeAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.UIElements.VisualTreeAsset>(assetPath);
if (visualTreeAsset == null) if (visualTreeAsset == null)
throw new System.Exception($"Failed to load {windowType}.uxml"); throw new System.Exception($"Failed to load {windowType}.uxml");
return visualTreeAsset; return visualTreeAsset;
@ -51,6 +51,7 @@ namespace YooAsset.Editor
throw new System.Exception($"Invalid YooAsset window type : {windowType}"); throw new System.Exception($"Invalid YooAsset window type : {windowType}");
} }
} }
#endif
/// <summary> /// <summary>
/// 加载相关的配置文件 /// 加载相关的配置文件