1.一键创建unity所必须的基础文件夹
2.节省工作量,提升效率
3.杜绝命名出错,因为有些文件夹是必须拼写正确才能正常运行 例如:Resources等
代码:
using UnityEngine;
using System.Collections;
using System.IO;
#if UNITY_EDITOR
using UnityEditor;
#endif
/// <summary>
///
/// Directory.CreateDirectory的内部原理是存在文件则不创建,不存在才创建
/// </summary>
public class GenerateFolders : MonoBehaviour
{
#if UNITY_EDITOR
static string folderRoot = "Game";
[MenuItem("Tools/CreateBaseFolder")]
private static void CreateBaseFolder()
{
GenerateFolder(0);
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 + "/" + folderRoot + "/";
Directory.CreateDirectory(prjPath + "Animations");//动作片段
Directory.CreateDirectory(prjPath + "FX"); //特效
Directory.CreateDirectory(prjPath + "Materials"); //材质
Directory.CreateDirectory(prjPath + "Models"); //模型
Directory.CreateDirectory(prjPath + "Prefabs"); //预设体
Directory.CreateDirectory(prjPath + "Textures"); //纹理图片
Directory.CreateDirectory(prjPath + "Scenes"); //场景
Directory.CreateDirectory(prjPath + "Scripts"); //脚本
if (1 == flag)
{
Directory.CreateDirectory(prjPath + "Standard Assets");
Directory.CreateDirectory(prjPath + "Editor");//
Directory.CreateDirectory(prjPath + "Sprites");//
Directory.CreateDirectory(prjPath + "Images");//
Directory.CreateDirectory(prjPath + "Audios");//音效 Music(音乐相关的部分)/ SFX(特效音乐相关的部分)
Directory.CreateDirectory(prjPath + "Fonts"); //字体
Directory.CreateDirectory(prjPath + "Shaders"); //着色器
Directory.CreateDirectory(prjPath + "Plugins"); //
Directory.CreateDirectory(prjPath + "Resources"); //需要动态加载的资源放在这里,不管有没有使用都会全部打包
Directory.CreateDirectory(prjPath + "StreamingAssets"); //这个目录将自动打包到导出程序,用Application.streamingAssetsPath读取
Directory.CreateDirectory(prjPath + "Gizmos");
Directory.CreateDirectory(prjPath + "Others");
}
AssetDatabase.Refresh();
}
#endif
}