unity动态创建文件夹

xiaoxiao2021-02-27  301

在做unity项目中,首先要创建好分类的文件夹,现在通过写代码的方式减少了手动创建文件夹这一步骤;

private void Start() { CreateBasicFolder(); } #if UNITY_EDITOR [MenuItem("Tools/CreateBasicFolder #&_b")] private static void CreateBasicFolder() { GenerateFolder(); Debug.Log("Folders Created"); } [MenuItem("Tools/CreateALLFolder")] private static void CreateAllFolder() { GenerateFolder(1); Debug.Log("Folders Created"); } private static void GenerateFolder(int flag = 0) { // 文件路径 string prjPath = Application.dataPath + "/"; Directory.CreateDirectory(prjPath + "Audio"); Directory.CreateDirectory(prjPath + "Prefabs"); Directory.CreateDirectory(prjPath + "Materials"); Directory.CreateDirectory(prjPath + "Resources"); Directory.CreateDirectory(prjPath + "Scripts"); Directory.CreateDirectory(prjPath + "Textures"); Directory.CreateDirectory(prjPath + "Scenes"); if (1== flag) { Directory.CreateDirectory(prjPath + "Meshes"); Directory.CreateDirectory(prjPath + "Shaders"); Directory.CreateDirectory(prjPath + "GUI"); } AssetDatabase.Refresh(); } #endif

下面是运行项目后的效果:

转载请注明原文地址: https://www.6miu.com/read-4369.html

最新回复(0)