DevicesHolder.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. if (CommonConfig.bDisableBluetooth) {
  52. //打开图标
  53. SimulateMouseController.ins?.SetBleConnected(true);
  54. //打靶和打猎需要设置为false
  55. BowCamera.isTouchMode = false;
  56. }
  57. //切换后算连接成功
  58. PopupMgr.ins.ClearAllTip();
  59. //这里判断一下如果是当前连接的不用重复调用设置了
  60. if (AimHandler.ins.aimDeviceInfos.arry.Count != 0) {
  61. AimDeviceInfo aimDeviceInfo = AimHandler.ins.aimDeviceInfos.arry[0];
  62. if (aimDeviceInfo.type == (int)deviceType) return;
  63. }
  64. //PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("BConnectTipSuccess"));
  65. //1.默认选择第一个玩家(这里沿用了之前的设置信息代码,和蓝牙无关)
  66. BluetoothAim.ins.setBLEPlayer(BluetoothPlayer.FIRST_PLAYER);
  67. Debug.Log("[DevicesHolder]当前选择的操作用户:" + BluetoothAim.ins.getBLEPlayer());
  68. AimHandler.ins.SetAimDeviceSelectIndex(0);
  69. //2.切换设备类型
  70. AimHandler.ins.onCreateTempAimDeviceInfo();
  71. switch (deviceType)
  72. {
  73. case AimDeviceType.HOUYI:
  74. case AimDeviceType.HOUYI2:
  75. case AimDeviceType.ARTEMIS:
  76. case AimDeviceType.HOUYIPRO:
  77. case AimDeviceType.Gun:
  78. case AimDeviceType.ARTEMISPRO:
  79. AimHandler.ins.SetTempAimDeviceType(deviceType);
  80. break;
  81. }
  82. Debug.Log("[DevicesHolder] SwitchDeviceByType deviceType :" + deviceType);
  83. //3.连接设备时候操作
  84. //连接重新初始化
  85. //进行重新初始化的时候。重置一下对应的mac
  86. AimHandler.ins.onCreateAimDeviceInfoById();
  87. AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
  88. AimHandler.ins.ResetAimDeviceMac();
  89. Debug.Log("[DevicesHolder]重新初始化时候 bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
  90. //切换 GlobalData.MyDeviceMode
  91. if (HomeView.ins) BluetoothAim.ins.SetMainConnectDeviceType();
  92. }
  93. // Update is called once per frame
  94. //void Update()
  95. //{
  96. //}
  97. }