using System; using System.Collections.Generic; using System.IO; using UnityEngine; public class LanguageUnit { public bool IsEnglish; private Dictionary AllStrings = new Dictionary(); private Dictionary AllImages = new Dictionary(); public LanguageUnit(TextAsset data, ImageData[] images) { foreach (ImageData imageData in images) { this.AllImages.Add(imageData.Name, imageData.Sprite); } using (StringReader stringReader = new StringReader(data.text)) { for (string text = stringReader.ReadLine(); text != null; text = stringReader.ReadLine()) { if (text.Length != 0) { int num = text.IndexOf(','); if (num < 0) { Debug.LogWarning("Couldn't parse: " + text); } else { string text2 = text.Substring(0, num); StringNames key; if (!Enum.TryParse(text2, out key)) { Debug.LogWarning("Couldn't parse: " + text2); } else { string value = LanguageUnit.UnescapeCodes(text.Substring(num + 1)); this.AllStrings.Add(key, value); } } } } } } public static string UnescapeCodes(string src) { if (src.IndexOf("\\n") < 0) { return src; } return src.Replace("\\n", "\n"); } public string GetString(StringNames stringId, params object[] parts) { string text; if (!this.AllStrings.TryGetValue(stringId, out text)) { return "STRMISS"; } if (parts.Length != 0) { return string.Format(text, parts); } return text; } public Sprite GetImage(ImageNames id) { Sprite result; this.AllImages.TryGetValue(id, out result); return result; } }