-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCreateProjectTree.cs
More file actions
99 lines (88 loc) · 3.27 KB
/
CreateProjectTree.cs
File metadata and controls
99 lines (88 loc) · 3.27 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
using System.IO;
namespace ProjectTreeGenerator
{
class Folder
{
public string DirPath { get; private set; }
public string ParentPath { get; private set; }
public string Name;
public List<Folder> Subfolders;
public Folder Add(string name)
{
Folder subfolder = null;
if (ParentPath.Length > 0)
subfolder = new Folder(name, ParentPath + Path.DirectorySeparatorChar + Name);
else
subfolder = new Folder(name, Name);
Subfolders.Add(subfolder);
return subfolder;
}
public Folder(string name, string dirPath)
{
Name = name;
ParentPath = dirPath;
DirPath = ParentPath + Path.DirectorySeparatorChar + Name;
Subfolders = new List<Folder>();
}
}
public class CreateProjectTree
{
[MenuItem("Tools/Generate Project Tree")]
public static void Execute()
{
var assets = GenerateFolderStructure();
CreateFolders(assets);
}
private static void CreateFolders(Folder rootFolder)
{
if (!AssetDatabase.IsValidFolder(rootFolder.DirPath))
{
Debug.Log("Creating: <b>" + rootFolder.DirPath + "</b>");
AssetDatabase.CreateFolder(rootFolder.ParentPath, rootFolder.Name);
File.Create(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + rootFolder.DirPath + Path.DirectorySeparatorChar + ".keep");
}
else
{
if (Directory.GetFiles(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + rootFolder.DirPath).Length < 1)
{
File.Create(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + rootFolder.DirPath + Path.DirectorySeparatorChar + ".keep");
Debug.Log("Creating '.keep' file in: <b>" + rootFolder.DirPath + "</b>");
}
else
{
Debug.Log("Directory <b>" + rootFolder.DirPath + "</b> already exists");
}
}
foreach (var folder in rootFolder.Subfolders)
{
CreateFolders(folder);
}
}
private static Folder GenerateFolderStructure()
{
Folder rootFolder = new Folder("Assets", "");
rootFolder.Add("Scripts");
rootFolder.Add("Scenes");
rootFolder.Add("Extensions");
rootFolder.Add("Resources");
rootFolder.Add("Plugins");
var staticAssets = rootFolder.Add("StaticAssets");
staticAssets.Add("Animations");
staticAssets.Add("Animators");
staticAssets.Add("Effects");
staticAssets.Add("Fonts");
staticAssets.Add("Materials");
staticAssets.Add("Models");
staticAssets.Add("Prefabs");
staticAssets.Add("Shaders");
staticAssets.Add("Sounds");
staticAssets.Add("Sprites");
staticAssets.Add("Textures");
staticAssets.Add("Videos");
return rootFolder;
}
}
}