From 0d7c93ac5564d483cc002cde86432939c37b8cdf Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 7 Apr 2022 10:17:42 +0800 Subject: [PATCH] Update EditorTools.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复Assets目录下存在多个YooAsset同名文件夹时,工具窗口无法显示的问题。 修复通过Packages导入YooAsset,工具窗口无法显示的问题。 --- Assets/YooAsset/Editor/EditorTools.cs | 60 +++++++++++++++++---------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/Assets/YooAsset/Editor/EditorTools.cs b/Assets/YooAsset/Editor/EditorTools.cs index 9e9eb6c..0f77e0a 100644 --- a/Assets/YooAsset/Editor/EditorTools.cs +++ b/Assets/YooAsset/Editor/EditorTools.cs @@ -15,7 +15,7 @@ namespace YooAsset.Editor /// public static class EditorTools { -#region Assembly + #region Assembly /// /// 调用私有的静态方法 /// @@ -49,9 +49,9 @@ namespace YooAsset.Editor } return methodInfo.Invoke(null, parameters); } -#endregion + #endregion -#region EditorUtility + #region EditorUtility /// /// 搜集资源 /// @@ -156,9 +156,9 @@ namespace YooAsset.Editor { EditorUtility.ClearProgressBar(); } -#endregion + #endregion -#region EditorWindow + #region EditorWindow public static void FocusUnitySceneWindow() { EditorWindow.FocusWindowIfItsOpen(); @@ -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 文件 /// /// 创建文件所在的目录 /// @@ -409,9 +409,9 @@ namespace YooAsset.Editor else return Encoding.UTF8.GetString(bytes.ToArray()); } -#endregion + #endregion -#region 路径 + #region 路径 private static string YooAssetPath; /// @@ -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 字符串 /// /// 是否含有中文 /// @@ -567,9 +581,9 @@ namespace YooAsset.Editor else return content.Substring(startIndex + key.Length); } -#endregion + #endregion -#region 玩家偏好 + #region 玩家偏好 // 枚举 public static void PlayerSetEnum(string key, T value) { @@ -581,6 +595,6 @@ namespace YooAsset.Editor string enumName = EditorPrefs.GetString(key, defaultValue.ToString()); return StringUtility.NameToEnum(enumName); } -#endregion + #endregion } } \ No newline at end of file