Version: 2022.2
public static string[] GetSubFolders (string path);

描述

给定 Assets 文件夹中目录相对于项目文件夹的路径,此方法将返回其所有子目录的数组。

using UnityEditor;
using UnityEngine;

public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Get Folder List")] static void SubFolderExample() { //This method prints out the entire folder list of a project into the console var folders = AssetDatabase.GetSubFolders("Assets"); foreach (var folder in folders) { Recursive(folder); } }

static void Recursive(string folder) { Debug.Log(folder); var folders = AssetDatabase.GetSubFolders(folder); foreach (var fld in folders) { Recursive(fld); } } }