(当前NGUI 版本为3.5.8)
先看几个SCRIPT文件:
Localization.cs (静态类):: 从text asset中读取本地化的文本文件,并解析出相关的字符串信息。所得的KEY/VALUE数据存储在 Dictionary<string, string> mOldDictionary结构中。
UILocalize.cs:: 用于对UIWidget进行本地化。
关键代码在:
void Start ()
{
#if UNITY_EDITOR
if (!Application.isPlaying) return;
#endif
mStarted = true;
OnLocalize();
}
/// <summary>
/// This function is called by the Localization manager via a broadcast SendMessage.
/// </summary>
void OnLocalize ()
{
// If no localization key has been specified, use the label's text as the key
if (string.IsNullOrEmpty(key))
{
UILabel lbl = GetComponent<UILabel>();
if (lbl != null) key = lbl.text;
}
// If we still don't have a key, leave the value as blank
if (!string.IsNullOrEmpty(key)) <span style="color:#ff0000;">value = Localization.Get(key)</span>;
}
一般在每个UILABEL控件中都要添加一个
UILocalize.cs的SCRIPT文件。