void Start() { #if !UNITY_EDITOR && UNITY_ANDROID // Initialize speech EasyTTSUtil.Initialize(EasyTTSUtil.UnitedKingdom); #endif // Load vocabulary m_VocabularyDictionary = new DataDictionary(); m_DataGrammar = new GrammarDictionary(); m_DataGamesDictionary = new GamesDictionary(); m_StateMenu = STATE_MENU.MAIN_MENU; m_MainMenuPanelUI.Show(); }
private void OnOptionPress(ButtonWithText optionButton) { Debug.Log("<color=cyan>" + "[GrammarControl.OnOptionPress] index " + optionButton.ButtonIndex + "Name " + optionButton.Title + "</color>"); if ((optionButton.ButtonIndex < 0) || (optionButton.ButtonIndex >= AppController.Instance.LauncherControl.GrammarSet.Count)) { return; } m_selectedCategory = AppController.Instance.LauncherControl.GrammarSet[optionButton.ButtonIndex]; m_selectedGrammar = 0; m_menu.Hide(); SetGrammarData(); m_isDescriptionShown = true; m_ui.Show(); }
public IEnumerator DownloadSubData(EDATATYPE tData) { switch (tData) { case EDATATYPE.VOCABULARY: m_VocabularySet = new List <WordDictionary>(); break; case EDATATYPE.PHRASAL_VERBS: m_PhrasalVerbSet = new List <WordDictionary>(); break; case EDATATYPE.IDIOMS: m_IdiomsSet = new List <WordDictionary>(); break; case EDATATYPE.EXPRESSIONS: m_ExpressionsSet = new List <WordDictionary>(); break; case EDATATYPE.GRAMMAR: m_grammarSet = new List <GrammarDictionary>(); break; } m_Result = ERESULT.SUCCESS; if (m_InfoFileList == null) { m_Result = ERESULT.FAIL; yield break; } int indexData = (int)tData; if (indexData >= m_InfoFileList.Count) { m_Result = ERESULT.FAIL; yield break; } string pictureFolder = Path.Combine(m_CloudDataUrl, m_PicturesFolder); for (int iData = 0; iData < m_InfoFileList[indexData].Data.Data.Count; iData++) { m_Progress.SetProgress("Downloading " + m_InfoFileList[indexData].Data.Data[iData].FileName); string fileName = m_InfoFileList[indexData].Data.Data[iData].FileName + ".json"; string dataCloudURL = m_CloudDataUrl + "/" + m_InfoFileList[indexData].DataFolderName + "/" + fileName; Debug.Log("<color=purple>" + "[LauncherControl.DownloadData] Retrieving (" + (iData + 1) + "/" + m_InfoFileList[indexData].Data.Data.Count + ") - URL: " + dataCloudURL + "</color>"); WWW wwwDataFile = new WWW(dataCloudURL); yield return(wwwDataFile); if (!string.IsNullOrEmpty(wwwDataFile.text)) { string dataLocalURL = Path.Combine(Application.persistentDataPath, m_InfoFileList[indexData].DataFolderName); dataLocalURL = Path.Combine(dataLocalURL, fileName); if (SaveFileToLocal(dataLocalURL, wwwDataFile)) { if (m_InfoFileList[indexData].DataType == EDATATYPE.VOCABULARY) { WordDictionary set = JsonUtility.FromJson <WordDictionary>(wwwDataFile.text); m_VocabularySet.Add(set); // Download images for (int iWord = 0; iWord < set.Data.Count; iWord++) { if (!string.IsNullOrEmpty(set.Data[iWord].PictureName)) { string pictureUrl = Path.Combine(pictureFolder, set.Data[iWord].PictureName); Debug.Log("<color=purple>" + "[LauncherControl.DownloadData] Picture URL at " + pictureUrl + "</color>"); WWW wwwPictureFile = new WWW(pictureUrl); yield return(wwwPictureFile); if (wwwPictureFile.texture != null) { Debug.Log("<color=purple>" + "[LauncherControl.RequestRecipe] Texture: (" + wwwPictureFile.texture.width + " x " + wwwPictureFile.texture.height + ")" + "</color>"); Texture2D texture = new Texture2D(wwwPictureFile.texture.width, wwwPictureFile.texture.height, TextureFormat.DXT1, false); wwwPictureFile.LoadImageIntoTexture(texture); Rect rec = new Rect(0, 0, texture.width, texture.height); set.Data[iWord].Sprite = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100); yield return(new WaitForEndOfFrame()); string localPicture = Path.Combine(m_LocalPictureDirectory, set.Data[iWord].PictureName); // Load Picture in memory SaveFileToLocal(localPicture, wwwPictureFile); } else { m_Result = ERESULT.FAIL; break; } wwwPictureFile.Dispose(); wwwPictureFile = null; } } } else if (m_InfoFileList[indexData].DataType == EDATATYPE.GRAMMAR) { GrammarDictionary set = JsonUtility.FromJson <GrammarDictionary>(wwwDataFile.text); set.Category = m_InfoFileList[indexData].Data.Data[iData].FileName; m_grammarSet.Add(set); } else if (m_InfoFileList[indexData].DataType == EDATATYPE.PHRASAL_VERBS) { WordDictionary set = JsonUtility.FromJson <WordDictionary>(wwwDataFile.text); m_PhrasalVerbSet.Add(set); } else if (m_InfoFileList[indexData].DataType == EDATATYPE.EXPRESSIONS) { WordDictionary set = JsonUtility.FromJson <WordDictionary>(wwwDataFile.text); m_ExpressionsSet.Add(set); } else if (m_InfoFileList[indexData].DataType == EDATATYPE.IDIOMS) { WordDictionary set = JsonUtility.FromJson <WordDictionary>(wwwDataFile.text); m_IdiomsSet.Add(set); } } } else { m_Result = ERESULT.FAIL; break; } } m_Progress.Hide(); }
private bool LoadSubData(EDATATYPE tData) { if (m_InfoFileList == null) { return(false); } int indexData = (int)tData; if (indexData >= m_InfoFileList.Count) { return(false); } // Read sub data for (int iData = 0; iData < m_InfoFileList[indexData].Data.Data.Count; iData++) { string localDataFile = Path.Combine(Application.persistentDataPath, m_InfoFileList[indexData].DataFolderName); localDataFile = Path.Combine(localDataFile, m_InfoFileList[indexData].Data.Data[iData].FileName + ".json"); string jsonData = string.Empty; if (ReadFile(localDataFile, ref jsonData)) { if (m_InfoFileList[indexData].DataType == EDATATYPE.VOCABULARY) { WordDictionary set = JsonUtility.FromJson <WordDictionary>(jsonData); m_VocabularySet.Add(set); // Load images for (int iWord = 0; iWord < set.Data.Count; iWord++) { if (!string.IsNullOrEmpty(set.Data[iWord].PictureName)) { string pictureUrl = Path.Combine(m_LocalPictureDirectory, set.Data[iWord].PictureName); if (File.Exists(pictureUrl)) { Texture2D texture = new Texture2D(2, 2); try { byte[] pictureData = File.ReadAllBytes(pictureUrl); texture.LoadImage(pictureData); Rect rec = new Rect(0, 0, texture.width, texture.width); set.Data[iWord].Sprite = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100); } catch (Exception e) { Debug.Log("<color=red>" + "[LauncherControl.LoadSubData] There was an error trying to get file (image) " + pictureUrl + " ERROR: " + e.Message + "</color>"); return(false); } } } } } else if (m_InfoFileList[indexData].DataType == EDATATYPE.GRAMMAR) { GrammarDictionary set = JsonUtility.FromJson <GrammarDictionary>(jsonData); set.Category = m_InfoFileList[indexData].Data.Data[iData].FileName; m_grammarSet.Add(set); } else if (m_InfoFileList[indexData].DataType == EDATATYPE.PHRASAL_VERBS) { WordDictionary set = JsonUtility.FromJson <WordDictionary>(jsonData); m_PhrasalVerbSet.Add(set); } else if (m_InfoFileList[indexData].DataType == EDATATYPE.EXPRESSIONS) { WordDictionary set = JsonUtility.FromJson <WordDictionary>(jsonData); m_ExpressionsSet.Add(set); } else if (m_InfoFileList[indexData].DataType == EDATATYPE.IDIOMS) { WordDictionary set = JsonUtility.FromJson <WordDictionary>(jsonData); m_IdiomsSet.Add(set); } } else { return(false); } } return(true); }