DevicesHolder.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// 用于单机直连设备的设置操作
  6. /// </summary>
  7. public class DevicesHolder : MonoBehaviour
  8. {
  9. public static DevicesHolder ins;
  10. public static void Init()
  11. {
  12. if (!BluetoothHolder.ins)
  13. {
  14. GameObject devicesHolder = Resources.Load<GameObject>("Prefabs/DevicesHolder");
  15. Instantiate(devicesHolder);
  16. }
  17. }
  18. void Awake()
  19. {
  20. if (ins)
  21. {
  22. Destroy(this.gameObject);
  23. }
  24. else
  25. {
  26. ins = this;
  27. DontDestroyOnLoad(this.gameObject);
  28. }
  29. }
  30. // Start is called before the first frame update
  31. void Start()
  32. {
  33. }
  34. /// <summary>
  35. /// 目前应该只使用红外设备,就是 HOUYIPRO,ARTEMISPRO,Gun
  36. /// </summary>
  37. /// <param name="deviceType"></param>
  38. public void SwitchDeviceByType(AimDeviceType deviceType) {
  39. //1.默认选择第一个玩家(这里沿用了之前的设置信息代码,和蓝牙无关)
  40. BluetoothAim.ins.setBLEPlayer(BluetoothPlayer.FIRST_PLAYER);
  41. Debug.Log("[DevicesHolder]当前选择的操作用户:" + BluetoothAim.ins.getBLEPlayer());
  42. AimHandler.ins.SetAimDeviceSelectIndex(0);
  43. //2.切换设备类型
  44. AimHandler.ins.onCreateTempAimDeviceInfo();
  45. switch (deviceType)
  46. {
  47. case AimDeviceType.HOUYIPRO:
  48. case AimDeviceType.Gun:
  49. case AimDeviceType.ARTEMISPRO:
  50. AimHandler.ins.SetTempAimDeviceType(deviceType);
  51. break;
  52. }
  53. Debug.Log("[DevicesHolder] SwitchDeviceByType deviceType :" + deviceType);
  54. //3.连接设备时候操作
  55. //连接重新初始化
  56. //进行重新初始化的时候。重置一下对应的mac
  57. AimHandler.ins.onCreateAimDeviceInfoById();
  58. AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
  59. AimHandler.ins.ResetAimDeviceMac();
  60. Debug.Log("[DevicesHolder]重新初始化时候 bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
  61. //切换 GlobalData.MyDeviceMode
  62. BluetoothAim.ins.SetMainConnectDeviceType();
  63. }
  64. // Update is called once per frame
  65. //void Update()
  66. //{
  67. //}
  68. }