微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果我更改先前序列化属性的属性,它会被正确反序列化吗?

如何解决如果我更改先前序列化属性的属性,它会被正确反序列化吗?

在 Unity (2020.3.8f1) 中,假设我有三个 UnityEngine.PropertyAttribute 派生属性,例如:

public class EmptyExampleAttribute : PropertyAttribute {
}

public class IntExampleAttribute : PropertyAttribute {
    private int value;
    public IntExampleAttribute (int v) { value = v; }
}

// Does this even accomplish anything? It *does* compile with no warnings...
[Serializable]
public class StrangeAttribute : PropertyAttribute {
    [Serializefield] private int value;
    public StrangeAttribute (int v) { value = v; }
}

现在,如果我在 MonoBehavIoUr 中有一些序列化的属性,我 #conditionally 将这些属性应用于:

public class SomeBehavIoUr : MonoBehavIoUr {

#if SOME_CONDITION
    [EmptyExample] public bool Property1;
    [IntExample(1)] public bool Property2;
    [Strange(5)] public bool Property3;
#else
    public bool Property1;
    public bool Property2;
    public bool Property3;
#endif

}

假设我实际上没有对代码中的这些属性任何事情(特别是当我看到它们时,我没有故意修改序列化内容-回复comment),我的问题是:

如果 SomeBehavIoUr 的反序列化值与对象最初序列化时的值不同,那么单独存在任何这些属性是否会以某种方式影响 SOME_CONDITION 的序列化,从而导致格式不兼容通过 Unity?

换句话说,假设我知道我的属性没有明确干扰序列化,我可以安全地更改属性属性而不破坏先前序列化的数据吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。