162 lines
3.2 KiB
C#
162 lines
3.2 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Unity
|
|||
|
// Author : Kimch
|
|||
|
// Created :
|
|||
|
//
|
|||
|
// Last Modified By : Kimch
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "Language" company=""></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
namespace G
|
|||
|
{
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using F;
|
|||
|
|
|||
|
internal class LanguageEntry
|
|||
|
{
|
|||
|
#region Field
|
|||
|
|
|||
|
private Dictionary<int, string> _entryDictionary = new Dictionary<int, string>();
|
|||
|
private Dictionary<string, int> _idDictionary = new Dictionary<string, int>();
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 支持反向查找Id段
|
|||
|
/// </summary>
|
|||
|
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
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="list"></param>
|
|||
|
public void LoadEntries(IList<object> list)
|
|||
|
{
|
|||
|
_entryDictionary.Clear();
|
|||
|
if (list != null && list.Count > 0)
|
|||
|
{
|
|||
|
var tmpL0 = (IList<object>)list[0];
|
|||
|
var idIndex = tmpL0.IndexOf("id");
|
|||
|
var textIndex = tmpL0.IndexOf("text");
|
|||
|
|
|||
|
for (int i = 1; i < list.Count; i++)
|
|||
|
{
|
|||
|
var tmpLi = (IList<object>)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;
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <param name="entry"></param>
|
|||
|
public void Add(int id, string entry)
|
|||
|
{
|
|||
|
_entryDictionary.Add(id, entry);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool Contains(int id)
|
|||
|
{
|
|||
|
return _entryDictionary.ContainsKey(id);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <param name="entry"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool TryGet(int id, out string entry)
|
|||
|
{
|
|||
|
return _entryDictionary.TryGetValue(id, out entry);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="entry"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public bool TryGetId(string entry, out int id)
|
|||
|
{
|
|||
|
return _idDictionary.TryGetValue(entry, out id);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|