gpt4 book ai didi

unity3d - Unity 不序列化 int? field

转载 作者:行者123 更新时间:2023-12-03 21:21:58 25 4
gpt4 key购买 nike

我有一个类,我想在编辑器中更改其属性。所以我创建了我的类 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 编辑器中序列化,因为它的序列化程序不支持 null .
如果您不打算使用 JsonUtility 将此类序列化为 json,则有一个小的解决方法。 .
关键思想是您必须创建自己的可为空的 int。就像是

public class IntNullable 
{
public int Value;
public bool HasValue;
}

就像在 .NET 中完成的一样。然后你可以创建一个 Custom EditorIntNullable或您的 UIOptionsRing .在此编辑器中,您可以为 int 值创建一个字段和一个“Set Null”按钮,这将更改 HasValue 的值。多变的。此外,您还需要使用此自定义 IntNullable在你的代码中。

关于unity3d - Unity 不序列化 int? field ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52854129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com