Convertir matrices de matrices a json
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
string filename = "data.json";
string jsonString;
string path;
[System.Serializable]
public class LevelGrid
{
public string[] rows;
}
[System.Serializable]
public class Levels
{
public LevelGrid[] levels;
}
void LoadGrid()
{
// Load data
string path = Application.streamingAssetsPath + "/" + filename;
jsonString = File.ReadAllText(path);
var levelBricks = JsonUtility.FromJson<Levels>(jsonString);
// DOESNT WORK
Debug.Log(levelBricks.levels[0]);
}
Mi data.json es:
{
"Levels": [
{"Level1": ["1,1,1,1,1", "1,1,1,1,1", "1,1,1,1,1"]},
{"Level2": ["1,1,1,1,1", "1,1,1,1,1", "1,0,1,0,1"]}
]
}
Algo está mal con el levelBricks int y nada se está cargando correctamente desde json. ¿Qué estoy haciendo mal? Debug.Log da un error y si solo depuro.Log "levelBricks", todo lo que obtengo es "Levels". Me gustaría poder acceder a las matrices en Level1 y Level2.