using UnityEngine; using System; using System.Collections.Generic; namespace PixelCrushers.DialogueSystem { /// /// Deprecated by PixelCrushers.Common.TextTable. /// /// An asset containing a table of localized text. You can create a localized /// text table asset using the Assets > Create > Dialogue System menu or by /// right-clicking in the Project view. /// [AddComponentMenu("")] // Deprecated public class LocalizedTextTable : ScriptableObject { [Serializable] public class LocalizedTextField { public string name = string.Empty; public List values = new List(); } /// /// The languages in the table. /// public List languages = new List(); /// /// The fields that have localized text. /// public List fields = new List(); private const int LanguageNotFound = -1; /// /// Gets the localized text for a field using the current language. /// /// Field name. public string this[string fieldName] { get { return GetText(fieldName); } } /// /// Determines whether the table contains a field. /// /// true, if the field is in the table, false otherwise. /// Field name. public bool ContainsField(string fieldName) { return (fields.Find(f => string.Equals(f.name, fieldName)) != null); } private string GetText(string fieldName) { return GetTextInLanguage(fieldName, GetLanguageIndex()); } private string GetTextInLanguage(string fieldName, int languageIndex) { if (languageIndex != LanguageNotFound) { foreach (var field in fields) { if (string.Equals(field.name, fieldName)) { if ((languageIndex < field.values.Count) && !string.IsNullOrEmpty(field.values[languageIndex])) { return field.values[languageIndex]; } else { return (Localization.useDefaultIfUndefined && field.values.Count > 0) ? field.values[0] : string.Empty; } } } } return (Localization.useDefaultIfUndefined && languageIndex > 0) ? GetTextInLanguage(fieldName, 0) : string.Empty; } private int GetLanguageIndex() { if (Localization.isDefaultLanguage) return 0; for (int i = 0; i < languages.Count; i++) { if (string.Equals(languages[i], Localization.language)) { return i; } } return LanguageNotFound; } } }