Write comments; some cleanup
This commit is contained in:
@@ -6,11 +6,13 @@ using TMPro;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
// JSON structure containing all themes/words
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class ThemeList {
|
public class ThemeList {
|
||||||
public Theme[] themes;
|
public Theme[] themes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Object representing part of the JSON containing word data
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class Theme {
|
public class Theme {
|
||||||
public string name;
|
public string name;
|
||||||
@@ -18,17 +20,29 @@ public class Theme {
|
|||||||
public string[] words;
|
public string[] words;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SpellingBeeController : MonoBehaviour {
|
public class SpellingBeeController : MonoBehaviour {
|
||||||
|
// All of the words that can be used in this session
|
||||||
private string[] words;
|
private string[] words;
|
||||||
|
|
||||||
|
// Where we currently are in the word
|
||||||
private int currentIndex;
|
private int currentIndex;
|
||||||
|
|
||||||
|
// The word that is currently being spelled
|
||||||
private string currentWord;
|
private string currentWord;
|
||||||
|
|
||||||
|
// All of the available themes
|
||||||
private ThemeList themeList;
|
private ThemeList themeList;
|
||||||
|
|
||||||
|
// The theme we are currently using
|
||||||
private Theme currentTheme;
|
private Theme currentTheme;
|
||||||
|
|
||||||
|
// The GameObjects representing the letters
|
||||||
private GameObject[] letters;
|
private GameObject[] letters;
|
||||||
|
|
||||||
|
// The Image component for displaying the appropriate sprite
|
||||||
public Image image;
|
public Image image;
|
||||||
public string inputString;
|
|
||||||
|
// The input field for testing purposes
|
||||||
public TMP_InputField input;
|
public TMP_InputField input;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
@@ -39,18 +53,6 @@ public class SpellingBeeController : MonoBehaviour {
|
|||||||
SetRandomWord();
|
SetRandomWord();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetRandomWord() {
|
|
||||||
currentIndex = 0;
|
|
||||||
|
|
||||||
int randomIndex = UnityEngine.Random.Range(0, words.Length - 1);
|
|
||||||
string randomWord = words[randomIndex];
|
|
||||||
|
|
||||||
letters = new GameObject[randomWord.Length];
|
|
||||||
currentWord = randomWord;
|
|
||||||
changeSprite(randomWord);
|
|
||||||
changeWord(randomWord);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update() {
|
void Update() {
|
||||||
if (input.text.Length > 0) {
|
if (input.text.Length > 0) {
|
||||||
@@ -71,7 +73,21 @@ public class SpellingBeeController : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeWord(string word) {
|
// Pick a new random word from words and initialize the needed variables
|
||||||
|
void SetRandomWord() {
|
||||||
|
currentIndex = 0;
|
||||||
|
|
||||||
|
int randomIndex = UnityEngine.Random.Range(0, words.Length - 1);
|
||||||
|
string randomWord = words[randomIndex];
|
||||||
|
|
||||||
|
letters = new GameObject[randomWord.Length];
|
||||||
|
currentWord = randomWord;
|
||||||
|
changeSprite(randomWord);
|
||||||
|
displayWord(randomWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Displays the word that needs to be spelled
|
||||||
|
void displayWord(string word) {
|
||||||
int length = word.Length;
|
int length = word.Length;
|
||||||
int canvasWidth = 1920;
|
int canvasWidth = 1920;
|
||||||
int maxWidth = 1080;
|
int maxWidth = 1080;
|
||||||
@@ -112,6 +128,7 @@ public class SpellingBeeController : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change the image that is being displayed
|
||||||
void changeSprite(string spriteName) {
|
void changeSprite(string spriteName) {
|
||||||
Image imageComponent = image.GetComponent<Image>();
|
Image imageComponent = image.GetComponent<Image>();
|
||||||
|
|
||||||
@@ -122,6 +139,7 @@ public class SpellingBeeController : MonoBehaviour {
|
|||||||
image.sprite = sprite;
|
image.sprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loads the JSON file containing all of the themes
|
||||||
void loadJson() {
|
void loadJson() {
|
||||||
TextAsset themeJson = Resources.Load<TextAsset>("SpellingBee/words");
|
TextAsset themeJson = Resources.Load<TextAsset>("SpellingBee/words");
|
||||||
string jsonString = themeJson.text;
|
string jsonString = themeJson.text;
|
||||||
|
|||||||
Reference in New Issue
Block a user