Version: 2022.3
public static bool IsValidFolder (string path);

参数

path 文件夹的路径。

返回

bool 如果文件夹存在,则返回 true。

描述

给定文件夹的路径,如果存在,则返回 true;否则,返回 false。

给定路径是相对于项目文件夹的路径。

using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class AssetDatabaseExamples : MonoBehaviour { [MenuItem("AssetDatabase/Create Folder Structure")] static void CreateFolderStructure() { var folderList = new List<string> { "Animations", "Textures", "Materials", "Prefabs", "Resources", "Scripts" };

//Check if folder exists with IsValidFolder if it doesn't create it foreach (var folder in folderList) { if (AssetDatabase.IsValidFolder($"Assets/{folder}")) continue; AssetDatabase.CreateFolder("Assets", folder); } } }