SmartBowHandler.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using SmartBowSDK;
  5. public class SmartBowHandler
  6. {
  7. SmartBowHelper smartBowHelper;
  8. Bow bow;
  9. public SmartBowHandler(SmartBowHelper smartBowHelper, Bow bow)
  10. {
  11. smartBowHelper.OnBluetoothModuleInited += OnBluetoothModuleInited;
  12. smartBowHelper.OnRotationUpdate += OnRotationUpdate;
  13. smartBowHelper.OnShooting += OnShooting;
  14. smartBowHelper.OnBleDeviceState += OnBleDeviceState;
  15. smartBowHelper.OnFunctionKeyPress += OnFunctionKeyPress;
  16. this.smartBowHelper = smartBowHelper;
  17. this.bow = bow;
  18. }
  19. void OnBluetoothModuleInited()
  20. {
  21. smartBowHelper.StartRotationSensor();
  22. smartBowHelper.StartShootingSensor();
  23. }
  24. void OnRotationUpdate(Quaternion rotation)
  25. {
  26. bow.transform.localRotation = rotation;
  27. }
  28. void OnShooting(float speed)
  29. {
  30. bow.Shoot();
  31. }
  32. void OnFunctionKeyPress()
  33. {
  34. smartBowHelper.ResetAim();
  35. }
  36. void OnBleDeviceState(BluetoothDeviceType bluetoothDeviceType, BluetoothDeviceStatus bluetoothDeviceStatus)
  37. {
  38. Debug.Log("设备类型:" + bluetoothDeviceType + "设备状态" + bluetoothDeviceStatus);
  39. if (bluetoothDeviceType == BluetoothDeviceType.Pistol1) {
  40. if (bluetoothDeviceStatus == BluetoothDeviceStatus.MagazineSeparation)
  41. {
  42. this.bow.info.text = "设备类型:枪" + ",状态:弹夹分离";
  43. Debug.Log(this.bow.info.text);
  44. }
  45. else if (bluetoothDeviceStatus == BluetoothDeviceStatus.MagazineLoading)
  46. {
  47. this.bow.info.text = "设备类型:枪" + ",状态:弹夹上膛";
  48. Debug.Log(this.bow.info.text);
  49. }
  50. else {
  51. this.bow.info.text = "设备类型:枪" + ",其他状态:" + bluetoothDeviceStatus;
  52. Debug.Log(this.bow.info.text);
  53. }
  54. }
  55. }
  56. }