Get JSON parser to work

This commit is contained in:
lvrossem
2023-03-01 19:43:56 +01:00
parent 994997d279
commit ecd24dce04
136 changed files with 1248 additions and 1359 deletions

View File

@@ -4,36 +4,47 @@ using System.IO;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class ThemeList
{
public Theme[] themes;
}
[System.Serializable]
public class Theme
{
public string name;
public string description;
public string[] words;
}
public class SpellingBeeController : MonoBehaviour
{
private string[] words;
private ThemeList themeList;
private Theme currentTheme;
public Image image;
// Start is called before the first frame update
void Start() {
TextAsset textFile = Resources.Load<TextAsset>("SpellingBee/words");
string fileContents = textFile.text;
words = fileContents.Split('\n');
Image imageComponent = image.GetComponent<Image>();
// Load the new sprite from the Resources folder
Debug.Log("SpellingBee/images/" + "monke");
Sprite sprite = Resources.Load<Sprite>("SpellingBee/images/monke");
image.sprite = sprite;
Debug.Log(sprite.pixelsPerUnit);
//changeSprite("monke");
loadJson();
theme = themeList[0];
changeSprite("kiwi");
}
// Update is called once per frame
void Update() {
/*
int randomIndex = UnityEngine.Random.Range(0, words.Length - 1);
string randomWord = words[randomIndex];
changeSprite(randomWord);
Debug.Log(randomWord);
*/
}
void changeWord(string word) {
}
@@ -47,4 +58,16 @@ public class SpellingBeeController : MonoBehaviour
// Set the new sprite as the Image component's source image
image.sprite = sprite;
}
void loadJson() {
TextAsset themeJson = Resources.Load<TextAsset>("SpellingBee/words");
string jsonString = themeJson.text;
Debug.Log(jsonString);
themeList = JsonUtility.FromJson<ThemeList>(jsonString);
foreach (Theme theme in themeList.themes)
{
Debug.Log(theme.description);
}
}
}