DevicesHolder.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. bool bConnected = false;
  11. public static void Init()
  12. {
  13. if (!BluetoothHolder.ins)
  14. {
  15. GameObject devicesHolder = Resources.Load<GameObject>("Prefabs/DevicesHolder");
  16. Instantiate(devicesHolder);
  17. }
  18. }
  19. void Awake()
  20. {
  21. if (ins)
  22. {
  23. Destroy(this.gameObject);
  24. }
  25. else
  26. {
  27. ins = this;
  28. DontDestroyOnLoad(this.gameObject);
  29. }
  30. }
  31. // Start is called before the first frame update
  32. void Start()
  33. {
  34. ShowConnectTip();
  35. }
  36. /// <summary>
  37. /// 提示正在连接
  38. /// </summary>
  39. public void ShowConnectTip() {
  40. if (!bConnected) {
  41. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("BConnectTip"), 15f);
  42. }
  43. }
  44. /// <summary>
  45. /// 目前应该只使用红外设备,就是 HOUYIPRO,ARTEMISPRO,Gun
  46. /// </summary>
  47. /// <param name="deviceType"></param>
  48. public void SwitchDeviceByType(AimDeviceType deviceType) {
  49. bConnected = true;
  50. //切换后算连接成功
  51. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("BConnectTipSuccess"));
  52. //1.默认选择第一个玩家(这里沿用了之前的设置信息代码,和蓝牙无关)
  53. BluetoothAim.ins.setBLEPlayer(BluetoothPlayer.FIRST_PLAYER);
  54. Debug.Log("[DevicesHolder]当前选择的操作用户:" + BluetoothAim.ins.getBLEPlayer());
  55. AimHandler.ins.SetAimDeviceSelectIndex(0);
  56. //2.切换设备类型
  57. AimHandler.ins.onCreateTempAimDeviceInfo();
  58. switch (deviceType)
  59. {
  60. case AimDeviceType.HOUYI:
  61. case AimDeviceType.HOUYI2:
  62. case AimDeviceType.ARTEMIS:
  63. case AimDeviceType.HOUYIPRO:
  64. case AimDeviceType.Gun:
  65. case AimDeviceType.ARTEMISPRO:
  66. AimHandler.ins.SetTempAimDeviceType(deviceType);
  67. break;
  68. }
  69. Debug.Log("[DevicesHolder] SwitchDeviceByType deviceType :" + deviceType);
  70. //3.连接设备时候操作
  71. //连接重新初始化
  72. //进行重新初始化的时候。重置一下对应的mac
  73. AimHandler.ins.onCreateAimDeviceInfoById();
  74. AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
  75. AimHandler.ins.ResetAimDeviceMac();
  76. Debug.Log("[DevicesHolder]重新初始化时候 bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
  77. //切换 GlobalData.MyDeviceMode
  78. BluetoothAim.ins.SetMainConnectDeviceType();
  79. }
  80. // Update is called once per frame
  81. //void Update()
  82. //{
  83. //}
  84. }