DevicesHolder.cs 2.8 KB

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