Small refactor to JSON loader
This commit is contained in:
1382
Assets/Scenes/SpellingBeeThemeSelection.unity
Normal file
1382
Assets/Scenes/SpellingBeeThemeSelection.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Scenes/SpellingBeeThemeSelection.unity.meta
Normal file
7
Assets/Scenes/SpellingBeeThemeSelection.unity.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2dfa1265c9d65014c90941ac4240a977
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,20 +6,6 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
// 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 SpellingBeeController : MonoBehaviour {
|
||||
// All of the words that can be used in this session
|
||||
private string[] words;
|
||||
@@ -47,8 +33,9 @@ public class SpellingBeeController : MonoBehaviour {
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
loadJson();
|
||||
themeList = ThemeLoader.loadJson();
|
||||
currentTheme = themeList.themes[0];
|
||||
words = currentTheme.words;
|
||||
|
||||
SetRandomWord();
|
||||
}
|
||||
@@ -139,14 +126,6 @@ public class SpellingBeeController : MonoBehaviour {
|
||||
image.sprite = sprite;
|
||||
}
|
||||
|
||||
// Loads the JSON file containing all of the themes
|
||||
void loadJson() {
|
||||
TextAsset themeJson = Resources.Load<TextAsset>("SpellingBee/words");
|
||||
string jsonString = themeJson.text;
|
||||
themeList = JsonUtility.FromJson<ThemeList>(jsonString);
|
||||
words = themeList.themes[UnityEngine.Random.Range(0, themeList.themes.Length - 1)].words;
|
||||
}
|
||||
|
||||
IEnumerator Wait() {
|
||||
yield return new WaitForSecondsRealtime(2);
|
||||
}
|
||||
|
||||
26
Assets/Scripts/ThemeLoader.cs
Normal file
26
Assets/Scripts/ThemeLoader.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ThemeLoader.cs.meta
Normal file
11
Assets/Scripts/ThemeLoader.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e90cb50d2bd06aa382940db9c8c2810
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user