Releases: OctopBP/unity-attributes
Releases · OctopBP/unity-attributes
1.4.0
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);