【发布时间】:2020-06-03 05:40:29
【问题描述】:
string selectedPath = GetPath();
var subFolders = AssetDatabase.GetSubFolders(selectedPath);
List<string> paths = new List<string>();
foreach(string path in subFolders)
{
paths.Add(path);
}
例如 subFolders 是 Assets/My Folder 但在我的文件夹下还有更多的子文件夹。
AssetDatabase.GetSubFolders 不会进行递归,它只获取第一个子文件夹。 我想让所有子文件夹递归。
我试过了:
列表路径 = new List(); foreach(子文件夹中的字符串路径) { 路径。添加(路径); }
但它仍然只给我第一个子文件夹。
这就是我在资产中获取所选路径名的方式:
[MenuItem("Assets/Get Path")]
private static string GetClickedDirFullPath()
{
string clickedAssetGuid = Selection.assetGUIDs[0];
string clickedPath = AssetDatabase.GUIDToAssetPath(clickedAssetGuid);
string clickedPathFull = Path.Combine(Directory.GetCurrentDirectory(), clickedPath);
FileAttributes attr = File.GetAttributes(clickedPathFull);
return attr.HasFlag(FileAttributes.Directory) ? clickedPathFull : Path.GetDirectoryName(clickedPathFull);
}
[MenuItem("Assets/Get Path")]
private static string GetPath()
{
string path = GetClickedDirFullPath();
int index = path.IndexOf("Assets");
string result = path.Substring(index);
return result;
}
【问题讨论】: