LanguageComponent.cs 896 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class LanguageComponent : MonoBehaviour
  6. {
  7. public string languageKey = "";
  8. [System.NonSerialized]
  9. public Text m_text;
  10. public void Start()
  11. {
  12. if (m_text == null)
  13. {
  14. m_text = GetComponent<Text>();
  15. }
  16. Init();
  17. }
  18. public void Init()
  19. {
  20. GlobalEvent.AddEvent(LanguageEventEnum.LanguageChange, ReceviceLanguageChange);
  21. ResetLanguage();
  22. }
  23. public void ResetLanguage()
  24. {
  25. if (string.IsNullOrEmpty(languageKey))
  26. return;
  27. string value = LanguageManager.GetContentByKey(languageKey).ToString();
  28. value = value.Replace("\\n", "\n");
  29. m_text.text = value;
  30. }
  31. void ReceviceLanguageChange(params object[] objs)
  32. {
  33. ResetLanguage();
  34. }
  35. }