Very new to c# from the www JavaScript world, I’m having troubles with partial success in getting loaded JSON converted into a usable object.
After loading the JSON, I can create an object with the loaded name present (success!). The positions are NULL however. It’s likely some scope issue but I’m not seeing it yet.
For my game puzzle layout, the JSON follows this structure:
{
"name": "Traditional 1",
"positions": [
[
{"x":6, "y":2},{"x":8, "y":2}
],
[
{"x":12, "y":4},{"x":14, "y":4},{"x":16, "y":4}
],
[
{"x":14, "y":6},{"x":16, "y":6},{"x":18, "y":6},{"x":20, "y":6}
]
]
}
Following examples from the docs, I created a Layout class (issue here likely, multidimensional arrays not in example docs of course):
public class Layout
{
public string name;
public LayoutPos[][] positions; //!!! issue?!! (positions in array, in array)
}
I also created a LayoutPos class to store slots where game pieces will be placed (not a Vector2 per say):
public class LayoutPos
{
public int x;
public int y;
}
Then I load the json into a Layout object:
void loadLayoutData (int layoutInt) {
string filePath = "Layouts/" + layoutInt.ToString("D5");
TextAsset layoutFile = Resources.Load<TextAsset>(filePath);
Layout layoutData = JsonUtility.FromJson<Layout>(layoutFile.text);
Debug.Log (layoutData.name); //success
Debug.Log (layoutData.positions); //!!! NULL
}
Any thoughts on how I would correct my positions reference? Thank you for taking a look.