Skip to content

A Unity source generator solution to generate enum length.

License

hoangtongvu/EnumLengthGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EnumLengthGenerator

Unity License

Introduction

EnumLengthGenerator is a source generator solution to generate a static class that contains enum length.

Installation

To install, paste the following URL into Unity's Package Manager:

  1. Open Package Manager.
  2. Click the + button.
  3. Select "Add package from git URL...".
  4. Enter:
https://github.com/hoangtongvu/EnumLengthGenerator.git?path=/Assets/EnumLengthGenerator
  1. Make sure all of the code that's going to use EnumLengthGenerator is under an .asmdef and references the EnumLengthGenerator.asmdef

How to use

Put the [GenerateEnumLength] attribute on any enum that you want to generate the length for:

namespace Core.Harvest
{
    [GenerateEnumLength]
    public enum HarvesteeType : byte
    {
        None = 0,
        Tree = 1,
        ResourcePit = 2,
    }
}

The source generator will generate a static class <EnumName>_Length (with the same namespace and underlying type as the original enum):

// HarvesteeType_Length.g.cs
// <auto-generated />
namespace Core.Harvest
{
    public static class HarvesteeType_Length
    {
        public const byte Value = 3;
    }
}

About

A Unity source generator solution to generate enum length.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages