wangguan
2020-12-25 b35c810d34558ac4bcdbe382fae6db4cb3e3b545
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
using UnityEngine;
using UnityEngine.UI;
using TMPro;
 
/// <summary>
/// 修改文字脚本
/// </summary>
public class LocalizationText : MonoBehaviour
{
    [SerializeField, Header("Langkey")]
    private string key = " ";
    private Text _text;
    private TextMeshProUGUI _textMeshPro;
    void Awake()
    {
        LanguageManager.onLanguageChanged += onLanguageChanged;
    }
 
    private void OnDestroy()
    {
        LanguageManager.onLanguageChanged -= onLanguageChanged;
    }
    /// <summary>
    /// Start is called on the frame when a script is enabled just before
    /// any of the Update methods is called the first time.
    /// </summary>
    void Start()
    {
        _text = GetComponent<Text>();
        _textMeshPro = GetComponent<TextMeshProUGUI>();
        onLanguageChanged();
    }
 
    void onLanguageChanged()
    {
        if (_text != null)
        {
            _text.text = MultiLangConst.GetValue(key);
        }
        else if (_textMeshPro != null)
        {
            _textMeshPro.text = MultiLangConst.GetValue(key);
        }
    }
}