ConnectGuidanceView.cs 11 KB

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