unity动态创建文件夹

在做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

下面是运行项目后的效果:
unity动态创建文件夹_第1张图片

你可能感兴趣的:(unity3D)