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; [SerializeField] Button btnClose; static DeviceReconnectView ins; public Action onComplete = null; public static GameObject Show() { string sceneName = SceneManager.GetActiveScene().name; if (!sceneName.StartsWith("Game")) return null; try { GameObject view = Resources.Load("Prefabs/Views/DeviceReconnectView"); return GameObject.Instantiate(view); } catch (Exception) {} return null; } void Awake() { if (ins) { Destroy(this.gameObject); } else { ins = this; } } void Start() { InitBtnForConnect(); RenderDeviceNames(); GameMgr.ins.addLockerForGamePause(this); //用于测试阶段,暂时屏蔽该页面 Destroy(this.gameObject); if (onComplete != null) onComplete(); } void OnDestroy() { if (ins == this) ins = null; if (GameMgr.ins) GameMgr.ins.removeLockerForGamePause(this); } void Update() { UpdateBtnForConnect(); btnClose.interactable = BluetoothStatus.IsAllConnected(); } void RenderDeviceNames() { try { (DeviceInfo bowInfo, DeviceInfo arrowInfo) = DeviceMgr.ins.GetCurrentBowArrowInfo(); this.transform.Find("ShowBow/Text").GetComponent().SetText(bowInfo.config.name); this.transform.Find("ShowArrow/Text").GetComponent().SetText(arrowInfo.config.name); } catch (System.Exception) {} } void InitBtnForConnect() { btnConnectBow.GetComponent