DeviceReconnectView.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. static DeviceReconnectView ins;
  12. public static void Show() {
  13. if (SceneManager.GetActiveScene().name != "Game") {
  14. return;
  15. }
  16. try {
  17. if (!ins) {
  18. GameObject view = Resources.Load<GameObject>("Prefabs/Views/DeviceReconnectView");
  19. GameObject.Instantiate(view);
  20. }
  21. } catch (Exception) {}
  22. }
  23. void Start()
  24. {
  25. ins = this;
  26. InitBtnForConnect();
  27. GameMgr.ins.addLockerForGamePause(this);
  28. }
  29. void OnDestroy()
  30. {
  31. GameMgr.ins.removeLockerForGamePause(this);
  32. }
  33. void Update()
  34. {
  35. UpdateBtnForConnect();
  36. }
  37. void InitBtnForConnect()
  38. {
  39. btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
  40. BluetoothAim.ins.Connect();
  41. });
  42. btnConnectArrow.GetComponent<Button>().onClick.AddListener(delegate() {
  43. BluetoothShoot.ins.Connect();
  44. });
  45. }
  46. BluetoothStatusEnum bowStatus;
  47. BluetoothStatusEnum arrowStatus;
  48. void UpdateBtnForConnect() {
  49. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
  50. bowStatus = BluetoothAim.ins.status;
  51. (string text1, Color color1) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  52. btnConnectBow.GetComponentInChildren<Text>().text = text1;
  53. btnConnectBow.GetComponentInChildren<Text>().color = color1;
  54. if (BluetoothAim.ins.status == BluetoothStatusEnum.Connect) {
  55. btnConnectBow.GetComponent<Button>().enabled = true;
  56. } else {
  57. btnConnectBow.GetComponent<Button>().enabled = false;
  58. }
  59. }
  60. if (BluetoothShoot.ins && arrowStatus != BluetoothShoot.ins.status) {
  61. arrowStatus = BluetoothShoot.ins.status;
  62. (string text2, Color color2) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
  63. btnConnectArrow.GetComponentInChildren<Text>().text = text2;
  64. btnConnectArrow.GetComponentInChildren<Text>().color = color2;
  65. if (BluetoothShoot.ins.status == BluetoothStatusEnum.Connect) {
  66. btnConnectArrow.GetComponent<Button>().enabled = true;
  67. } else {
  68. btnConnectArrow.GetComponent<Button>().enabled = false;
  69. }
  70. }
  71. }
  72. public void Close() {
  73. AudioMgr.ins.PlayBtn();
  74. Destroy(this.gameObject);
  75. }
  76. }