public void saveHandler() { // Play sound. audioManager.Play("ButtonClick"); // Get words. string[] words = { word1.text, word2.text, word3.text, word4.text, word5.text, word6.text, word7.text, word8.text, word9.text, word10.text }; // Check words. if (!checkWords(words)) { return; } // Delete old save. File.Delete(savePath + saveFileName); // Create object. WordsObject wordsObject = new WordsObject(); wordsObject.words = words; string jsonString = JsonUtility.ToJson(wordsObject); // Save file. File.WriteAllText(configPath + wordFileName, jsonString); // Go to main menu. int buildIndex = SceneUtility.GetBuildIndexByScenePath("Assets/Scenes/Main Menu.unity"); levelManager.loadLevel(buildIndex); }
private void loadWords() { string jsonString = File.ReadAllText(configPath + wordFileName); WordsObject wordObject = JsonUtility.FromJson <WordsObject>(jsonString); word = wordObject.words[currentLevel - 1].ToUpper(); }
public void createWordsFile() { // Create new "words.txt" file. WordsObject wordsObject = new WordsObject(); wordsObject.words = ProjectConst.defaultWords; string jsonString = JsonUtility.ToJson(wordsObject); File.WriteAllText(configPath + wordFileName, jsonString); }
private bool validateFile() { // Get amount of words. int wordsCnt = ProjectConst.maxLevel; // Get array of words from the file. string jsonString = File.ReadAllText(configPath + wordFileName); WordsObject wordsObject = JsonUtility.FromJson <WordsObject>(jsonString); // Get length of the array. int arrLength = wordsObject.words.Length; // Validate the file. if (wordsCnt == arrLength) { return(true); } return(false); }