c# - 是否可以在 Unity 的自定义检查器中显示部分枚举?
问题描述
有没有办法在检查器中只提供某些枚举值?例如,我有一个充满对象的枚举,如果我选择表,我希望第二个具有特定对象 id 的枚举仅显示 table1/table2/table3 而不是所有可用的对象。
public enum Objects
{
Chair,
Table,
Door
}
public enum ObjectIDs
{
Chair01,
Chair02,
Table01,
Table02,
Table03,
etc..
}
解决方案
您可以修改此代码以制作您想要的内容。
您需要更改EnumOrderDrawer
类以使循环不适用于所有enum
变量。
例如更改代码
public const string TypeOrder = "10,1,5,2";
public enum Type
{
One = 10,
Two = 1,
Three = 5,
Four = 2,
}
[EnumOrder(TypeOrder)]
public Type type3;
.
.
.
.
for (int i=0; i<property.enumNames.Length; i++)
{
items[i] = property.enumNames[indexArray[i]];
}
至
public const int[] TypeOrder = new int[] { 10, 1, 5, 2 };
public enum Type
{
One = 10,
Two = 1,
Three = 5,
Four = 2,
}
[EnumOrder(TypeOrder)]
public Type type3;
.
.
.
.
for (int i=0; i<TypeOrder.Length; i++)
{
items[i] = property.enumNames[indexArray[i]];
}
.
.
.
.
推荐阅读
- node.js - 每 5 秒刷新一次 - 如何缓存 s3 文件?
- css - 变换:旋转在跨度上什么都不做
- python - 如何只显示当前时间
- asp.net-core - 在我的 aspnet 核心应用程序中使用非通用 ILogger 的最简单选择
- c# - 在所有 ASP.NET MVC 视图中使用动态视图
- javascript - 打开多个应用程序选项卡时通知未关闭
- symfony - 将数据数组传递给表单
- python - 如何将 --force-with-lease 与 (GitPython) git.remote.Remote 一起使用?
- python-3.x - 无法将 Blob 存储文件复制/下载到 Azure Functions 文件夹
- java - MacOS 无法识别 MacOS 10.14.6 上更新的 Java