Created
May 20, 2017 13:36
-
-
Save Flavelius/07f3b9fec08c5508b8ca1d7f9337549a to your computer and use it in GitHub Desktop.
Unity Editor - Create folders from enum
This file contains 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 System; | |
using System.Linq; | |
using System.Reflection; | |
using UnityEditor; | |
using UnityEngine; | |
class EnumFolderCreator: EditorWindow | |
{ | |
[MenuItem("Edit/CreateEnumFolders")] | |
static void Open() | |
{ | |
GetWindow<EnumFolderCreator>(true); | |
} | |
Type[] enumTypes; | |
string[] enumTypeNames; | |
int selectedIndex = 0; | |
void OnEnable() | |
{ | |
enumTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsEnum).ToArray(); | |
enumTypeNames = new string[enumTypes.Length]; | |
for (int i = 0; i < enumTypes.Length; i++) | |
{ | |
enumTypeNames[i] = enumTypes[i].Name; | |
} | |
} | |
void OnGUI() | |
{ | |
if (enumTypes.Length == 0) | |
{ | |
EditorGUILayout.HelpBox("No enums found", MessageType.Info); | |
return; | |
} | |
selectedIndex = EditorGUILayout.Popup("Select Enum", selectedIndex, enumTypeNames); | |
var enumNames = Enum.GetNames(enumTypes[selectedIndex]); | |
EditorGUILayout.BeginVertical(EditorStyles.helpBox); | |
EditorGUILayout.HelpBox("Folders created:", MessageType.None); | |
for (int i = 0; i < enumNames.Length; i++) | |
{ | |
EditorGUILayout.LabelField(enumNames[i]); | |
} | |
EditorGUILayout.EndVertical(); | |
if (GUILayout.Button("Select parent and create")) | |
{ | |
var path = EditorUtility.OpenFolderPanel("Select Parent folder", "Assets", ""); | |
if (path.StartsWith(Application.dataPath)) | |
{ | |
path = path.Replace(Application.dataPath, "Assets"); | |
} | |
if (!string.IsNullOrEmpty(path)) | |
{ | |
for (int i = 0; i < enumNames.Length; i++) | |
{ | |
AssetDatabase.CreateFolder(path, enumNames[i]); | |
} | |
} | |
} | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment