A package that contains generators that will generate classes containing the project's Layers and Tags for easy access.
- The package is available on the openupm registry. You can install it via openupm-cli.
openupm add net.tnrd.layertagsgenerator
- Installing through a Unity Package created by the Package Installer Creator from Needle
Once you have installed the package into your project you can access the generators through the menu as shown below.
You can generate the Tags, Layers, and Sorting Layers all separately by using their respective menu items, or generate them all by using the Generate All menu item.
Once you have generated one or more through the menu, you will see the files appear in your project located int he Generated folder, which resides at top level in your Assets folder.
To use the generated files you simply access them through their classes which are: Tags, Layers, and SortingLayers. Below is an example of a use case for the Tags.
public class Foo : MonoBehaviour
{
private void OnCollisionEnter(Collision other)
{
if (other.transform.CompareTag(Tags.PLAYER))
{
...
}
}
}
Layers & Tags 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.
Pull requests are welcomed. Please feel free to fix any issues you find, or add new features.