ConnectGuidanceView.cs 11 KB

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