| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class DeviceReconnectView : MonoBehaviour
- {
- [SerializeField] GameObject btnConnectBow;
- [SerializeField] GameObject btnConnectArrow;
- static DeviceReconnectView ins;
- public static void Show() {
- if (SceneManager.GetActiveScene().name != "Game") {
- return;
- }
- try {
- if (!ins) {
- GameObject view = Resources.Load<GameObject>("Prefabs/Views/DeviceReconnectView");
- GameObject.Instantiate(view);
- }
- } catch (Exception) {}
- }
-
- void Start()
- {
- ins = this;
- InitBtnForConnect();
- GameMgr.ins.addLockerForGamePause(this);
- }
- void OnDestroy()
- {
- GameMgr.ins.removeLockerForGamePause(this);
- }
- void Update()
- {
- UpdateBtnForConnect();
- }
- void InitBtnForConnect()
- {
- btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
- BluetoothAim.ins.Connect();
- });
- btnConnectArrow.GetComponent<Button>().onClick.AddListener(delegate() {
- BluetoothShoot.ins.Connect();
- });
- }
- BluetoothStatusEnum bowStatus;
- BluetoothStatusEnum arrowStatus;
- void UpdateBtnForConnect() {
- if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
- bowStatus = BluetoothAim.ins.status;
- (string text1, Color color1) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
- btnConnectBow.GetComponentInChildren<Text>().text = text1;
- btnConnectBow.GetComponentInChildren<Text>().color = color1;
- if (BluetoothAim.ins.status == BluetoothStatusEnum.Connect) {
- btnConnectBow.GetComponent<Button>().enabled = true;
- } else {
- btnConnectBow.GetComponent<Button>().enabled = false;
- }
- }
- if (BluetoothShoot.ins && arrowStatus != BluetoothShoot.ins.status) {
- arrowStatus = BluetoothShoot.ins.status;
- (string text2, Color color2) = BluetoothStatus.GetStatusInfo(BluetoothShoot.ins.status);
- btnConnectArrow.GetComponentInChildren<Text>().text = text2;
- btnConnectArrow.GetComponentInChildren<Text>().color = color2;
- if (BluetoothShoot.ins.status == BluetoothStatusEnum.Connect) {
- btnConnectArrow.GetComponent<Button>().enabled = true;
- } else {
- btnConnectArrow.GetComponent<Button>().enabled = false;
- }
- }
- }
- public void Close() {
- AudioMgr.ins.PlayBtn();
- Destroy(this.gameObject);
- }
- }
|