-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolderSetupWindow.cs
More file actions
152 lines (127 loc) · 4.43 KB
/
Copy pathFolderSetupWindow.cs
File metadata and controls
152 lines (127 loc) · 4.43 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// =============================================
// Folder Setup Tool
// © AJSGamedev 2026
// =============================================
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.IO;
/// <summary>
/// Editor window tool that generates a customisable folder
/// structure in a new Unity project.
/// </summary>
public class FolderSetupWindow : EditorWindow
{
// Dictionary used over two Lists to keep folder name and
// enabled state together and avoid index sync issues
private Dictionary<string,bool> folders = new Dictionary<string, bool>
{
{ "Animations", true },
{ "Audio",true },
{ "Fonts", true },
{ "Materials", true },
{ "Meshes", true },
{ "Prefabs", true },
{ "Scenes", true },
{ "Scripts", true },
{ "ScriptableObjects", true },
{ "Shaders", true },
{ "Sprites", true },
{ "Textures", true },
{ "ThirdParty", true },
{ "UI", true },
{ "_Sandbox", true }
};
private Vector2 scrollPosition;
[MenuItem("Tools/Folder Setup")]
public static void OpenWindow()
{
FolderSetupWindow window = GetWindow<FolderSetupWindow>("Folder Setup");
window.minSize = new Vector2(300, 400);
}
private void OnGUI()
{
GUILayout.Label("Project Folder Setup", EditorStyles.boldLabel);
GUILayout.Space(5);
GUILayout.Label("Add, remove or rename folders, then hit Generate.", EditorStyles.helpBox);
GUILayout.Space(10);
string folderToRemove = null;
string keyToUpdate = null;
bool valueToUpdate = false;
string keyToRename = null;
string newName = null;
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
//Loop to generate the GUI
foreach (KeyValuePair<string,bool> folder in folders)
{
EditorGUILayout.BeginHorizontal();
bool newValue = EditorGUILayout.Toggle(folder.Value, GUILayout.Width(20));
string editedName = EditorGUILayout.TextField(folder.Key, GUILayout.ExpandWidth(true));
if (editedName != folder.Key)
{
keyToRename = folder.Key;
newName = editedName;
}
if (GUILayout.Button("X", GUILayout.Width(25)))
{
folderToRemove = folder.Key;
}
if (newValue != folder.Value)
{
keyToUpdate = folder.Key;
valueToUpdate = newValue;
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
GUILayout.Space(10);
// Changes are stored and applied after the loop to avoid
// modifying the dictionary during iteration
if (folderToRemove != null)
{
folders.Remove(folderToRemove);
}
if (keyToUpdate != null)
{
folders[keyToUpdate] = valueToUpdate;
}
if (keyToRename != null)
{
bool currentValue = folders[keyToRename];
folders.Remove(keyToRename);
folders.Add(newName, currentValue);
}
if (GUILayout.Button("+ Add Folder"))
{
folders.Add("NewFolder",true);
}
GUILayout.Space(5);
if (GUILayout.Button("Generate Folders"))
{
GenerateFolders();
}
}
/// <summary>
/// Generates folders in the Assets directory for all enabled entries.
/// Skips folders that are unchecked or have empty names.
/// </summary>
private void GenerateFolders()
{
foreach (KeyValuePair<string, bool> folder in folders)
{
if (string.IsNullOrWhiteSpace(folder.Key)|| !folder.Value) continue;
string path = "Assets/" + folder.Key.Trim();
if (!AssetDatabase.IsValidFolder(path))
{
AssetDatabase.CreateFolder("Assets", folder.Key.Trim());
Debug.Log("Created: " + path);
}
else
{
Debug.Log("Already exists, skipped: " + path);
}
}
AssetDatabase.Refresh();
Debug.Log("Folder setup complete!");
}
}