【问题标题】:Bad saving in Unity 3D with JSON使用 JSON 在 Unity 3D 中保存不好
【发布时间】:2017-04-05 16:10:12
【问题描述】:

我的体素地形源代码无法保存数据。我有一个名为地形的 3D 字符数组,当我保存时,结果是空 json。结果是:

{}

源码为:

public void TerrainSave() {
    LoadingSavingClass myObject = new LoadingSavingClass();
    myObject.terrain = terrain;
    string json = JsonUtility.ToJson(myObject);
    File.WriteAllText(Application.streamingAssetsPath + "/terrain/save.ter", json);
    if(json == "{}")
    {
        Debug.Log("Saved clear data");
    }
}

班级是:

[Serializable]
public class LoadingSavingClass
{
    public char[,,] terrain = new char[128, 32, 128];
}

保存的 3D char 字符数组不为空,我在保存前放入了一些数据。

【问题讨论】:

    标签: json unity3d save


    【解决方案1】:

    正如JSON Serialization Docs 中提到的,JsonUtility.ToJson 只会序列化与您在 Unity 的检查器中可以序列化的类型相同的类型。 char[,,,] 不会在 Unity 的检查器中序列化,因此不会使用 JsonUtility.ToJson 序列化

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多