-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathSceneEnumAutoGenerator
54 lines (43 loc) · 1.19 KB
/
SceneEnumAutoGenerator
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
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Linq;
public class SceneEnumAutoGenerator : UnityEditor.AssetModificationProcessor
{
public static string[] OnWillSaveAssets(string[] paths)
{
foreach(string path in paths)
{
if(path.ToLower().Contains(".unity"))
GenerateSceneEnum();
}
return paths;
}
[MenuItem("Utilities/GenerateSceneEnum")]
static void GenerateSceneEnum()
{
// Change this path for wherever you want your enum file to end up
string path = Application.dataPath + "/Scripts/GameScenes.cs";
var streamWriter = new StreamWriter(path, false);
string text =
@" // Auto-generated by SceneEnumAutoGenerator.
using UnityEngine;
using System.Collections;
public enum GameScenes
{";
for(int i = 0; i < EditorBuildSettings.scenes.Length; i++)
{
if(EditorBuildSettings.scenes[i] == null || EditorBuildSettings.scenes[i].path == "")
continue;
text += "\r\n\t";
text += EditorBuildSettings.scenes[i].path.Split('/').Last().Replace(".unity", "");
if(i < EditorBuildSettings.scenes.Length - 1)
text += ",";
}
text += "\r\n}";
streamWriter.Write(text);
streamWriter.Flush();
streamWriter.Close();
AssetDatabase.Refresh();
}
}