Created
January 27, 2022 17:06
-
-
Save th3d0g/c0be475cbb5d7582859eff2560cadfcc to your computer and use it in GitHub Desktop.
Generate enum from editor
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 UnityEditor; | |
using System.IO; | |
public class GenerateEnum | |
{ | |
[MenuItem( "Tools/GenerateEnum" )] | |
public static void Go() | |
{ | |
string enumName = "MyEnum"; | |
string[] enumEntries = { "Foo", "Goo", "Hoo" }; | |
string filePathAndName = "Assets/Scripts/Enums/" + enumName + ".cs"; //The folder Scripts/Enums/ is expected to exist | |
using ( StreamWriter streamWriter = new StreamWriter( filePathAndName ) ) | |
{ | |
streamWriter.WriteLine( "public enum " + enumName ); | |
streamWriter.WriteLine( "{" ); | |
for( int i = 0; i < enumEntries.Length; i++ ) | |
{ | |
streamWriter.WriteLine( "\t" + enumEntries[i] + "," ); | |
} | |
streamWriter.WriteLine( "}" ); | |
} | |
AssetDatabase.Refresh(); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment