Enum Utils
用于创建、获取和解析枚举的工具库。本身不添加游戏内容,主要作为其他模组的依赖,也提供给模组开发者调用。
0浏览
0下载点击
0点赞
0收藏
关于这个 Mod
Enum Utils
用于创建、获取和解析枚举的工具库。本模组本身不添加游戏内容,主要作为其他模组的依赖。
遇到问题或有功能建议,可前往项目问题页面。
安装
建议使用模组管理器安装;作者推荐使用 r2modman。
开发者快速入门
从 Thunderstore 或 GitHub 发布页下载最新版本,解压后,在所用 IDE(如 Visual Studio 或 Rider)中添加该模组 DLL 的引用。
枚举工具
获取枚举
提供多种枚举查询和解析方法,例如:
[BepInPlugin(modGUID, modName, modVersion)]
public class ExampleModClass : BaseUnityPlugin
{
private void Start()
{
CauseOfDeath bludgeoning = EnumUtils.Parse<CauseOfDeath>("Bludgeoning");
if (EnumUtils.TryParse("Example", out CauseOfDeath example))
{
}
int numOfDeathCauses = EnumUtils.Count<CauseOfDeath>();
CauseOfDeath minDeathCause = EnumUtils.GetMinValue<CauseOfDeath>();
CauseOfDeath maxDeathCause = EnumUtils.GetMaxValue<CauseOfDeath>();
CauseOfDeath randomDeathCause = EnumUtils.GetRandom<CauseOfDeath>();
CauseOfDeath unusedDeathCauseValue = EnumUtils.GetFirstFreeValue<CauseOfDeath>();
string[] allDeathNames = EnumUtils.GetNames<CauseOfDeath>();
CauseOfDeath[] allDeathValues = EnumUtils.GetValues<CauseOfDeath>();
bool doesExampleDeathExist = EnumUtils.IsDefined<CauseOfDeath>("Example");
Type valueType = EnumUtils.GetUnderlyingType<CauseOfDeath>();
bool hasFlags = EnumUtils.IsPowerOfTwoEnum<CauseOfDeath>();
}
}
创建枚举
可以使用 EnumUtils 创建枚举值:
[BepInPlugin(modGUID, modName, modVersion)]
public class ExampleModClass : BaseUnityPlugin
{
// 将一个未使用的枚举值关联到指定名称。
private static readonly CauseOfDeath Example = EnumUtils.Create<CauseOfDeath>("Example");
// 将指定枚举值关联到指定名称。
private static readonly CauseOfDeath Example2 = EnumUtils.Create<CauseOfDeath>("Example2", -1);
private void Awake()
{
}
}
枚举持有类
也可以使用枚举持有类创建枚举。给类添加 [EnumHolder] 特性,然后调用 RegisterAllEnumHolders;其中的静态枚举字段会以字段名创建枚举值。默认会选择一个未使用的值,也可以自行指定值。
using System.Reflection;
[BepInPlugin(modGUID, modName, modVersion)]
public class ExampleModClass : BaseUnityPlugin
{
private void Awake()
{
EnumUtils.RegisterAllEnumHolders(Assembly.GetExecutingAssembly());
}
}
[EnumHolder]
public static class ExampleEnumHolderClass
{
public static readonly CauseOfDeath Example;
public static readonly CauseOfDeath Example2 = (CauseOfDeath)-1;
}
前置
- BepInEx:运行此库所需。
来源与文件
- 原作者:MegaPiggy
- 原项目:Enum Utils
- 文件:MegaPiggy.EnumUtils(ID:465)
来源列出的依赖与关系
- 作者列出的前置:BepInEx — Needed to run this library
前往 N 网打开所选文件。安装与下载要求以原作者及平台说明为准。
<!-- aoe-mods-source:nexusmods:lethalcompany:53 -->