diff options
Diffstat (limited to 'Erika/Assets/Tools/ActionTool/Editor/ActionToolUtils.cs')
-rw-r--r-- | Erika/Assets/Tools/ActionTool/Editor/ActionToolUtils.cs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Erika/Assets/Tools/ActionTool/Editor/ActionToolUtils.cs b/Erika/Assets/Tools/ActionTool/Editor/ActionToolUtils.cs new file mode 100644 index 00000000..a02c2ecc --- /dev/null +++ b/Erika/Assets/Tools/ActionTool/Editor/ActionToolUtils.cs @@ -0,0 +1,68 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + public static class ActionToolUtils + { + + public static string GetParentFolder(string fileOrFolder) + { + string path = fileOrFolder.Replace("\\", "/"); + if (path.LastIndexOf('/') == path.Length - 1) // 表明是文件夹,trim 最后一个 / + { + path = path.TrimEnd('/'); + } + int end = path.LastIndexOf('/'); + string folder = path.Substring(0, end + 1); + return folder; + } + + public static string GetFolderName(string path) + { + string folder = path.TrimEnd('/'); + int end = folder.LastIndexOf('/'); + folder = folder.Substring(end + 1, folder.Length - end - 1); + return folder; + } + + public static bool IsValidFolder(string path) + { + path = path.Trim('/'); + return AssetDatabase.IsValidFolder(path); + } + + public static void CreateFolder(string parent, string folderName) + { + parent = parent.Trim('/'); + AssetDatabase.CreateFolder(parent, folderName); + } + + /// <summary> + /// 递归创建父文件夹,知道此文件夹创建成功 + /// </summary> + /// <param name="folder"></param> + /// <returns></returns> + public static void CreateFolder(string folder) + { + if (IsValidFolder(folder)) + { + return; + } + string parent = GetParentFolder(folder); + if(IsValidFolder(parent)) + { + string name = GetFolderName(folder); + CreateFolder(parent, name); + } + else + { + CreateFolder(parent); + CreateFolder(folder); + } + } + + } +} |