74 lines
1.8 KiB
C#
74 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
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() {
|
|
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) {
|
|
|
|
}
|
|
|
|
void changeSprite(string spriteName) {
|
|
Image imageComponent = image.GetComponent<Image>();
|
|
|
|
// Load the new sprite from the Resources folder
|
|
Debug.Log("SpellingBee/images/" + spriteName);
|
|
Sprite sprite = Resources.Load<Sprite>("SpellingBee/images/" + spriteName);
|
|
Debug.Log(sprite.pixelsPerUnit);
|
|
// 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);
|
|
}
|
|
}
|
|
}
|