天天看點

NGUI的多語言處理

(目前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檔案。

繼續閱讀