ConnectGuidanceView.cs 7.5 KB

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