Skip to content

1.4.0

Latest
Compare
Choose a tag to compare
@OctopBP OctopBP released this 19 Mar 20:28
· 0 commits to main since this release

Add EnumTypeFor attribute

You can add this attribute to enum

[EnumTypeFor(typeof(AssetReference))]
public enum UnitType
{
    Frog,
    Snake,
}

and it will generate new type for you

[Serializable]
public class UnitTypeForAssetReference
{
    [SerializeField] public AssetReference Frog;
    [SerializeField] public AssetReference Snake;

    public AssetReference Get(UnitType key)
    {
        return key switch
        {
            UnitType.Frog => Frog,
            UnitType.Snake => Snake,
            _ => throw new System.ArgumentOutOfRangeException(nameof(key), key, null),
        };
    }
}

So you can use it like this:

var assetAtType = unitAssets.Get(type);