我有一个类想要在编辑器中更改其属性。所以我创建了我的类 System.Serializable 并将我希望能够更改的变量公开。
就像这样:
[System.Serializable]
public class UIOptionsRing
{
public float Radius, DistanceBetweenPoints, StartOffset, GapInDegrees;
public int? GapAfterElementNumer = 3; //this var doesnt show up
public Vector3 CircleCenter;
public GameObject CircleElementsContainer;
}
但我遇到的问题是 GapAfterElementNumer 没有显示在所有其他字段的编辑器中。我怎样才能做到这一点int?
也出现了?
可空类型不会在 Unity Editor 中序列化,因为它的序列化程序不支持null
。
如果您不打算使用以下方法将此类序列化为 json,有一个小解决方法JsonUtility
。
关键思想是您必须创建自己的可空 int。就像是
public class IntNullable
{
public int Value;
public bool HasValue;
}
就像在 .NET 中完成的一样。然后你可以创建一个自定义编辑器 https://docs.unity3d.com/Manual/editor-CustomEditors.html for IntNullable
或你的UIOptionsRing
。在此编辑器中,您可以创建一个 int 值字段和一个“Set Null”按钮,这将更改HasValue
多变的。此外,您还需要使用此自定义IntNullable
在你的代码中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)