DeviceReconnectView.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityEngine.SceneManagement;
  7. public class DeviceReconnectView : MonoBehaviour
  8. {
  9. [SerializeField] GameObject btnConnectBow;
  10. [SerializeField] GameObject btnConnectArrow;
  11. [SerializeField] Button btnClose;
  12. static DeviceReconnectView ins;
  13. public Action onComplete = null;
  14. public static GameObject Show() {
  15. if (SceneManager.GetActiveScene().name != "Game") return null;
  16. try {
  17. GameObject view = Resources.Load<GameObject>("Prefabs/Views/DeviceReconnectView");
  18. return GameObject.Instantiate(view);
  19. } catch (Exception) {}
  20. return null;
  21. }
  22. void Awake()
  23. {
  24. if (ins)
  25. {
  26. Destroy(this.gameObject);
  27. } else {
  28. ins = this;
  29. }
  30. }
  31. void Start()
  32. {
  33. InitBtnForConnect();
  34. GameMgr.ins.addLockerForGamePause(this);
  35. //debug不做连接检测
  36. Destroy(this.gameObject);
  37. if (onComplete != null) {
  38. onComplete();
  39. }
  40. }
  41. void OnDestroy()
  42. {
  43. GameMgr.ins.removeLockerForGamePause(this);
  44. }
  45. void Update()
  46. {
  47. UpdateBtnForConnect();
  48. btnClose.interactable = BluetoothStatus.IsAllConnected();
  49. }
  50. void InitBtnForConnect()
  51. {
  52. btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
  53. BluetoothAim.ins.Connect();
  54. });
  55. btnConnectArrow.GetComponent<Button>().onClick.AddListener(delegate() {
  56. BluetoothShoot.ins.Connect();
  57. });
  58. }
  59. BluetoothStatusEnum bowStatus;
  60. BluetoothStatusEnum arrowStatus;
  61. void UpdateBtnForConnect() {
  62. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
  63. bowStatus = BluetoothAim.ins.status;
  64. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  65. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  66. btnConnectBow.GetComponentInChildren<Text>().color = color;
  67. if (BluetoothAim.ins.status == BluetoothStatusEnum.Connect) {
  68. btnConnectBow.GetComponent<Button>().enabled = true;
  69. } else {
  70. btnConnectBow.GetComponent<Button>().enabled = false;
  71. }
  72. }
  73. if (BluetoothShoot.ins && arrowStatus != BluetoothShoot.ins.status) {
  74. arrowStatus = BluetoothShoot.ins.status;
  75. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
  76. btnConnectArrow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  77. btnConnectArrow.GetComponentInChildren<Text>().color = color;
  78. if (BluetoothShoot.ins.status == BluetoothStatusEnum.Connect) {
  79. btnConnectArrow.GetComponent<Button>().enabled = true;
  80. } else {
  81. btnConnectArrow.GetComponent<Button>().enabled = false;
  82. }
  83. }
  84. }
  85. public void BackHome() {
  86. AudioMgr.ins.PlayBtn();
  87. SceneManager.LoadScene("Home", LoadSceneMode.Single);
  88. }
  89. public void Close() {
  90. AudioMgr.ins.PlayBtn();
  91. Destroy(this.gameObject);
  92. if (onComplete != null) {
  93. onComplete();
  94. }
  95. }
  96. }