1. 程式人生 > >unity動態建立資料夾

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

下面是執行專案後的效果:
這裡寫圖片描述