using System;
using TMPro;

namespace UnityEngine.UI
{
    public class UXTextMeshPro : TextMeshProUGUI
    {
        [SerializeField] private string m_localizationID = "";

        protected override void Start()
        {
            base.Start();
            if (!Application.isPlaying) return;
            ChangeLanguage();
        }

        protected void ChangeLanguage()
        {
            if (!string.IsNullOrEmpty(m_localizationID) && !"None".Equals(m_localizationID) && GameApp.Localization != null)
            {
                text = GameApp.Localization?.GetString(m_localizationID);
            }
        }

        /// <summary>
        /// 重新动态设置多语言
        /// </summary>
        /// <param name="localizationID"></param>
        public void SetLocalization(string localizationID)
        {
            m_localizationID = localizationID;
            ChangeLanguage();
        }
    }
}
