/// <sumamry> /// Populates the prompt based on ActiveRound. 1: Foreign Text; 2: English Text; 3: Image; 4: Audio Only /// </sumamry> void PopulatePrompt() { wordPrompt.gameObject.SetActive(false); imagePrompt.gameObject.SetActive(false); switch (GameState.Instance.ActiveRound) { case -1: case 1: wordPrompt.gameObject.SetActive(true); wordPrompt.UpdateWord(vocabResource.GetWord(languageIndex, currentIndex), vocabResource.GetWordAudioPath(languageIndex, currentIndex)); break; case 2: wordPrompt.gameObject.SetActive(true); wordPrompt.UpdateWord(vocabResource.GetWord(0, currentIndex), vocabResource.GetWordAudioPath(0, currentIndex)); break; case 3: imagePrompt.gameObject.SetActive(true); imagePrompt.sprite = Resources.Load <Sprite>(vocabResource.GetImagePath(currentIndex)); break; case 4: wordPrompt.gameObject.SetActive(true); wordPrompt.UpdateWord("", vocabResource.GetWordAudioPath(0, currentIndex)); break; } }
/// <summary> /// Updates the UI with the information from the previous (i=-1), current (i=0), or next(i=1) vocab word /// </summary> /// <returns>Whether it can go farther in the direction i.</returns> public bool Proceed(int i) { SetupLanguageHelp(); englishWord.gameObject.SetActive((english == 1)); englishDefinition.gameObject.SetActive((english == 1)); foreignWord.gameObject.SetActive((foreignHelp == 1)); foreignDefinition.gameObject.SetActive((foreignHelp == 1)); foreignHelpIcon.gameObject.SetActive((foreignHelp == 0)); GameState.Instance.SpeechEnabled = (speech == 1); UnityEngine.Object.FindObjectOfType <VoiceControlManager>().Enabled = (speech == 1); resultAnimation.SetActive(false); if (currentIndex + i > -1 && currentIndex + i < vocabJsonObject.Length) { // advance the vocab index currentIndex += i; // Update the UI image.sprite = Resources.Load <Sprite>(vocabJsonObject.GetImagePath(currentIndex)); englishWord.UpdateWord(vocabJsonObject.GetWord(0, currentIndex), vocabJsonObject.GetWordAudioPath(0, currentIndex)); englishDefinition.UpdateWord(vocabJsonObject.GetDefinition(0, currentIndex), vocabJsonObject.GetDefinitionAudioPath(0, currentIndex)); foreignWord.UpdateWord(vocabJsonObject.GetWord(languageIndex, currentIndex), vocabJsonObject.GetWordAudioPath(languageIndex, currentIndex)); foreignDefinition.UpdateWord(vocabJsonObject.GetDefinition(languageIndex, currentIndex), vocabJsonObject.GetDefinitionAudioPath(languageIndex, currentIndex)); return(currentIndex + i > -1 && currentIndex + i < vocabJsonObject.Length); } else { return(false); } }
/// <sumamry> /// Populates and randomizes the options so there are no repeats. /// </sumamry> void PopulateOptions() { var random = new System.Random(); int[] wordIndices = new int[options.Count / 2]; wordIndices[0] = currentIndex; // Get indices for random words as options for (int i = 1; i < options.Count / 2; i++) { int j, temp = -1; do { j = random.Next(vocabResource.Length); // check against existing array elements: try { temp = Array.FindIndex(wordIndices, value => value == j); } catch (ArgumentNullException e) { Debug.Log(e); temp = -1; } } while (temp != -1); wordIndices[i] = j; } // Setup the options. int displayType; int displayType2; for (int i = 0; i < options.Count / 2; i++) { options[i].SetActive(true); options[i].GetComponent <MatchGameOption>().Enabled = true; options[i].GetComponent <MatchGameOption>().EnglishWord = vocabResource.GetWord(0, wordIndices[i]); options[i].GetComponent <MatchGameOption>().ForeignWord = vocabResource.GetWord(languageIndex, wordIndices[i]); // Change this to languageIndex options[i].GetComponent <MatchGameOption>().ImagePath = vocabResource.GetImagePath(wordIndices[i]); options[i].GetComponent <MatchGameOption>().EnglishAudioPath = vocabResource.GetWordAudioPath(0, wordIndices[i]); options[i].GetComponent <MatchGameOption>().ForeignAudioPath = vocabResource.GetWordAudioPath(languageIndex, wordIndices[i]); options[i + options.Count / 2].SetActive(true); options[i + options.Count / 2].GetComponent <MatchGameOption>().Enabled = true; options[i + options.Count / 2].GetComponent <MatchGameOption>().EnglishWord = vocabResource.GetWord(0, wordIndices[i]); options[i + options.Count / 2].GetComponent <MatchGameOption>().ForeignWord = vocabResource.GetWord(languageIndex, wordIndices[i]); // Change this to languageIndex options[i + options.Count / 2].GetComponent <MatchGameOption>().ImagePath = vocabResource.GetImagePath(wordIndices[i]); options[i + options.Count / 2].GetComponent <MatchGameOption>().EnglishAudioPath = vocabResource.GetWordAudioPath(0, wordIndices[i]); options[i + options.Count / 2].GetComponent <MatchGameOption>().ForeignAudioPath = vocabResource.GetWordAudioPath(languageIndex, wordIndices[i]); // Choose the type of options: See the MatchGameOption class Display() method for details. switch (GameState.Instance.ActiveRound) { case 1: displayType = MatchGameOption.DISPLAY_IMAGE; displayType2 = MatchGameOption.DISPLAY_FOREIGN; break; case 2: displayType = MatchGameOption.DISPLAY_IMAGE; displayType2 = MatchGameOption.DISPLAY_ENGLISH; break; case 3: displayType = MatchGameOption.DISPLAY_ENGLISH; displayType2 = MatchGameOption.DISPLAY_FOREIGN; break; case 4: displayType = MatchGameOption.DISPLAY_IMAGE; displayType2 = MatchGameOption.DISPLAY_ENGLISH; break; default: displayType = MatchGameOption.DISPLAY_IMAGE; displayType2 = MatchGameOption.DISPLAY_ENGLISH; break; } options[i].GetComponent <MatchGameOption>().DisplayType = displayType; options[i + options.Count / 2].GetComponent <MatchGameOption>().DisplayType = displayType2; options[i].GetComponent <MatchGameOption>().Display(MatchGameOption.DISPLAY_BLANK); options[i + options.Count / 2].GetComponent <MatchGameOption>().Display(MatchGameOption.DISPLAY_BLANK); } // randomize the order of the options; for (int i = 0; i < options.Count; i++) { int j = random.Next(options.Count); GameObject k = options[j]; options[j] = options[options.Count - 1]; options[options.Count - 1] = k; } for (int i = 0; i < options.Count; i++) { options[i].transform.SetSiblingIndex(i); } }