@inthevaldis

Сохранение Двумерного массива в JSON UNITY C#?

При сохранение сохраняется все, кроме Map, которая является Map = new int[width, height];
Но на этом месте в файле JSON ничего нет.

void Update()
{
if (Input.GetKeyDown(KeyCode.LeftAlt))
{
if (Map != null)
{
mapInf.MapData = Map;
mapInf.width = width;
mapInf.height = height;
mapInf.MapOffset = MapOffset;
mapInf.sprites = sprites;

File.WriteAllText(path, JsonUtility.ToJson(mapInf));

Debug.Log("Saved!");
}
}
}

[Serializable]
public class MapInfo {

public int[,] MapData = new int[0,0];
public int width;
public int height;
public int MapOffset;

public Sprite[] sprites;
}
  • Вопрос задан
  • 1170 просмотров
Решения вопроса 1
Griboks
@Griboks Куратор тега C#
Открываем справку, читаем: "The types of fields that you want to be included must be supported by the serializer; unsupported fields will be ignored, as will private fields, static fields, and fields with the NonSerialized attribute applied."
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы