NewDemo.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using SmartBowSDK;
  5. using UnityEngine.UI;
  6. public class NewDemo : MonoBehaviour
  7. {
  8. [SerializeField] Toggle _DetectingMacToggle1;
  9. [SerializeField] Toggle _DetectingMacToggle2;
  10. SmartBowHelper smartBowHelper1;
  11. SmartBowHelper smartBowHelper2;
  12. //数据存储标识
  13. string userTags = "test";
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. smartBowHelper1 = SmartBowHelper.NewInstance();
  18. smartBowHelper2 = SmartBowHelper.NewInstance();
  19. Init(smartBowHelper1, GameObject.Find("A").GetComponent<Bow>());
  20. Init(smartBowHelper2, GameObject.Find("B").GetComponent<Bow>());
  21. SmartBowLogger.isDebug = true;
  22. //BleWinHelper.RegisterTo(this.gameObject);
  23. }
  24. void Init(SmartBowHelper smartBowHelper, Bow bow)
  25. {
  26. new SmartBowHandler(smartBowHelper, bow);
  27. }
  28. int deviceId = 1;
  29. public void Connect1()
  30. {
  31. //默认需要检测mac,bRecreateDeviceInfo:false.如不需要:设置bRecreateDeviceInfo:true;
  32. bool bRecreateDeviceInfo = _DetectingMacToggle1.isOn ? false : true;
  33. smartBowHelper1.Connect(userTags, deviceId, bRecreateDeviceInfo);
  34. }
  35. public void ClearDeviceInfo1()
  36. {
  37. smartBowHelper1.ClearDeviceInfo(userTags, deviceId);
  38. }
  39. int deviceId2 = 2;
  40. public void Connect2()
  41. { //默认需要检测mac,bRecreateDeviceInfo:false.如不需要:设置bRecreateDeviceInfo:true;
  42. bool bRecreateDeviceInfo = _DetectingMacToggle2.isOn ? false : true;
  43. smartBowHelper2.Connect(userTags, deviceId2, bRecreateDeviceInfo);
  44. }
  45. public void ClearDeviceInfo2()
  46. {
  47. smartBowHelper2.ClearDeviceInfo(userTags, deviceId2);
  48. }
  49. public void ClearAllDeviceInfo()
  50. {
  51. ClearDeviceInfo1();
  52. ClearDeviceInfo2();
  53. }
  54. public void getAllDeviceInfo()
  55. {
  56. AimDeviceInfo aimDeviceInfo1 = smartBowHelper1.GetDeviceInfo(userTags, deviceId);
  57. Debug.Log("设备1:" + JsonUtility.ToJson(aimDeviceInfo1));
  58. AimDeviceInfo aimDeviceInfo2 = smartBowHelper2.GetDeviceInfo(userTags, deviceId2);
  59. Debug.Log("设备2:" + JsonUtility.ToJson(aimDeviceInfo2));
  60. }
  61. }