LangSwitcher.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Eiko.YaSDK;
  2. using System;
  3. using TMPro;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class LangSwitcher : MonoBehaviour
  7. {
  8. public TextMeshProUGUI textTmp;
  9. public Text text;
  10. public string Text { get => text ? text.text : textTmp.text; set
  11. {
  12. if (text)
  13. {
  14. text.text = value;
  15. }
  16. else
  17. {
  18. textTmp.text = value;
  19. }
  20. }
  21. }
  22. public string ru;
  23. public string en;
  24. private void OnValidate()
  25. {
  26. if(text == null && textTmp == null)
  27. {
  28. if (gameObject.TryGetComponent<TextMeshProUGUI>(out var tmp))
  29. {
  30. textTmp=tmp;
  31. }
  32. else if (gameObject.TryGetComponent<Text>(out var text))
  33. {
  34. this.text = text;
  35. }
  36. else
  37. {
  38. Debug.LogError("GameObject must have a text component!");
  39. DestroyImmediate(this);
  40. }
  41. }
  42. }
  43. public void Start()
  44. {
  45. if(YandexSDK.instance.Lang=="en")
  46. {
  47. Text= en;
  48. }
  49. else
  50. {
  51. Text = ru;
  52. }
  53. }
  54. }