/// <summary> /// Saves word list to a file /// </summary> private void SaveWordToFile() { // Creates a new JsonWords object JsonWords fileWords = new JsonWords(); // Assign the list in the object to our word list fileWords.words = m_WordList; // Serializes the object to a string string fileContent = JsonConvert.SerializeObject(fileWords, Formatting.Indented); // Writes the serialized data to the file File.WriteAllText(WORD_FILE_NAME, fileContent); }
/// <summary> /// Loads the words from a file and sets m_WordList to the loaded list /// </summary> private void LoadWordsFromFile() { // Check if the file exists if (File.Exists(WORD_FILE_NAME)) { // Load the content of the file string fileContent = File.ReadAllText(WORD_FILE_NAME); // Deserializes the content from the file and creates a object JsonWords fileWords = JsonConvert.DeserializeObject <JsonWords>(fileContent); // Assign the loaded list to the m_WordList variables m_WordList = fileWords.words; } }
void Start() { words = JsonUtility.FromJson <JsonWords>(jsonFile.text); Debug.Log(words.letters9[10]); }