ConnectGuidanceView.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. void Start()
  10. {
  11. //进入指南页面,onCreateAimDeviceInfoById 一下 aimdevice,和设置一下type
  12. resetAimType();
  13. InitConfirmStorage();
  14. transform.Find("BtnNext").GetComponent<Button>().onClick.AddListener(OnClick_Next);
  15. if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS)
  16. {
  17. ShowDeviceLayout(1);
  18. }
  19. else {
  20. ShowDeviceLayout(0);
  21. }
  22. //NewUserGuiderManager newUserGuiderManager = FindObjectOfType<NewUserGuiderManager>();
  23. //newUserGuiderManager.curConfigKey = "视角归位-触发";
  24. //newUserGuiderManager.isNewModule = AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS;
  25. ////进入射箭场景
  26. //GlobalData.pkMatchType = PKMatchType.None;
  27. //GameMgr.gameType = 1;
  28. ////射一箭回到连接页面,Device.view
  29. //GameMgr.bNavBack = true;
  30. //GameMgr.bShowDistance = false;
  31. //AimHandler.ins.bInitOne = true;
  32. //UnityEngine.SceneManagement.SceneManager.LoadScene(
  33. // "Game", UnityEngine.SceneManagement.LoadSceneMode.Single);
  34. }
  35. void ShowDeviceLayout(int index)
  36. {
  37. for (int i = 0; i < layouts.Count; i++)
  38. {
  39. GameObject _button = layouts[i];
  40. _button.SetActive(index == i);
  41. }
  42. }
  43. void Update()
  44. {
  45. UpdateBtnForConnect();
  46. }
  47. void OnClick_Next()
  48. {
  49. onEnterInfrared();
  50. return;
  51. if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
  52. {
  53. if (bowStatus == BluetoothStatusEnum.ConnectSuccess)
  54. {
  55. AimHandler.ins.OnSaveAimDeviceInfos();
  56. if (AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.HOUYIPRO)
  57. {
  58. //如果不是红外设备,才进入校准?
  59. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  60. ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
  61. }
  62. else
  63. {
  64. if (!PlayerPrefs.HasKey("hideInfraredBowAndArrow"))
  65. {
  66. //如果是红外连接成功,记录一个tag
  67. PlayerPrefs.SetInt("hideInfraredBowAndArrow", 1);
  68. }
  69. onEnterInfrared();
  70. }
  71. }
  72. }
  73. else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
  74. {
  75. if (bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected)
  76. {
  77. AimHandler.ins.OnSaveAimDeviceInfos();
  78. if (AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.HOUYIPRO)
  79. {
  80. //如果不是红外设备,才进入校准?
  81. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  82. ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
  83. }
  84. else
  85. {
  86. if (!PlayerPrefs.HasKey("hideInfraredBowAndArrow"))
  87. {
  88. //如果是红外连接成功,记录一个tag
  89. PlayerPrefs.SetInt("hideInfraredBowAndArrow", 1);
  90. }
  91. onEnterInfrared();
  92. }
  93. //ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
  94. }
  95. }
  96. }
  97. void InitConfirmStorage()
  98. {
  99. transform.Find("ConfirmStep/Toggle").GetComponent<Toggle>().SetIsOnWithoutNotify(IsConfirmInStorage());
  100. transform.Find("ConfirmStep/Toggle").GetComponent<Toggle>().onValueChanged.AddListener(v =>
  101. {
  102. SetConfirmToStorage(v);
  103. });
  104. }
  105. bool IsConfirmInStorage()
  106. {
  107. return PlayerPrefs.GetInt("connect-confirm-" + LoginMgr.myUserInfo.id, 0) == 1;
  108. }
  109. void SetConfirmToStorage(bool value)
  110. {
  111. PlayerPrefs.SetInt("connect-confirm-" + LoginMgr.myUserInfo.id, value ? 1 : 0);
  112. }
  113. [SerializeField] GameObject btnConnectBow;
  114. BluetoothStatusEnum bowStatus;
  115. SmartBowSDK.BluetoothStatusEnum bowStatus2P;
  116. void UpdateBtnForConnect()
  117. {
  118. if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
  119. {
  120. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status)
  121. {
  122. bowStatus = BluetoothAim.ins.status;
  123. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  124. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  125. btnConnectBow.GetComponentInChildren<Text>().color = color;
  126. btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus == BluetoothStatusEnum.ConnectSuccess);
  127. }
  128. //自动跳转
  129. if (!isNext && bowStatus == BluetoothStatusEnum.ConnectSuccess)
  130. {
  131. isNext = true;
  132. OnClick_Next();
  133. }
  134. }
  135. else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
  136. {
  137. SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
  138. if (smartBowHelper == null) return;
  139. if (BluetoothAim.ins && bowStatus2P != smartBowHelper.GetBluetoothStatus())
  140. {
  141. bowStatus2P = smartBowHelper.GetBluetoothStatus();
  142. (int textID, Color color) = BluetoothStatus.GetBLE2StatusInfo(bowStatus2P);
  143. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  144. btnConnectBow.GetComponentInChildren<Text>().color = color;
  145. btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected);
  146. }
  147. //自动跳转
  148. if (!isNext && bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected)
  149. {
  150. isNext = true;
  151. OnClick_Next();
  152. }
  153. }
  154. }
  155. public void OnClick_ConnectBLE()
  156. {
  157. if (!IsConfirmInStorage())
  158. {
  159. //PopupMgr.ins.ShowTip("Please Confirmed the completion of the above steps");
  160. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("Guidance_Checked"));
  161. return;
  162. }
  163. //此页面连接当作重新初始化
  164. resetAimDevice();
  165. if (HomeView.ShowProminentBeforeConnectBLE()) return;
  166. Debug.Log("BluetoothAim.ins.getBLEPlayer():"+ BluetoothAim.ins.getBLEPlayer());
  167. if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
  168. {
  169. BluetoothAim.ins.DoConnect();
  170. }
  171. else if(BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
  172. {
  173. BluetoothAim.ins.DoConnect2P();
  174. }
  175. }
  176. public void OnClick_Back()
  177. {
  178. AudioMgr.ins.PlayBtn();
  179. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  180. }
  181. public void resetAimDevice() {
  182. //进行重新初始化的时候。重置一下对应的mac
  183. AimHandler.ins.onCreateAimDeviceInfoById();
  184. AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
  185. AimHandler.ins.ResetAimDeviceMac();
  186. Debug.Log("重新初始化时候 bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
  187. }
  188. public void resetAimType() {
  189. AimHandler.ins.onCreateAimDeviceInfoById();
  190. AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
  191. //如果有正在连接的情况,重置一下mac。其他不需要
  192. if (BluetoothAim.ins)
  193. {
  194. if (BluetoothAim.ins.status == BluetoothStatusEnum.Connecting)
  195. {
  196. AimHandler.ins.ResetAimDeviceMac();
  197. }
  198. SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
  199. if (smartBowHelper != null) {
  200. SmartBowSDK.BluetoothStatusEnum bluetoothStatusEnum = smartBowHelper.GetBluetoothStatus();
  201. if (bluetoothStatusEnum == SmartBowSDK.BluetoothStatusEnum.Connecting)
  202. {
  203. AimHandler.ins.ResetAimDeviceMac();
  204. }
  205. }
  206. }
  207. Debug.Log("重新初始化时候 resetAimType bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
  208. }
  209. void OnDestroy()
  210. {
  211. //退出面板时候,取消正在连接的连接
  212. BluetoothAim.ins.onCancelAllConnecting();
  213. }
  214. //连接之后,跳转进入场景
  215. void onEnterInfrared() {
  216. //添加进入射箭场景
  217. if (PlayerPrefs.GetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 0) != 1)
  218. {
  219. Debug.Log("-----进入射箭场景!");
  220. NewUserGuiderManager newUserGuiderManager = FindObjectOfType<NewUserGuiderManager>();
  221. newUserGuiderManager.curConfigKey = "开始-红外调整";
  222. newUserGuiderManager.isNewModule = AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.HOUYIPRO;
  223. //进入射箭场景
  224. GlobalData.pkMatchType = PKMatchType.None;
  225. GameMgr.gameType = 1;
  226. //射一箭回到连接页面,Device.view
  227. GameMgr.bNavBack = true;
  228. GameMgr.bShowDistance = false;
  229. AimHandler.ins.bInitOne = true;
  230. UnityEngine.SceneManagement.SceneManager.LoadScene(
  231. "Game", UnityEngine.SceneManagement.LoadSceneMode.Single);
  232. PlayerPrefs.SetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 1);
  233. }
  234. else
  235. {
  236. Debug.Log("-----跳转回连接界面!");
  237. //如不是第一次,则应该跳转回连接界面
  238. ViewMgr.Instance.DestroyView<SmartArcheryView>();
  239. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  240. }
  241. }
  242. }