ConnectGuidanceView.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class ConnectGuidanceView : MonoBehaviour
  6. {
  7. [SerializeField] List<GameObject> layouts;
  8. bool isNext = false;
  9. [SerializeField] GameObject textTip01;
  10. [SerializeField] GameObject textTip02;
  11. //定位进来时候调用
  12. public void showTextipInfrared() {
  13. textTip01.SetActive(false);
  14. textTip02.SetActive(true);
  15. }
  16. void Start()
  17. {
  18. //进入指南页面,onCreateAimDeviceInfoById 一下 aimdevice,和设置一下type
  19. resetAimType();
  20. InitConfirmStorage();
  21. transform.Find("BtnNext").GetComponent<Button>().onClick.AddListener(OnClick_Next);
  22. if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMISPRO)
  23. {
  24. ShowDeviceLayout(1);
  25. }
  26. else if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.Gun)
  27. {
  28. ShowDeviceLayout(2);
  29. }
  30. else
  31. {
  32. ShowDeviceLayout(0);
  33. }
  34. //NewUserGuiderManager newUserGuiderManager = FindObjectOfType<NewUserGuiderManager>();
  35. //newUserGuiderManager.curConfigKey = "视角归位-触发";
  36. //newUserGuiderManager.isNewModule = AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS;
  37. ////进入射箭场景
  38. //GlobalData.pkMatchType = PKMatchType.None;
  39. //GameMgr.gameType = 1;
  40. ////射一箭回到连接页面,Device.view
  41. //GameMgr.bNavBack = true;
  42. //GameMgr.bShowDistance = false;
  43. //AimHandler.ins.bInitOne = true;
  44. //UnityEngine.SceneManagement.SceneManager.LoadScene(
  45. // "Game", UnityEngine.SceneManagement.LoadSceneMode.Single);
  46. }
  47. void ShowDeviceLayout(int index)
  48. {
  49. for (int i = 0; i < layouts.Count; i++)
  50. {
  51. GameObject _button = layouts[i];
  52. _button.SetActive(index == i);
  53. }
  54. }
  55. void Update()
  56. {
  57. UpdateBtnForConnect();
  58. }
  59. void OnClick_Next()
  60. {
  61. //onEnterInfrared();
  62. //return;
  63. if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
  64. {
  65. if (bowStatus == BluetoothStatusEnum.ConnectSuccess)
  66. {
  67. AimHandler.ins.OnSaveAimDeviceInfos();
  68. BluetoothAim.ins.SetMainConnectDeviceType();
  69. if (AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.HOUYIPRO
  70. && AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.Gun
  71. && AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.ARTEMISPRO)
  72. {
  73. //如果不是红外设备,才进入校准?
  74. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  75. ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
  76. }
  77. else
  78. {
  79. //修改步骤
  80. ViewManager2.ShowView(ViewManager2.Path_InfraredView);
  81. //if (!PlayerPrefs.HasKey("hideInfraredBowAndArrow"))
  82. //{
  83. // //如果是红外连接成功,记录一个tag
  84. // PlayerPrefs.SetInt("hideInfraredBowAndArrow", 1);
  85. //}
  86. //onEnterInfrared();
  87. }
  88. }
  89. }
  90. else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
  91. {
  92. if (bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected)
  93. {
  94. AimHandler.ins.OnSaveAimDeviceInfos();
  95. BluetoothAim.ins.SetMainConnectDeviceType();
  96. if (AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.HOUYIPRO
  97. && AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.Gun
  98. && AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.ARTEMISPRO)
  99. {
  100. //如果不是红外设备,才进入校准?
  101. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  102. ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
  103. }
  104. //todo 红外先跳转回连接页面吧
  105. else
  106. {
  107. //修改步骤
  108. //ViewManager2.ShowView(ViewManager2.Path_InfraredView);
  109. ViewMgr.Instance.DestroyView<SmartArcheryView>();
  110. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  111. //if (!PlayerPrefs.HasKey("hideInfraredBowAndArrow"))
  112. //{
  113. // //如果是红外连接成功,记录一个tag
  114. // PlayerPrefs.SetInt("hideInfraredBowAndArrow", 1);
  115. //}
  116. //onEnterInfrared();
  117. }
  118. //ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
  119. }
  120. }
  121. }
  122. void InitConfirmStorage()
  123. {
  124. transform.Find("ConfirmStep/Toggle").GetComponent<Toggle>().SetIsOnWithoutNotify(IsConfirmInStorage());
  125. transform.Find("ConfirmStep/Toggle").GetComponent<Toggle>().onValueChanged.AddListener(v =>
  126. {
  127. SetConfirmToStorage(v);
  128. });
  129. }
  130. bool IsConfirmInStorage()
  131. {
  132. return PlayerPrefs.GetInt("connect-confirm-" + LoginMgr.myUserInfo.id, 0) == 1;
  133. }
  134. void SetConfirmToStorage(bool value)
  135. {
  136. PlayerPrefs.SetInt("connect-confirm-" + LoginMgr.myUserInfo.id, value ? 1 : 0);
  137. }
  138. [SerializeField] GameObject btnConnectBow;
  139. [SerializeField] Text btnOmitText;
  140. private int dotCount = 0;
  141. private float interval = 0.5f; // 标点更新间隔
  142. private float timer = 0f;
  143. BluetoothStatusEnum bowStatus;
  144. SmartBowSDK.BluetoothStatusEnum bowStatus2P;
  145. void UpdateBtnForConnect()
  146. {
  147. if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
  148. {
  149. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status)
  150. {
  151. bowStatus = BluetoothAim.ins.status;
  152. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  153. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  154. btnConnectBow.GetComponentInChildren<Text>().color = color;
  155. btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus == BluetoothStatusEnum.ConnectSuccess);
  156. btnOmitText.color = color;
  157. }
  158. if (bowStatus != BluetoothStatusEnum.ConnectSuccess) {
  159. isNext = false;
  160. }
  161. //自动跳转
  162. else if (!isNext && bowStatus == BluetoothStatusEnum.ConnectSuccess)
  163. {
  164. isNext = true;
  165. OnClick_Next();
  166. }
  167. if (bowStatus == BluetoothStatusEnum.Connecting)
  168. {
  169. btnOmitText.gameObject.SetActive(true);
  170. UpdateLoadingText();
  171. }
  172. else
  173. {
  174. StopLoading();
  175. }
  176. }
  177. else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
  178. {
  179. SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
  180. if (smartBowHelper == null) return;
  181. if (BluetoothAim.ins && bowStatus2P != smartBowHelper.GetBluetoothStatus())
  182. {
  183. bowStatus2P = smartBowHelper.GetBluetoothStatus();
  184. (int textID, Color color) = BluetoothStatus.GetBLE2StatusInfo(bowStatus2P);
  185. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  186. btnConnectBow.GetComponentInChildren<Text>().color = color;
  187. btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected);
  188. btnOmitText.color = color;
  189. }
  190. if (bowStatus2P != SmartBowSDK.BluetoothStatusEnum.Connected)
  191. {
  192. isNext = false;
  193. }
  194. //自动跳转
  195. if (!isNext && bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected)
  196. {
  197. isNext = true;
  198. OnClick_Next();
  199. }
  200. if (bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connecting)
  201. {
  202. btnOmitText.gameObject.SetActive(true);
  203. UpdateLoadingText();
  204. }
  205. else
  206. {
  207. StopLoading();
  208. }
  209. }
  210. }
  211. void UpdateLoadingText()
  212. {
  213. timer += Time.deltaTime;
  214. // 每隔 `interval` 秒更新一次标点符号
  215. if (timer >= interval)
  216. {
  217. dotCount = (dotCount + 1) % 4; // 标点数量从 0 到 3 循环
  218. btnOmitText.text = new string('.', dotCount); // 添加相应数量的点
  219. timer = 0f; // 重置计时器
  220. }
  221. }
  222. // 停止加载效果
  223. public void StopLoading()
  224. {
  225. dotCount = 0;
  226. btnOmitText.text = ""; // 停止时恢复为基础文本
  227. }
  228. public void OnClick_ConnectBLE()
  229. {
  230. if (!IsConfirmInStorage())
  231. {
  232. //PopupMgr.ins.ShowTip("Please Confirmed the completion of the above steps");
  233. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("Guidance_Checked"));
  234. return;
  235. }
  236. //此页面连接当作重新初始化
  237. resetAimDevice();
  238. if (HomeView.ShowProminentBeforeConnectBLE()) return;
  239. Debug.Log("BluetoothAim.ins.getBLEPlayer():"+ BluetoothAim.ins.getBLEPlayer());
  240. if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
  241. {
  242. BluetoothAim.ins.DoConnect();
  243. }
  244. else if(BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
  245. {
  246. BluetoothAim.ins.DoConnect2P();
  247. }
  248. }
  249. public void OnClick_Back()
  250. {
  251. AudioMgr.ins.PlayBtn();
  252. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  253. }
  254. public void resetAimDevice() {
  255. //进行重新初始化的时候。重置一下对应的mac
  256. AimHandler.ins.onCreateAimDeviceInfoById();
  257. AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
  258. AimHandler.ins.ResetAimDeviceMac();
  259. Debug.Log("重新初始化时候 bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
  260. }
  261. public void resetAimType() {
  262. AimHandler.ins.onCreateAimDeviceInfoById();
  263. AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
  264. //如果有正在连接的情况,重置一下mac。其他不需要
  265. if (BluetoothAim.ins)
  266. {
  267. if (BluetoothAim.ins.status == BluetoothStatusEnum.Connecting)
  268. {
  269. AimHandler.ins.ResetAimDeviceMac();
  270. }
  271. SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
  272. if (smartBowHelper != null) {
  273. SmartBowSDK.BluetoothStatusEnum bluetoothStatusEnum = smartBowHelper.GetBluetoothStatus();
  274. if (bluetoothStatusEnum == SmartBowSDK.BluetoothStatusEnum.Connecting)
  275. {
  276. AimHandler.ins.ResetAimDeviceMac();
  277. }
  278. }
  279. }
  280. Debug.Log("重新初始化时候 resetAimType bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
  281. }
  282. void OnDestroy()
  283. {
  284. //退出面板时候,取消正在连接的连接
  285. BluetoothAim.ins.onCancelAllConnecting();
  286. }
  287. //连接之后,跳转进入场景
  288. //void onEnterInfrared() {
  289. // //添加进入射箭场景
  290. // if (PlayerPrefs.GetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 0) == 0)
  291. // {
  292. // Debug.Log("-----进入射箭场景!");
  293. // NewUserGuiderManager newUserGuiderManager = FindObjectOfType<NewUserGuiderManager>();
  294. // newUserGuiderManager.curConfigKey = "开始-红外调整";
  295. // newUserGuiderManager.isNewModule = AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.HOUYIPRO || AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.Gun ;
  296. // //进入射箭场景
  297. // GlobalData.pkMatchType = PKMatchType.None;
  298. // GameMgr.gameType = 1;
  299. // //射一箭回到连接页面,Device.view
  300. // GameMgr.bNavBack = true;
  301. // GameMgr.bShowDistance = false;
  302. // AimHandler.ins.bInitOne = true;
  303. // //关闭计时器
  304. // GameMgr.turnOffTimer = true;
  305. // UnityEngine.SceneManagement.SceneManager.LoadScene(
  306. // "Game", UnityEngine.SceneManagement.LoadSceneMode.Single);
  307. // PlayerPrefs.SetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 1);
  308. // }
  309. // else
  310. // {
  311. // Debug.Log("-----跳转回连接界面!");
  312. // //如不是第一次,则应该跳转回连接界面
  313. // ViewMgr.Instance.DestroyView<SmartArcheryView>();
  314. // ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  315. // }
  316. //}
  317. }