Example.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace SC.XR.Unity.Module_DetectorSystem
  6. {
  7. public class Example : MonoBehaviour
  8. {
  9. public Button chineseBtn;
  10. public Button englishBtn;
  11. public SCToggleCheckbox3D useSystemLanguageToggle;
  12. public Button getSystemLanguageBtn;
  13. public Text currentSystemLanguage;
  14. public object API_Module_Language { get; private set; }
  15. private void Awake()
  16. {
  17. chineseBtn.onClick.AddListener(OnClickChineseBtn);
  18. englishBtn.onClick.AddListener(OnClickEnglishBtn);
  19. useSystemLanguageToggle.onValueChanged.AddListener(OnUseSystemLanguageToggleValueChanged);
  20. getSystemLanguageBtn.onClick.AddListener(OnClickGetSystemLanguageBtn);
  21. }
  22. private void Update()
  23. {
  24. if (Input.GetKeyDown(KeyCode.K))
  25. {
  26. API_Module_DetectorSystem_Notice.SetNotice("The device position is NAN", "Please Reboot recovery", NoticeType.Warning, 0.8f, AlignmentType.Center, FollowType.False);
  27. API_Module_DetectorSystem_Notice.Show(1.5f);
  28. }
  29. }
  30. private void OnDestroy()
  31. {
  32. chineseBtn.onClick.RemoveListener(OnClickChineseBtn);
  33. englishBtn.onClick.RemoveListener(OnClickEnglishBtn);
  34. useSystemLanguageToggle.onValueChanged.RemoveListener(OnUseSystemLanguageToggleValueChanged);
  35. getSystemLanguageBtn.onClick.RemoveListener(OnClickGetSystemLanguageBtn);
  36. }
  37. public void OnClickChineseBtn()
  38. {
  39. SCBatteryDetector.getInstance.ChangeLanguage(DeviveBatteryLanguageEnum.Chinese);
  40. chineseBtn.GetComponentInChildren<Text>().text = "切换中文";
  41. englishBtn.GetComponentInChildren<Text>().text = "切换英文";
  42. useSystemLanguageToggle.GetComponentInChildren<TextMesh>().text = "使用系统语言";
  43. }
  44. public void OnClickEnglishBtn()
  45. {
  46. SCBatteryDetector.getInstance.ChangeLanguage(DeviveBatteryLanguageEnum.English);
  47. chineseBtn.GetComponentInChildren<Text>().text = "Change Chinese";
  48. englishBtn.GetComponentInChildren<Text>().text = "Change English";
  49. useSystemLanguageToggle.GetComponentInChildren<TextMesh>().text = "Use System Language";
  50. }
  51. public void OnUseSystemLanguageToggleValueChanged(bool value)
  52. {
  53. SCBatteryDetector.getInstance.useSystemLanguage = value;
  54. }
  55. public void OnClickGetSystemLanguageBtn()
  56. {
  57. switch (API_Module_DetectorSystem_Language.GetSystemLanguage())
  58. {
  59. case SCLanguageEnum.ChineseSimplified:
  60. case SCLanguageEnum.ChineseTraditional:
  61. getSystemLanguageBtn.GetComponentInChildren<Text>().text = "获取当前系统语言";
  62. currentSystemLanguage.text = "当前系统语言:中文";
  63. break;
  64. case SCLanguageEnum.English:
  65. getSystemLanguageBtn.GetComponentInChildren<Text>().text = "Get Current System Language";
  66. currentSystemLanguage.text = "Current System Language : English";
  67. break;
  68. }
  69. }
  70. }
  71. }