| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- /// <summary>
- /// 用于单机直连设备的设置操作
- /// </summary>
- public class DevicesHolder : MonoBehaviour
- {
- public static DevicesHolder ins;
- bool bConnected = false;
- public static void Init()
- {
- if (!BluetoothHolder.ins)
- {
- GameObject devicesHolder = Resources.Load<GameObject>("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();
- }
- /// <summary>
- /// 提示正在连接
- /// </summary>
- public void ShowConnectTip() {
- if (!bConnected) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("BConnectTip"), 15f);
- }
- }
- /// <summary>
- /// 目前应该只使用红外设备,就是 HOUYIPRO,ARTEMISPRO,Gun
- /// </summary>
- /// <param name="deviceType"></param>
- 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()
- //{
-
- //}
- }
|