700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 创建一些特定的目录结构

创建一些特定的目录结构

时间:2022-11-01 23:57:42

相关推荐

创建一些特定的目录结构

如果做固定开发,经常会遇到一些固定模式,例如开发某个功能,要创建对应的文件夹,名字都是有套路的,此时就可以使用工具来一键生成,节省时间。

/*--------------------------------------------------------------------

Author Name: DXLCreation Time: .1.15File Describe: 创建场景的结构路径,用于新场景开发------------------------------------------------------------------*/

using System.Collections;

using System.Collections.Generic;

using System.IO;

using UnityEditor;

using UnityEngine;

using LogPrint;

using System.Text;

public class CreateScenePath

{

static EditorWindow m_singleSceneWindow;

//开发新场景时直接创建对应结构目录 public static void CreateSceneFile(string scene){//------------------------都在Assets文件夹下-------------//1、先检测AnimationFile的XXX_Ani文件夹string animaAni = Application.dataPath + "/AnimationFile" + "/" + scene + "_Ani";if (!Directory.Exists(animaAni)){//创建一个文件夹Directory.CreateDirectory(animaAni);}//2、创建Prefab下的XXX_Prefab文件夹 string scenePrefab = Application.dataPath + "/Prefab" + "/" + scene + "_Prefab";if (!Directory.Exists(scenePrefab)){//创建一个文件夹Directory.CreateDirectory(scenePrefab);}//3、创建Sound下的XXX_Sound文件夹 string sceneSound = Application.dataPath + "/Sound" + "/" + scene + "_Sound";if (!Directory.Exists(sceneSound)){//创建一个文件夹Directory.CreateDirectory(sceneSound);}//4、创建Texture下的XXX_Texture文件夹 string sceneTexture = Application.dataPath + "/Texture" + "/" + scene + "_Texture";if (!Directory.Exists(sceneTexture)){//创建一个文件夹Directory.CreateDirectory(sceneTexture);}//Texture文件夹中的BackGround文件夹string textureBG = sceneTexture + "/BackGround";if (!Directory.Exists(textureBG)){//创建一个文件夹Directory.CreateDirectory(textureBG);}//Texture文件夹中的UI文件夹string textureUI = sceneTexture + "/UI";if (!Directory.Exists(textureUI)){//创建一个文件夹Directory.CreateDirectory(textureUI);}//7、Script文件夹 \Scripts\SceneLogic\ XXXstring scriptFloder = Application.dataPath + "/Scripts/SceneLogic/" + scene;if (!Directory.Exists(scriptFloder)){//创建一个文件夹Directory.CreateDirectory(scriptFloder);}//5、ConfigXlsx文件夹下的XXXModel.xlsx文件和XXXScene.xlsx文件,就手动创建吧,因为里面包含特殊字段//6、Resources/TestScene文件夹下对应的XXX_Prefab也手动创建,这个要等运行时手动拖动m_singleSceneWindow.Close();AssetDatabase.Refresh();Debug.Log(scene + " Struct Path create success!");}//打开界面[MenuItem("HideUIRaycast/CreateSceneStructurePath")]private static void ShowWindow(){m_singleSceneWindow = EditorWindow.GetWindowWithRect(typeof(CreateSceneWindow), new Rect(0, 0, 400, 600), true, "SingleSceneWindow");}//打开测试界面 public static void ShowSceneInfoWindow(){if (m_singleSceneWindow) m_singleSceneWindow.Close();m_singleSceneWindow = EditorWindow.GetWindowWithRect(typeof(SceneInfoWindow), new Rect(0, 0, 400, 600), true, "SingleSceneWindow");}//Spine资源地址static string modelSourcePath = Application.dataPath + "/AnimationFile" + "/" + "FourElves" + "_Ani";//Audio资源地址static string audioSourcePath = Application.dataPath + "/Sound" + "/" + "FourElves" + "_Sound";//测试场景ModelExcel地址static string testModelExcelPath = Application.dataPath + "/ConfigXlsx/Model/" + "LittlePoliceModel.xlsx";//测试场景SceneExcel地址static string testSceneExcelPath = Application.dataPath + "/ConfigXlsx/Scene/" + "LittlePoliceScene.xlsx";//练习场景ModelExcel地址static string practiceModelExcelPath = Application.dataPath + "/ConfigXlsx/Model/" + "TakenModel.xlsx";//练习场景SceneExcel地址static string practiceSceneExcelPath = Application.dataPath + "/ConfigXlsx/Scene/" + "TakenScene.xlsx";//KeepBg预制体的地址static string keepBgPath = Application.dataPath + "/Prefab" + "/" + "FourElves" + "_Prefab/KeepBg.prefab";static int createFileNum; //创建文件的数量//传递3个参数,场景名字,要创建的模型名字,是否是测试场景(如果不是,就是练习场景)public static void CreateSceneFile2(string scene, List<string> modelList, bool isTestScene){//------------------------都在Assets文件夹下-------------createFileNum = 0;//1、先检测AnimationFile的XXX_Ani文件夹string animaAni = Application.dataPath + "/AnimationFile" + "/" + scene + "_Ani";if (!Directory.Exists(animaAni)){//创建一个文件夹Directory.CreateDirectory(animaAni);createFileNum++;}//1.2创建AnimationFile下的模型资源 for (int i = 0; i < modelList.Count; ++i){if (!Directory.Exists(animaAni + "/" + modelList[i])){Directory.CreateDirectory(animaAni + "/" + modelList[i]);createFileNum++;}CopyAniFile(scene, modelList[i]);}//2、创建Prefab下的XXX_Prefab文件夹 string scenePrefab = Application.dataPath + "/Prefab" + "/" + scene + "_Prefab";if (!Directory.Exists(scenePrefab)){//创建一个文件夹Directory.CreateDirectory(scenePrefab);createFileNum++;}//3、创建Sound下的XXX_Sound文件夹 string sceneSound = Application.dataPath + "/Sound" + "/" + scene + "_Sound";if (!Directory.Exists(sceneSound)){//创建一个文件夹Directory.CreateDirectory(sceneSound);createFileNum++;}//3.2创建下面对应的子文件夹for (int i = 0; i < modelList.Count; ++i){if (!Directory.Exists(sceneSound + "/" + modelList[i])){//创建一个文件夹Directory.CreateDirectory(sceneSound + "/" + modelList[i]);createFileNum++;}}//3.3 将一些经常用到的音效文件,例如ClickEffect.mp3这样音效复制进来if (!Directory.Exists(sceneSound + "/BasicAudio")){//创建一个文件夹Directory.CreateDirectory(sceneSound + "/BasicAudio");createFileNum++;}CopyAudioFile(scene);//4、创建Texture下的XXX_Texture文件夹 string sceneTexture = Application.dataPath + "/Texture" + "/" + scene + "_Texture";if (!Directory.Exists(sceneTexture)){//创建一个文件夹Directory.CreateDirectory(sceneTexture);createFileNum++;}//Texture文件夹中的BackGround文件夹string textureBG = sceneTexture + "/BackGround";if (!Directory.Exists(textureBG)){//创建一个文件夹Directory.CreateDirectory(textureBG);createFileNum++;}//Texture文件夹中的UI文件夹string textureUI = sceneTexture + "/UI";if (!Directory.Exists(textureUI)){//创建一个文件夹Directory.CreateDirectory(textureUI);createFileNum++;}//7、Script文件夹 \Scripts\SceneLogic\ XXXstring scriptFloder = Application.dataPath + "/Scripts/SceneLogic/" + scene;if (!Directory.Exists(scriptFloder)){//创建一个文件夹Directory.CreateDirectory(scriptFloder);createFileNum++;}//7.2创建对应 的cs脚本文件CreateScriptFile(scene, scriptFloder);//5、创建对应的Excel文件CreateExcelFile(scene, isTestScene);//6、创建经常用的 Prefab预制体CreatePrefab(scene);if (createFileNum > 0){Debug.Log(scene + " Struct Path create " + createFileNum + " filse success!");}else{Debug.Log(scene + " had already been created,so not create new file");}m_singleSceneWindow.Close();AssetDatabase.Refresh();//这里可以创建对应的Spine预制体和打图集 todo}//复制Spine的资源static void CopyAniFile(string sceneName, string targetDirName){//获取文件夹下所有文件string[] files = Directory.GetFiles(modelSourcePath + "/" + targetDirName);for (int j = 0; j < files.Length; ++j){if (files[j].Contains(".meta")){continue;}string target = files[j].Replace("FourElves_Ani", sceneName + "_Ani");if (files[j].Contains(".atlas.txt")){//这里要检测是否已经存在当前文件了,正常情况下是没有的if (!File.Exists(target)){File.Copy(files[j], target);createFileNum++;}}else if (files[j].Contains(".json")){if (!File.Exists(target)){File.Copy(files[j], target);createFileNum++;}}else if (files[j].Contains(".png")){if (!File.Exists(target)){File.Copy(files[j], target);createFileNum++;}}else if (files[j].Contains(".controller")){if (!File.Exists(target)){File.Copy(files[j], target);createFileNum++;}}}}//复制mp3文件到目录中static void CopyAudioFile(string sceneName){string[] files = Directory.GetFiles(audioSourcePath);for (int i = 0; i < files.Length; ++i){//这里仅仅针对mp3资源,ogg音效暂时不考虑if (files[i].Contains("meta") || !files[i].Contains("mp3")){continue;}string target = files[i].Replace("FourElves_Sound", sceneName + "_Sound/BasicAudio");if (!File.Exists(target)){File.Copy(files[i], target);createFileNum++;}}}//创建一个cs脚本文件static void CreateScriptFile(string sceneName, string scriptFolderPath){if (!File.Exists(scriptFolderPath + "/" + sceneName + "Scene.cs")){using (FileStream fs = new FileStream(scriptFolderPath + "/" + sceneName + "Scene.cs", FileMode.Create, FileAccess.Write)){StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("UTF-8"));sw.WriteLine("using System.Collections;");sw.WriteLine("using System.Collections.Generic;");sw.WriteLine("using UnityEngine;");sw.WriteLine("");sw.WriteLine("public class " + sceneName + "Scene : MonoBehaviour");sw.WriteLine("{");sw.WriteLine("");sw.WriteLine("\t#region variable");sw.WriteLine("");sw.WriteLine("\t#endregion");sw.WriteLine("");sw.WriteLine("\t#region ui");sw.WriteLine("");sw.WriteLine("\tvoid Start ()");sw.WriteLine("\t{");sw.WriteLine("");sw.WriteLine("\t}");sw.WriteLine("");sw.WriteLine("\tvoid Update ()");sw.WriteLine("\t{");sw.WriteLine("");sw.WriteLine("\t}");sw.WriteLine("");sw.WriteLine("\t#endregion");sw.WriteLine("}");sw.Close();}createFileNum++;}}//创建2个Excelstatic void CreateExcelFile(string sceneName, bool isTest){if (isTest){//是测试场景,有学习卡string targetModel = testModelExcelPath.Replace("LittlePolice", sceneName);if (!File.Exists(targetModel)){File.Copy(testModelExcelPath, targetModel);createFileNum++;}string targetScene = testSceneExcelPath.Replace("LittlePolice", sceneName);if (!File.Exists(targetScene)){File.Copy(testSceneExcelPath, targetScene);createFileNum++;}}else{//是练习场景,有碎片的string targetModel = practiceModelExcelPath.Replace("Taken", sceneName);if (!File.Exists(targetModel)){File.Copy(practiceModelExcelPath, targetModel);createFileNum++;}string targetScene = practiceSceneExcelPath.Replace("Taken", sceneName);if (!File.Exists(targetScene)){File.Copy(practiceSceneExcelPath, targetScene);createFileNum++;}}}//创建一些经常用的预制体static void CreatePrefab(string sceneName){//创建一个KeepBg预制体string target = keepBgPath.Replace("FourElves", sceneName);if(!File.Exists(target)){File.Copy(keepBgPath, target);createFileNum++;}}//打开界面//[MenuItem("HideUIRaycast/TestEditorPath")]static void TestEditorAction(){//CreateScriptFile("MagicTest2", @"E:\SVN2\yxxj_optimize\Assets\Scripts\SceneLogic\MagicMask");//AssetDatabase.Refresh();}

}

