DevicesHolder.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.HOUYI:
  48. case AimDeviceType.HOUYI2:
  49. case AimDeviceType.ARTEMIS:
  50. case AimDeviceType.HOUYIPRO:
  51. case AimDeviceType.Gun:
  52. case AimDeviceType.ARTEMISPRO:
  53. case AimDeviceType.PistolM17:
  54. case AimDeviceType.RifleM416:
  55. AimHandler.ins.SetTempAimDeviceType(deviceType);
  56. break;
  57. }
  58. Debug.Log("[DevicesHolder] SwitchDeviceByType deviceType :" + deviceType);
  59. //3.连接设备时候操作
  60. //连接重新初始化
  61. //进行重新初始化的时候。重置一下对应的mac
  62. AimHandler.ins.onCreateAimDeviceInfoById();
  63. AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
  64. AimHandler.ins.ResetAimDeviceMac();
  65. Debug.Log("[DevicesHolder]重新初始化时候 bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
  66. //切换 GlobalData.MyDeviceMode
  67. BluetoothAim.ins.SetMainConnectDeviceType();
  68. }
  69. // Update is called once per frame
  70. //void Update()
  71. //{
  72. //}
  73. }