public static List <VLanguage> PreloadLanguages(string dName) { Dictionary <string, object> dict; List <VLanguage> langs = new List <VLanguage>(); if (!Application.isPlaying) { if (!File.Exists(Application.dataPath + "/../" + VIDE_EditorDB.videRoot + "/Resources/LocalizationSettings.json")) { if (File.Exists(Application.dataPath + "/../" + VIDE_EditorDB.videRoot + "/Resources/demo_loc.json")) { dict = SerializeHelper.ReadFromFile("demo_loc" + ".json") as Dictionary <string, object>; } else { Debug.LogError("No localization settings found"); return(null); } } else { dict = SerializeHelper.ReadFromFile("LocalizationSettings" + ".json") as Dictionary <string, object>; } } else { return(null); } int langCount = (int)((long)dict["langs"]); for (int i = 0; i < langCount; i++) { langs.Add(new VLanguage()); langs[i].enabled = (bool)dict["langEnabled_" + i.ToString()]; langs[i].name = (string)dict["lang_Name" + i.ToString()]; } if (!Application.isPlaying) { if (!File.Exists(Application.dataPath + "/../" + VIDE_EditorDB.videRoot + "/Resources/Localized/" + "LOC_" + dName + ".json")) { //Debug.LogWarning("No localization file found"); return(null); } else { string fileDataPath = Application.dataPath + "/../" + VIDE_EditorDB.videRoot + "/Resources/Localized/"; string jsonString = File.ReadAllText(fileDataPath + "LOC_" + dName + ".json"); dict = DiagJson.Deserialize(jsonString) as Dictionary <string, object>; } } for (int d = 0; d < langs.Count; d++) { string lang = langs[d].name + "_"; Sprite[] sprites = Resources.LoadAll <Sprite>(""); AudioClip[] audios = Resources.LoadAll <AudioClip>(""); List <string> spriteNames = new List <string>(); List <string> audioNames = new List <string>(); foreach (Sprite t in sprites) { spriteNames.Add(t.name); } foreach (AudioClip t in audios) { audioNames.Add(t.name); } if (!dict.ContainsKey(lang + "playerDiags")) { continue; } int pDiags = (int)((long)dict[lang + "playerDiags"]); if (pDiags > 0) { langs[d].playerDiags = new List <VIDE_EditorDB.DialogueNode>(); } for (int i = 0; i < pDiags; i++) { langs[d].playerDiags.Add(new VIDE_EditorDB.DialogueNode()); VIDE_EditorDB.DialogueNode c = langs[d].playerDiags[i]; if (!dict.ContainsKey(lang + "pd_pTag_" + i.ToString())) { continue; } c.playerTag = (string)dict[lang + "pd_pTag_" + i.ToString()]; int cSize = (int)((long)dict[lang + "pd_comSize_" + i.ToString()]); string name = Path.GetFileNameWithoutExtension((string)dict[lang + "pd_sprite_" + i.ToString()]); if (spriteNames.Contains(name)) { c.sprite = sprites[spriteNames.IndexOf(name)]; } else if (name != string.Empty) { Debug.LogError("'" + name + "' not found in any Resources folder!"); } for (int ii = 0; ii < cSize; ii++) { c.comment.Add(new VIDE_EditorDB.Comment()); c.comment[ii].text = (string)dict[lang + "pd_" + i.ToString() + "_com_" + ii.ToString() + "text"]; string namec = Path.GetFileNameWithoutExtension((string)dict[lang + "pd_" + i.ToString() + "_com_" + ii.ToString() + "sprite"]); if (spriteNames.Contains(namec)) { c.comment[ii].sprites = sprites[spriteNames.IndexOf(namec)]; } else if (namec != "") { Debug.LogError("'" + namec + "' not found in any Resources folder!"); } namec = Path.GetFileNameWithoutExtension((string)dict[lang + "pd_" + i.ToString() + "_com_" + ii.ToString() + "audio"]); if (audioNames.Contains(namec)) { c.comment[ii].audios = audios[audioNames.IndexOf(namec)]; } else if (namec != "") { Debug.LogError("'" + namec + "' not found in any Resources folder!"); } } } } return(langs); }
public static object ReadFromFile(string filename) { string jsonString = File.ReadAllText(fileDataPath + filename); return(DiagJson.Deserialize(jsonString)); }
public static void LoadLanguages(string dName, bool onlyLoadDef) { Dictionary <string, object> dict; if (!Application.isPlaying) { if (!File.Exists(Application.dataPath + "/../" + VIDE_EditorDB.videRoot + "/Resources/Localized/" + "LOC_" + dName + ".json")) { for (int i = 0; i < languages.Count; i++) { languages[i].playerDiags = null; } return; } else { string fileDataPath = Application.dataPath + "/../" + VIDE_EditorDB.videRoot + "/Resources/Localized/"; string jsonString = File.ReadAllText(fileDataPath + "LOC_" + dName + ".json"); dict = DiagJson.Deserialize(jsonString) as Dictionary <string, object>; } } else { if (Resources.Load <TextAsset>("Localized/" + "LOC_" + dName) == null) { foreach (VLanguage l in languages) { l.playerDiags = null; } return; } string jstr = Resources.Load <TextAsset>("Localized/" + "LOC_" + dName).text; dict = MiniJSON_VIDE.DiagJson.Deserialize(jstr) as Dictionary <string, object>; } for (int d = 0; d < languages.Count; d++) { if (onlyLoadDef) { if (languages[d] != defaultLanguage) { continue; } } string lang = languages[d].name + "_"; Sprite[] sprites = Resources.LoadAll <Sprite>(""); AudioClip[] audios = Resources.LoadAll <AudioClip>(""); List <string> spriteNames = new List <string>(); List <string> audioNames = new List <string>(); foreach (Sprite t in sprites) { spriteNames.Add(t.name); } foreach (AudioClip t in audios) { audioNames.Add(t.name); } if (!dict.ContainsKey(lang + "playerDiags")) { continue; } int pDiags = (int)((long)dict[lang + "playerDiags"]); if (pDiags > 0) { languages[d].playerDiags = new List <VIDE_EditorDB.DialogueNode>(); } for (int i = 0; i < pDiags; i++) { languages[d].playerDiags.Add(new VIDE_EditorDB.DialogueNode()); VIDE_EditorDB.DialogueNode c = languages[d].playerDiags[i]; if (!dict.ContainsKey(lang + "pd_pTag_" + i.ToString())) { continue; } c.playerTag = (string)dict[lang + "pd_pTag_" + i.ToString()]; int cSize = (int)((long)dict[lang + "pd_comSize_" + i.ToString()]); string name = Path.GetFileNameWithoutExtension((string)dict[lang + "pd_sprite_" + i.ToString()]); if (spriteNames.Contains(name)) { c.sprite = sprites[spriteNames.IndexOf(name)]; } else if (name != string.Empty) { Debug.LogError("'" + name + "' not found in any Resources folder!"); } for (int ii = 0; ii < cSize; ii++) { c.comment.Add(new VIDE_EditorDB.Comment()); c.comment[ii].text = (string)dict[lang + "pd_" + i.ToString() + "_com_" + ii.ToString() + "text"]; string namec = Path.GetFileNameWithoutExtension((string)dict[lang + "pd_" + i.ToString() + "_com_" + ii.ToString() + "sprite"]); if (spriteNames.Contains(namec)) { c.comment[ii].sprites = sprites[spriteNames.IndexOf(namec)]; } else if (namec != "") { Debug.LogError("'" + namec + "' not found in any Resources folder!"); } namec = Path.GetFileNameWithoutExtension((string)dict[lang + "pd_" + i.ToString() + "_com_" + ii.ToString() + "audio"]); if (audioNames.Contains(namec)) { c.comment[ii].audios = audios[audioNames.IndexOf(namec)]; } else if (namec != "") { Debug.LogError("'" + namec + "' not found in any Resources folder!"); } } } } }