BowsSettingsView.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using AppUI.Bluetooth;
  2. using AppUI.Config;
  3. using AppUI.Util.Group;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using TMPro;
  8. using UnityEngine;
  9. using UnityEngine.Events;
  10. using UnityEngine.UI;
  11. namespace AppUI.View.Home.SettingsView
  12. {
  13. public class BowsSettingsView : MonoBehaviour
  14. {
  15. //ScreenDistance 相关
  16. [SerializeField] TMP_Text screenSizeText;
  17. [SerializeField] TMP_Text distanceText;
  18. [SerializeField] TMP_InputField inputSize;
  19. //BoxLevel 相关
  20. [SerializeField]
  21. BtnGroupSelector arrowWeightGroup;
  22. [SerializeField]
  23. BtnGroupSelector trainModeGroup;
  24. [SerializeField]
  25. BtnGroupSelector shootLevelGroup;
  26. [SerializeField]
  27. BtnGroupSelector bowAndArrowGroup;
  28. private void OnEnable()
  29. {
  30. //弓箭重量
  31. InitArrowWeight();
  32. //射击水平
  33. InitShootLevel();
  34. //训练模式
  35. InitTrainMode();
  36. //场景里面的弓箭手臂显示
  37. InitBowAndArrow();
  38. }
  39. void Start()
  40. {
  41. InitForRotateConvert();
  42. }
  43. void SetScreenSize(float v)
  44. {
  45. string vStr = v.ToString("#0");
  46. screenSizeText.text = vStr + "Inch";
  47. }
  48. void SetScreenDistance(float v)
  49. {
  50. string vStr = v.ToString("#0.00");
  51. distanceText.text = vStr + "M";
  52. }
  53. void InitForRotateConvert()
  54. {
  55. UnityAction<string> onEndEdit_inputSize = (string str) => {
  56. inputSize.SetTextWithoutNotify("");
  57. float v = (float)System.Math.Round(double.Parse(str), 2);
  58. if (v < 1 || v > 120)
  59. {
  60. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("输入值不在常规范围内"));
  61. return;
  62. }
  63. SetScreenSize(v);
  64. //save
  65. UserSettings.ins.bowRotateConvert.screenSize = v;
  66. UserSettings.ins.Save();
  67. SetScreenDistance(UserSettings.ins.bowRotateConvert.GetAdviseScreenDistance());
  68. };
  69. inputSize.onEndEdit.AddListener(onEndEdit_inputSize);
  70. SetScreenSize(UserSettings.ins.bowRotateConvert.screenSize);
  71. SetScreenDistance(UserSettings.ins.bowRotateConvert.GetAdviseScreenDistance());
  72. }
  73. void InitArrowWeight()
  74. {
  75. int index =
  76. System.Array.IndexOf(
  77. GlobalConfig.ArrowWeights,
  78. UserSettings.ins.actualArrowWeight);
  79. if (index < 0)
  80. index = 0;
  81. string[] texts =
  82. System.Array.ConvertAll(
  83. GlobalConfig.ArrowWeights,
  84. x => x.ToString());
  85. arrowWeightGroup.Init(
  86. texts,
  87. index,
  88. (selectIndex) =>
  89. {
  90. AudioMgr.ins.PlayBtn();
  91. UserSettings.ins.actualArrowWeight =
  92. GlobalConfig.ArrowWeights[selectIndex];
  93. UserSettings.ins.Save();
  94. SmartBowDeviceHub.ins?.SyncArrowWeights();
  95. });
  96. }
  97. void InitTrainMode()
  98. {
  99. int index =
  100. UserSettings.ins.trainMode ? 0 : 1;
  101. trainModeGroup.Init(
  102. GlobalConfig.ButtonStrs,
  103. index,
  104. (selectIndex) =>
  105. {
  106. AudioMgr.ins.PlayBtn();
  107. UserSettings.ins.trainMode =
  108. selectIndex == 0;
  109. UserSettings.ins.Save();
  110. });
  111. }
  112. void InitShootLevel()
  113. {
  114. int index = UserSettings.ins.shootLevel;
  115. shootLevelGroup.Init(
  116. GlobalConfig.ShootLevelStrs,
  117. index,
  118. (selectIndex) =>
  119. {
  120. AudioMgr.ins.PlayBtn();
  121. UserSettings.ins.shootLevel =
  122. GlobalConfig.ShootLevels[selectIndex];
  123. UserSettings.ins.Save();
  124. });
  125. }
  126. void InitBowAndArrow()
  127. {
  128. bowAndArrowGroup.Init(
  129. GlobalConfig.ButtonStrs,
  130. UserSettings.ins.openBowAndArrow ? 0 : 1,
  131. (selectIndex) =>
  132. {
  133. AudioMgr.ins.PlayBtn();
  134. UserSettings.ins.openBowAndArrow =
  135. selectIndex == 0;
  136. UserSettings.ins.Save();
  137. //如果打开图标并且存在 hideInfraredBowAndArrow key时候,设置为0
  138. if (UserSettings.ins.openBowAndArrow
  139. && PlayerPrefs.HasKey("hideInfraredBowAndArrow")
  140. && PlayerPrefs.GetInt("hideInfraredBowAndArrow") == 2 //armbow 设置 hideInfraredBowAndArrow = 2 状态下 操作面板才会 解开 红外的openBowAndArrow
  141. )
  142. {
  143. PlayerPrefs.SetInt("hideInfraredBowAndArrow", 0);
  144. }
  145. });
  146. }
  147. }
  148. }