Unity3D-CodeGenerator
Unity3D-CodeGenerator copied to clipboard
Code Generator
Provides a collection of classes that will aid you with generating code.
Installation
- The package is available on the openupm registry. You can install it via openupm-cli.
openupm add net.tnrd.codegenerator
- Installing through a Unity Package created by the Package Installer Creator from Needle
Usage
The following example is based on the package Layers & Tags Generator
public void Generate()
{
var tags = InternalEditorUtility.tags;
var generator = new Generator();
var tagsClass = new Class("Tags");
foreach (var tag in tags)
{
tagsClass.AddField(
new Field(Utilities.GetScreamName(tag), tag, typeof(string))
{
IsConst = true,
});
}
generator.AddClass(tagsClass);
generator.SaveToFile(Application.dataPath + "/Generated/Tags.cs");
AssetDatabase.Refresh();
}
In the example above you can see the generator being used.
It starts with a Generator, which holds all of the items that will be generated. In this example a class named Tags will be added.
The Tags class contains some simple fields that have the name of the tag in SCREAM_CASE and are assigned the value. The type of the fields are of string and they are marked as constant for easy access.
Support
Code Generator is an open-source project that I hope helps other people. It is by no means necessary but if you feel generous you can support me by donating.
Contributions
Pull requests are welcomed. Please feel free to fix any issues you find, or add new features.