| 12345678910111213141516171819202122232425262728293031323334353637 |
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- [RequireComponent(typeof(Text))]
- public class TextLocalization : MonoBehaviour {
- public string key;
- private string replaceText;
- void Start() {
- // Get the string value from localization manager from key
- // and set the text component text value to the returned string value
- string text = LocalizationManager.Instance.GetText(key);
- text = text.Replace("\\n", Environment.NewLine);
- if (replaceText != null) {
- text = String.Format(text, replaceText);
- }
- GetComponent<Text>().text = text;
- }
- public void UpdateText() {
- string text = LocalizationManager.Instance.GetText(key);
- text = text.Replace("\\n", Environment.NewLine);
- if (replaceText != null) {
- text = String.Format(text, replaceText);
- }
- GetComponent<Text>().text = text;
- }
- public void SetReplaceText(string value) {
- replaceText = value;
- }
- }
|