// *********************************************************************** // Assembly : Unity // Author : Kimch // Created : // // Last Modified By : Kimch // Last Modified On : // *********************************************************************** // // // *********************************************************************** namespace G { using System.Collections; using System.Collections.Generic; using F; internal class LanguageEntry { #region Field private Dictionary _entryDictionary = new Dictionary(); private Dictionary _idDictionary = new Dictionary(); /// /// 支持反向查找Id段 /// private int _keyRangeMin = 0; private int _keyRangeMax = 0; #endregion #region Property public string name { get; set; } public string iconName { get; set; } public string database { get; set; } public int keyRangeMin { get { return _keyRangeMin; } set { _keyRangeMin = value; } } public int keyRangeMax { get { return _keyRangeMax; } set { _keyRangeMax = value; } } #endregion #region Method /// /// /// /// public void LoadEntries(IList list) { _entryDictionary.Clear(); if (list != null && list.Count > 0) { var tmpL0 = (IList)list[0]; var idIndex = tmpL0.IndexOf("id"); var textIndex = tmpL0.IndexOf("text"); for (int i = 1; i < list.Count; i++) { var tmpLi = (IList)list[i]; int key = tmpLi.GetInt(idIndex); string value = tmpLi.GetString(textIndex); if (_entryDictionary.ContainsKey(key)) { #if UNITY_EDITOR UnityEngine.Debug.LogWarning("[Language]主语言冲突:" + key + " " + value); #endif continue; } _entryDictionary.Add(key, value); } } } public void SetAsDefault() { _idDictionary.Clear(); foreach (var kvPair in _entryDictionary) { if (kvPair.Key < _keyRangeMin || kvPair.Key > _keyRangeMax) { continue; } #if UNITY_EDITOR if (_idDictionary.ContainsKey(kvPair.Value)) { UnityEngine.Debug.LogWarning("主语言表冲突:" + kvPair.Key + " " + kvPair.Value); } #endif _idDictionary[kvPair.Value] = kvPair.Key; } } /// /// /// /// /// public void Add(int id, string entry) { _entryDictionary.Add(id, entry); } /// /// /// /// /// public bool Contains(int id) { return _entryDictionary.ContainsKey(id); } /// /// /// /// /// /// public bool TryGet(int id, out string entry) { return _entryDictionary.TryGetValue(id, out entry); } /// /// /// /// /// public bool TryGetId(string entry, out int id) { return _idDictionary.TryGetValue(entry, out id); } #endregion } }