ConnectGuidanceView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
  50. {
  51. if (bowStatus == BluetoothStatusEnum.ConnectSuccess)
  52. {
  53. AimHandler.ins.OnSaveAimDeviceInfos();
  54. if (AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.HOUYIPRO)
  55. {
  56. //如果不是红外设备,才进入校准?
  57. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  58. ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
  59. }
  60. }
  61. }
  62. else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
  63. {
  64. if (bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected)
  65. {
  66. AimHandler.ins.OnSaveAimDeviceInfos();
  67. if (AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.HOUYIPRO)
  68. {
  69. //如果不是红外设备,才进入校准?
  70. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  71. ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
  72. }
  73. //ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
  74. }
  75. }
  76. }
  77. void InitConfirmStorage()
  78. {
  79. transform.Find("ConfirmStep/Toggle").GetComponent<Toggle>().SetIsOnWithoutNotify(IsConfirmInStorage());
  80. transform.Find("ConfirmStep/Toggle").GetComponent<Toggle>().onValueChanged.AddListener(v =>
  81. {
  82. SetConfirmToStorage(v);
  83. });
  84. }
  85. bool IsConfirmInStorage()
  86. {
  87. return PlayerPrefs.GetInt("connect-confirm-" + LoginMgr.myUserInfo.id, 0) == 1;
  88. }
  89. void SetConfirmToStorage(bool value)
  90. {
  91. PlayerPrefs.SetInt("connect-confirm-" + LoginMgr.myUserInfo.id, value ? 1 : 0);
  92. }
  93. [SerializeField] GameObject btnConnectBow;
  94. BluetoothStatusEnum bowStatus;
  95. SmartBowSDK.BluetoothStatusEnum bowStatus2P;
  96. void UpdateBtnForConnect()
  97. {
  98. if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
  99. {
  100. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status)
  101. {
  102. bowStatus = BluetoothAim.ins.status;
  103. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  104. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  105. btnConnectBow.GetComponentInChildren<Text>().color = color;
  106. btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus == BluetoothStatusEnum.ConnectSuccess);
  107. }
  108. //自动跳转
  109. if (!isNext && bowStatus == BluetoothStatusEnum.ConnectSuccess)
  110. {
  111. isNext = true;
  112. OnClick_Next();
  113. }
  114. }
  115. else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
  116. {
  117. SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
  118. if (smartBowHelper == null) return;
  119. if (BluetoothAim.ins && bowStatus2P != smartBowHelper.GetBluetoothStatus())
  120. {
  121. bowStatus2P = smartBowHelper.GetBluetoothStatus();
  122. (int textID, Color color) = BluetoothStatus.GetBLE2StatusInfo(bowStatus2P);
  123. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  124. btnConnectBow.GetComponentInChildren<Text>().color = color;
  125. btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected);
  126. }
  127. //自动跳转
  128. if (!isNext && bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected)
  129. {
  130. isNext = true;
  131. OnClick_Next();
  132. }
  133. }
  134. }
  135. public void OnClick_ConnectBLE()
  136. {
  137. if (!IsConfirmInStorage())
  138. {
  139. //PopupMgr.ins.ShowTip("Please Confirmed the completion of the above steps");
  140. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("Guidance_Checked"));
  141. return;
  142. }
  143. //此页面连接当作重新初始化
  144. resetAimDevice();
  145. if (HomeView.ShowProminentBeforeConnectBLE()) return;
  146. Debug.Log("BluetoothAim.ins.getBLEPlayer():"+ BluetoothAim.ins.getBLEPlayer());
  147. if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
  148. {
  149. BluetoothAim.ins.DoConnect();
  150. }
  151. else if(BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
  152. {
  153. BluetoothAim.ins.DoConnect2P();
  154. }
  155. }
  156. public void OnClick_Back()
  157. {
  158. AudioMgr.ins.PlayBtn();
  159. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  160. }
  161. public void resetAimDevice() {
  162. //进行重新初始化的时候。重置一下对应的mac
  163. AimHandler.ins.onCreateAimDeviceInfoById();
  164. AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
  165. AimHandler.ins.ResetAimDeviceMac();
  166. Debug.Log("重新初始化时候 bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
  167. }
  168. public void resetAimType() {
  169. AimHandler.ins.onCreateAimDeviceInfoById();
  170. AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
  171. //如果有正在连接的情况,重置一下mac。其他不需要
  172. if (BluetoothAim.ins)
  173. {
  174. if (BluetoothAim.ins.status == BluetoothStatusEnum.Connecting)
  175. {
  176. AimHandler.ins.ResetAimDeviceMac();
  177. }
  178. SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
  179. if (smartBowHelper != null) {
  180. SmartBowSDK.BluetoothStatusEnum bluetoothStatusEnum = smartBowHelper.GetBluetoothStatus();
  181. if (bluetoothStatusEnum == SmartBowSDK.BluetoothStatusEnum.Connecting)
  182. {
  183. AimHandler.ins.ResetAimDeviceMac();
  184. }
  185. }
  186. }
  187. Debug.Log("重新初始化时候 resetAimType bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
  188. }
  189. void OnDestroy()
  190. {
  191. //退出面板时候,取消正在连接的连接
  192. BluetoothAim.ins.onCancelAllConnecting();
  193. }
  194. }