Last active
January 21, 2024 19:10
-
-
Save marutypes/767b7cc3acae77f11851cb6bf2f67fe2 to your computer and use it in GitHub Desktop.
Unity Directory Bootstrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_EDITOR | |
using UnityEngine; | |
using UnityEditor; | |
using System.IO; | |
public class FolderStructureSetup | |
{ | |
[MenuItem("Tools/Setup Project Structure")] | |
private static void SetupProjectFolders() | |
{ | |
// Prompt the user for the project name | |
string path = EditorUtility.SaveFolderPanel("Choose Project Folder", Application.dataPath, ""); | |
if (string.IsNullOrEmpty(path)) | |
{ | |
return; // User cancelled the operation | |
} | |
// Get the relative path from the Assets directory | |
string relativePath = path.Replace(Application.dataPath, "Assets"); | |
string[] folderNames = { | |
"Code/Scripts", | |
"Code/Scripts/Editor", | |
"Code/Shaders", | |
"Code/Shaders/Shadergraph", | |
"Art/Scenes", | |
"Art/Materials", | |
"Art/Models", | |
"Art/Fonts", | |
"Art/Sprites", | |
"Art/Animations", | |
"Art/Textures", | |
"Audio/Music", | |
"Audio/SFX", | |
"GameData", | |
"GameData/Prefabs", | |
"_Scenes" | |
}; | |
foreach (string folderName in folderNames) | |
{ | |
CreateSubFolders(relativePath, folderName); | |
} | |
// The AssetDatabase does not automatically refresh, so we need to do it manually. | |
AssetDatabase.Refresh(); | |
} | |
private static void CreateSubFolders(string relativePath, string folderName) | |
{ | |
string[] subFolders = folderName.Split('/'); | |
string currentPath = relativePath; | |
foreach (string subFolder in subFolders) | |
{ | |
string newFolderPath = Path.Combine(currentPath, subFolder); | |
if (!AssetDatabase.IsValidFolder(newFolderPath)) | |
{ | |
// Create the directory. | |
AssetDatabase.CreateFolder(currentPath, subFolder); | |
} | |
currentPath = newFolderPath; | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment