| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using AppUI.Bluetooth;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using AppUIAimHandler = AppUI.Bluetooth.AimHandler;
- /// <summary>
- /// 用于单机直连设备的设置操作
- /// </summary>
- public class DevicesHolder : MonoBehaviour
- {
- public static DevicesHolder ins;
- 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()
- {
-
- }
- /// <summary>
- /// 目前应该只使用红外设备,就是 HOUYIPRO,ARTEMISPRO,Gun
- /// </summary>
- /// <param name="deviceType"></param>
- public void SwitchDeviceByType(AimDeviceType deviceType)
- {
- SmartBowDeviceHub.EnsureReady();
- SmartBowDeviceHub hub = SmartBowDeviceHub.ins;
- AppUIAimHandler aim = hub?.Aim;
- if (hub == null || aim == null)
- {
- Debug.LogError("[DevicesHolder] SmartBowDeviceHub 未就绪");
- return;
- }
- //1.默认选择第一个玩家(这里沿用了之前的设置信息代码,和蓝牙无关)
- hub.SetActivePlayer(BluetoothPlayer.FIRST_PLAYER);
- Debug.Log("[DevicesHolder]当前选择的操作用户:" + hub.GetActivePlayer());
- aim.SetAimDeviceSelectIndex(0);
- //2.切换设备类型
- aim.onCreateTempAimDeviceInfo();
- switch (deviceType)
- {
- case AimDeviceType.HOUYI:
- case AimDeviceType.HOUYI2:
- case AimDeviceType.HOUYI3:
- case AimDeviceType.ARTEMIS:
- case AimDeviceType.HOUYIPRO:
- case AimDeviceType.Gun:
- case AimDeviceType.ARTEMISPRO:
- case AimDeviceType.PistolM17:
- case AimDeviceType.RifleM416:
- aim.SetTempAimDeviceType(deviceType);
- break;
- }
- Debug.Log("[DevicesHolder] SwitchDeviceByType deviceType :" + deviceType);
- //3.连接设备时候操作
- //连接重新初始化
- //进行重新初始化的时候。重置一下对应的mac
- aim.onCreateAimDeviceInfoById();
- aim.SetAimDeviceType(aim.GetTempDeviceType());
- aim.ResetAimDeviceMac();
- Debug.Log("[DevicesHolder]重新初始化时候 bInitMac :" + aim.aimDeviceInfo.bInitMac);
- //切换 GlobalData.MyDeviceMode
- hub.SetMainConnectDeviceType();
- }
- // Update is called once per frame
- //void Update()
- //{
- //}
- }
|