Update EditorTools.cs

修复Assets目录下存在多个YooAsset同名文件夹时,工具窗口无法显示的问题。
修复通过Packages导入YooAsset,工具窗口无法显示的问题。
pull/4/head
hevinci 2022-04-07 10:17:42 +08:00
parent 25088918d3
commit 0d7c93ac55
1 changed files with 37 additions and 23 deletions

View File

@ -15,7 +15,7 @@ namespace YooAsset.Editor
/// </summary>
public static class EditorTools
{
#region Assembly
#region Assembly
/// <summary>
/// 调用私有的静态方法
/// </summary>
@ -49,9 +49,9 @@ namespace YooAsset.Editor
}
return methodInfo.Invoke(null, parameters);
}
#endregion
#endregion
#region EditorUtility
#region EditorUtility
/// <summary>
/// 搜集资源
/// </summary>
@ -156,9 +156,9 @@ namespace YooAsset.Editor
{
EditorUtility.ClearProgressBar();
}
#endregion
#endregion
#region EditorWindow
#region EditorWindow
public static void FocusUnitySceneWindow()
{
EditorWindow.FocusWindowIfItsOpen<SceneView>();
@ -188,9 +188,9 @@ namespace YooAsset.Editor
System.Type T = Assembly.Load("UnityEditor").GetType("UnityEditor.ConsoleWindow");
EditorWindow.GetWindow(T, false, "Console", true);
}
#endregion
#endregion
#region 控制台
#region 控制台
private static MethodInfo _clearConsoleMethod;
private static MethodInfo ClearConsoleMethod
{
@ -213,9 +213,9 @@ namespace YooAsset.Editor
{
ClearConsoleMethod.Invoke(new object(), null);
}
#endregion
#endregion
#region 文件
#region 文件
/// <summary>
/// 创建文件所在的目录
/// </summary>
@ -409,9 +409,9 @@ namespace YooAsset.Editor
else
return Encoding.UTF8.GetString(bytes.ToArray());
}
#endregion
#endregion
#region 路径
#region 路径
private static string YooAssetPath;
/// <summary>
@ -430,26 +430,40 @@ namespace YooAsset.Editor
if (string.IsNullOrEmpty(YooAssetPath) == false)
return YooAssetPath;
string packagesPath = ("Packages/com.tuyoo.yooasset/README.md");
// 从Pakcages目录下搜索
string packagesPath = ("Packages/com.tuyoogame.yooasset/README.md");
var obj = AssetDatabase.LoadAssetAtPath(packagesPath, typeof(TextAsset));
if(obj != null)
if (obj != null)
{
YooAssetPath = "Packages/com.tuyoo.yooasset/";
YooAssetPath = "Packages/com.tuyoogame.yooasset/";
return YooAssetPath;
}
// 从Assets目录下搜索
string[] allDirectorys = Directory.GetDirectories(Application.dataPath, "YooAsset", SearchOption.AllDirectories);
if (allDirectorys.Length == 0)
{
Debug.LogError("Not found YooAsset Folder!");
Debug.LogError("Not found YooAsset Package !");
return string.Empty;
}
if (allDirectorys.Length > 1)
string targetDirectory = string.Empty;
foreach (var directory in allDirectorys)
{
Debug.LogError("Found multiple YooAsset Folders!");
string asmdefFilePath = $"{directory}/Editor/YooAsset.Editor.asmdef";
if (File.Exists(asmdefFilePath))
{
targetDirectory = directory;
break;
}
}
if (string.IsNullOrEmpty(targetDirectory))
{
Debug.LogError("Should never get here !");
return string.Empty;
}
YooAssetPath = AbsolutePathToAssetPath(allDirectorys[0]);
YooAssetPath = AbsolutePathToAssetPath(targetDirectory);
return YooAssetPath;
}
@ -504,9 +518,9 @@ namespace YooAsset.Editor
}
return string.Empty;
}
#endregion
#endregion
#region 字符串
#region 字符串
/// <summary>
/// 是否含有中文
/// </summary>
@ -567,9 +581,9 @@ namespace YooAsset.Editor
else
return content.Substring(startIndex + key.Length);
}
#endregion
#endregion
#region 玩家偏好
#region 玩家偏好
// 枚举
public static void PlayerSetEnum<T>(string key, T value)
{
@ -581,6 +595,6 @@ namespace YooAsset.Editor
string enumName = EditorPrefs.GetString(key, defaultValue.ToString());
return StringUtility.NameToEnum<T>(enumName);
}
#endregion
#endregion
}
}