Unity中動態建立資料夾
本文章由cartzhang編寫,轉載請註明出處。 所有權利保留。
文章連結:http://blog.csdn.net/cartzhang/article/details/50474664
作者:cartzhang
Unity中一鍵建立常用資料夾
說明
專案測試版本Unity5.3。
這個一個小工具;功能非常簡單,就是一鍵給新建工程新增所有資料夾。到此結束。
但是具體咋操作呢?
與把大象裝進冰箱一樣,三步,下載程式碼,把程式碼放到工程中,點選工具下的建立按鈕。
一、下載程式碼
哪裡有程式碼啊?下面會給出下載地址。
http://download.csdn.net/detail/cartzhang/9393932
也可以直接負責貼上,
程式碼如下:
/**************************************************************************
Copyright:@cartzhang
Author: cartzhang
Date:[2016/1/6]
Description:
**************************************************************************/
using UnityEngine;
using System.Collections;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class GenerateFolders : MonoBehaviour
{
#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
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
程式碼很簡單。
當然也可以從這裡下載:
下載地址:http://download.csdn.net/detail/cartzhang/9393932
二、使用
使用就有很簡單。
首先,需要把下載或編寫的程式碼放到工程中,放哪裡呢?原理上放哪裡都可以,隨你喜歡。
本例測試過程中,就放在了工程最外層:如下圖:
在選單中,會發現已經有了一個新的Tools選項,下面有兩個可選項。如下圖:
然後就會發現,工程Project中已經建立了你需要的基礎資料夾,如下圖:
這時候,你想建立更多資料夾,也可以點選下面的CreateALLFolder,當然,若這樣,你還覺得與你的使用習慣不一樣,你可以到程式碼中修改。
在private static void GenerateFolder(int flag = 0) 函式中,
一目瞭然,自由新增你想要或去掉你不想要的資料夾。是不是很方便呢?!!!
三、問題
這樣,檔案就來了,要是我之前建立的資料夾中,有自己已經做的檔案或材質,紋理等,會給覆蓋掉麼?
答案是,不會的。我這邊測試的結果是,資料夾中存在的東西依舊會存在不會做更改。
——-THE———END——————
---------------------
作者:cartzhang
來源:CSDN
原文:https://blog.csdn.net/cartzhang/article/details/50474664
版權宣告:本文為博主原創文章,轉載請附上博文連結!