ConnectGuidanceView.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. InitConfirmStorage();
  12. transform.Find("BtnNext").GetComponent<Button>().onClick.AddListener(OnClick_Next);
  13. if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS)
  14. {
  15. ShowDeviceLayout(1);
  16. }
  17. else {
  18. ShowDeviceLayout(0);
  19. }
  20. //NewUserGuiderManager newUserGuiderManager = FindObjectOfType<NewUserGuiderManager>();
  21. //newUserGuiderManager.curConfigKey = "视角归位-触发";
  22. //newUserGuiderManager.isNewModule = AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS;
  23. ////进入射箭场景
  24. //GlobalData.pkMatchType = PKMatchType.None;
  25. //GameMgr.gameType = 1;
  26. ////射一箭回到连接页面,Device.view
  27. //GameMgr.bNavBack = true;
  28. //GameMgr.bShowDistance = false;
  29. //AimHandler.ins.bInitOne = true;
  30. //UnityEngine.SceneManagement.SceneManager.LoadScene(
  31. // "Game", UnityEngine.SceneManagement.LoadSceneMode.Single);
  32. }
  33. void ShowDeviceLayout(int index)
  34. {
  35. for (int i = 0; i < layouts.Count; i++)
  36. {
  37. GameObject _button = layouts[i];
  38. _button.SetActive(index == i);
  39. }
  40. }
  41. void Update()
  42. {
  43. UpdateBtnForConnect();
  44. }
  45. void OnClick_Next()
  46. {
  47. if (bowStatus == BluetoothStatusEnum.ConnectSuccess)
  48. {
  49. AimHandler.ins.OnSaveAimDeviceInfos();
  50. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  51. ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
  52. }
  53. }
  54. void InitConfirmStorage()
  55. {
  56. transform.Find("ConfirmStep/Toggle").GetComponent<Toggle>().SetIsOnWithoutNotify(IsConfirmInStorage());
  57. transform.Find("ConfirmStep/Toggle").GetComponent<Toggle>().onValueChanged.AddListener(v =>
  58. {
  59. SetConfirmToStorage(v);
  60. });
  61. }
  62. bool IsConfirmInStorage()
  63. {
  64. return PlayerPrefs.GetInt("connect-confirm-" + LoginMgr.myUserInfo.id, 0) == 1;
  65. }
  66. void SetConfirmToStorage(bool value)
  67. {
  68. PlayerPrefs.SetInt("connect-confirm-" + LoginMgr.myUserInfo.id, value ? 1 : 0);
  69. }
  70. [SerializeField] GameObject btnConnectBow;
  71. BluetoothStatusEnum bowStatus;
  72. void UpdateBtnForConnect()
  73. {
  74. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status)
  75. {
  76. bowStatus = BluetoothAim.ins.status;
  77. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  78. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  79. btnConnectBow.GetComponentInChildren<Text>().color = color;
  80. btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus == BluetoothStatusEnum.ConnectSuccess);
  81. }
  82. //自动跳转
  83. if(!isNext && bowStatus == BluetoothStatusEnum.ConnectSuccess)
  84. {
  85. isNext = true;
  86. OnClick_Next();
  87. }
  88. }
  89. public void OnClick_ConnectBLE()
  90. {
  91. if (!IsConfirmInStorage())
  92. {
  93. PopupMgr.ins.ShowTip("Please Confirmed the completion of the above steps");
  94. return;
  95. }
  96. if (HomeView.ShowProminentBeforeConnectBLE()) return;
  97. BluetoothAim.ins.DoConnect();
  98. }
  99. public void OnClick_Back()
  100. {
  101. AudioMgr.ins.PlayBtn();
  102. ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
  103. }
  104. }