ConnectGuidanceView.cs 14 KB

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