From 6d150933fdb5639cc259ea58e95b087ede55931f Mon Sep 17 00:00:00 2001 From: coffee <985942825@qq.com> Date: Thu, 2 Jan 2025 00:21:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E9=80=89=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Unity-Tools/Core/Editor/DirectoryUtil.cs | 68 +++++++++++++++++++ .../Core/Editor/DirectoryUtil.cs.meta | 3 + .../Editor/ExcelResolverEditorConfig.asset | 3 +- .../Editor/ExcelResolverEditorConfig.cs | 4 +- 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 Assets/Unity-Tools/Core/Editor/DirectoryUtil.cs create mode 100644 Assets/Unity-Tools/Core/Editor/DirectoryUtil.cs.meta diff --git a/Assets/Unity-Tools/Core/Editor/DirectoryUtil.cs b/Assets/Unity-Tools/Core/Editor/DirectoryUtil.cs new file mode 100644 index 0000000..2106e4b --- /dev/null +++ b/Assets/Unity-Tools/Core/Editor/DirectoryUtil.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using UnityEngine; + +namespace Tools.Editor +{ + /// + /// 目录操作的工具类。 + /// + public static class DirectoryUtil + { + /// + /// 确保指定的目录存在。如果不存在,则创建该目录。 + /// + /// 要检查或创建的目录路径。 + public static void MakeSureDirectory(string path) + { + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + } + + /// + /// 获取 "Assets/" 文件夹中所有目录的文件路径,排除某些目录。 + /// + /// 文件路径的可枚举集合。 + public static IEnumerable GetFilePaths() + { + var dirs = Directory.GetDirectories("Assets/", "*", SearchOption.AllDirectories); + var filterList = dirs.Where(file => + !file.Contains(".git") && + !file.Contains("Plugins") && + !file.Contains("Scenes") + ).Select(file => file.Replace('\\', '/')).ToHashSet(); + return filterList; + } + + /// + /// 从指定路径中提取文件或目录的名称。 + /// + /// 要提取名称的路径。 + /// 提取的名称。 + public static string ExtractName(string path) + { + var startIndex1 = path.LastIndexOf("/", StringComparison.Ordinal) + 1; + var startIndex2 = path.LastIndexOf("\\", StringComparison.Ordinal) + 1; + var startIndex = Mathf.Max(startIndex1, startIndex2); + var endIndex = path.LastIndexOf(".", StringComparison.Ordinal); + return endIndex == -1 ? path[startIndex..] : path[startIndex..endIndex]; + } + + /// + /// 从指定路径中提取文件夹路径。 + /// + /// 要提取文件夹路径的路径。 + /// 提取的文件夹路径。 + public static string ExtractFolder(string path) + { + var endIndex1 = path.LastIndexOf("/", StringComparison.Ordinal); + var endIndex2 = path.LastIndexOf("\\", StringComparison.Ordinal); + var endIndex = Mathf.Max(endIndex1, endIndex2); + return path[..endIndex]; + } + } +} \ No newline at end of file diff --git a/Assets/Unity-Tools/Core/Editor/DirectoryUtil.cs.meta b/Assets/Unity-Tools/Core/Editor/DirectoryUtil.cs.meta new file mode 100644 index 0000000..4e814fd --- /dev/null +++ b/Assets/Unity-Tools/Core/Editor/DirectoryUtil.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a9cf985844984893aa10d114d8710d0d +timeCreated: 1735748052 \ No newline at end of file diff --git a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorConfig.asset b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorConfig.asset index fc0bf4e..490fb01 100644 --- a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorConfig.asset +++ b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorConfig.asset @@ -12,4 +12,5 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9247b1b02271436ca893eadb1fa8bdce, type: 3} m_Name: ExcelResolverEditorConfig m_EditorClassIdentifier: - ExcelPath: + ExcelPath: Assets/Unity-Tools/Core/ExcelResolver/Editor + JsonPath: diff --git a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorConfig.cs b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorConfig.cs index 9e23e85..3932571 100644 --- a/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorConfig.cs +++ b/Assets/Unity-Tools/Core/ExcelResolver/Editor/ExcelResolverEditorConfig.cs @@ -4,9 +4,11 @@ using UnityEngine; namespace Tools.ExcelResolver.Editor { [InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)] - public class ExcelResolverEditorConfig : ScriptableObject + public sealed class ExcelResolverEditorConfig : ScriptableObject { + [ValueDropdown("@Tools.Editor.DirectoryUtil.GetFilePaths()")] public string ExcelPath; + [FolderPath] public string JsonPath; } } \ No newline at end of file