using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 用于单机直连设备的设置操作 /// public class DevicesHolder : MonoBehaviour { public static DevicesHolder ins; bool bConnected = false; public static void Init() { if (!BluetoothHolder.ins) { GameObject devicesHolder = Resources.Load("Prefabs/DevicesHolder"); Instantiate(devicesHolder); } } void Awake() { if (ins) { Destroy(this.gameObject); } else { ins = this; DontDestroyOnLoad(this.gameObject); } } // Start is called before the first frame update void Start() { ShowConnectTip(); } /// /// 提示正在连接 /// public void ShowConnectTip() { if (!bConnected) { PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("BConnectTip"), 15f); } } /// /// 目前应该只使用红外设备,就是 HOUYIPRO,ARTEMISPRO,Gun /// /// public void SwitchDeviceByType(AimDeviceType deviceType) { bConnected = true; //去除蓝牙连接之后才设置这里 if (CommonConfig.bDisableBluetooth) { //打开图标 SimulateMouseController.ins?.SetBleConnected(true); //打靶和打猎需要设置为false BowCamera.isTouchMode = false; } //切换后算连接成功 PopupMgr.ins.ClearAllTip(); //这里判断一下如果是当前连接的不用重复调用设置了 if (AimHandler.ins.aimDeviceInfos.arry.Count != 0) { AimDeviceInfo aimDeviceInfo = AimHandler.ins.aimDeviceInfos.arry[0]; if (aimDeviceInfo.type == (int)deviceType) return; } //PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("BConnectTipSuccess")); //1.默认选择第一个玩家(这里沿用了之前的设置信息代码,和蓝牙无关) BluetoothAim.ins.setBLEPlayer(BluetoothPlayer.FIRST_PLAYER); Debug.Log("[DevicesHolder]当前选择的操作用户:" + BluetoothAim.ins.getBLEPlayer()); AimHandler.ins.SetAimDeviceSelectIndex(0); //2.切换设备类型 AimHandler.ins.onCreateTempAimDeviceInfo(); switch (deviceType) { case AimDeviceType.HOUYI: case AimDeviceType.HOUYI2: case AimDeviceType.ARTEMIS: case AimDeviceType.HOUYIPRO: case AimDeviceType.Gun: case AimDeviceType.ARTEMISPRO: AimHandler.ins.SetTempAimDeviceType(deviceType); break; } Debug.Log("[DevicesHolder] SwitchDeviceByType deviceType :" + deviceType); //3.连接设备时候操作 //连接重新初始化 //进行重新初始化的时候。重置一下对应的mac AimHandler.ins.onCreateAimDeviceInfoById(); AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type); AimHandler.ins.ResetAimDeviceMac(); Debug.Log("[DevicesHolder]重新初始化时候 bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac); //切换 GlobalData.MyDeviceMode if (HomeView.ins) BluetoothAim.ins.SetMainConnectDeviceType(); } // Update is called once per frame //void Update() //{ //} }