public class CreateSceneWindow : EditorWindow

{

static bool[] ShowArray = new bool[400];

Vector2 m_scrollPos = Vector2.zero;string[] m_scenes;int toggleIndex = -1; //当前选中的场景idvoid OnGUI(){if (GUILayout.Button("Create", GUILayout.Width(100), GUILayout.Height(50))){//打包if (toggleIndex < 0){LogSystem.Log("Please choose scene!");return;}//CreateScenePath.CreateSceneFile(m_scenes[toggleIndex]);SceneInfoWindow.sceneName = m_scenes[toggleIndex];CreateScenePath.ShowSceneInfoWindow();}m_scrollPos = GUILayout.BeginScrollView(m_scrollPos);GUILayout.BeginVertical();m_scenes = System.Enum.GetNames(typeof(SceneType));for (int i = m_scenes.Length - 1; i >= 0; --i){if (m_scenes[i].Contains("MainScene") || m_scenes[i].Contains("PipiHome")){continue;}//ShowArray[i] = EditorGUILayout.ToggleLeft(m_scenes[i], ShowArray[i]);ShowArray[i] = EditorGUILayout.ToggleLeft(m_scenes[i], toggleIndex == i);if (ShowArray[i]){toggleIndex = i;}}GUILayout.EndVertical();GUILayout.EndScrollView();}private void OnDisable(){Clean();}public static void Clean(){//SceneNameList.Clear();for (int i = 0; i < ShowArray.Length; ++i){ShowArray[i] = false;}}

}

