Small refactor to JSON loader

This commit is contained in:
lvrossem
2023-03-02 12:28:19 +01:00
parent 8a27a1fe3b
commit 62ee8b9097
5 changed files with 1428 additions and 23 deletions

View File

@@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// JSON structure containing all themes/words
[System.Serializable]
public class ThemeList {
public Theme[] themes;
}
// Object representing part of the JSON containing word data
[System.Serializable]
public class Theme {
public string name;
public string description;
public string[] words;
}
public class ThemeLoader : MonoBehaviour
{
// Loads the JSON file containing all of the themes
public static ThemeList loadJson() {
TextAsset themeJson = Resources.Load<TextAsset>("SpellingBee/words");
return JsonUtility.FromJson<ThemeList>(themeJson.text);
}
}