//场景信息设置面板

public class SceneInfoWindow : EditorWindow

{

public static string sceneName = “”; //当前要创建的场景名字

List modelList = new List(); //要创建的模型名单

Vector2 m_scrollPos = Vector2.zero;//--------------------------bool haveMeiMei; //是否创建美美这个模型bool haveNiuZhenZhang;bool haveTiger;bool haveElves; //是否创建小精灵这个模型,包含小黄,小红。。。bool haveJingJing;bool haveWolf;bool haveBabu;bool haveMiaoDa;bool haveElephant;bool haveElephantFight;bool haveSmoke;bool isTestScene;//是否是测试场景,不是测试场景,就是练习场景//----------------------------void OnGUI(){m_scrollPos = GUILayout.BeginScrollView(m_scrollPos);GUILayout.BeginVertical();EditorGUILayout.Space();EditorGUILayout.Space();EditorGUILayout.LabelField(" 请以下选择创建的模型", GUILayout.Height(20));EditorGUILayout.LabelField("--------------------------------------------------------------");EditorGUILayout.Space();haveMeiMei = EditorGUILayout.ToggleLeft("美美", haveMeiMei);haveNiuZhenZhang = EditorGUILayout.ToggleLeft("牛镇长", haveNiuZhenZhang);haveTiger = EditorGUILayout.ToggleLeft("小虎", haveTiger);haveElves = EditorGUILayout.ToggleLeft("小精灵", haveElves);haveJingJing = EditorGUILayout.ToggleLeft("静静", haveJingJing);haveWolf = EditorGUILayout.ToggleLeft("灰狼", haveWolf);haveBabu = EditorGUILayout.ToggleLeft("巴布", haveBabu);haveMiaoDa = EditorGUILayout.ToggleLeft("喵达", haveMiaoDa);haveElephant = EditorGUILayout.ToggleLeft("大象警察", haveElephant);haveElephantFight = EditorGUILayout.ToggleLeft("大象与老狼搏斗", haveElephantFight);haveSmoke = EditorGUILayout.ToggleLeft("烟雾", haveSmoke);EditorGUILayout.Space();EditorGUILayout.Space();EditorGUILayout.LabelField("--------------------------------------------------------------");EditorGUILayout.Space();isTestScene = EditorGUILayout.ToggleLeft("是否是测试场景", isTestScene);EditorGUILayout.Space();EditorGUILayout.Space();EditorGUILayout.Space();EditorGUILayout.Space();EditorGUILayout.LabelField("当前创建场景: " + sceneName);EditorGUILayout.LabelField("--------------------------------------------------------------");EditorGUILayout.Space();EditorGUILayout.Space();if (GUILayout.Button("Create", GUILayout.Width(100), GUILayout.Height(50))){//开始创建对应的场景结构路径 todoif (haveMeiMei) modelList.Add("MeiMei");if (haveNiuZhenZhang) modelList.Add("NiuZhenZhang");if (haveTiger) modelList.Add("Tiger");if (haveElves) modelList.Add("Elves");if (haveJingJing) modelList.Add("JingJing");if (haveWolf) modelList.Add("Wolf");if (haveBabu) modelList.Add("Babu");if (haveMiaoDa) modelList.Add("MiaoDa");if (haveElephant) modelList.Add("Elephant");if (haveElephantFight) modelList.Add("ElephantFight");if (haveSmoke) modelList.Add("Smoke");CreateScenePath.CreateSceneFile2(sceneName, modelList, isTestScene);}GUILayout.EndVertical();GUILayout.EndScrollView();}void OnDisable(){sceneName = "";modelList.Clear();isTestScene = false;}

}

这是个编辑器界面功能,有缺陷,但是可以使用。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。