InfraredDemo.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using SmartBowSDK;
  6. using InfraredManager;
  7. using ZIM;
  8. using SLAMUVC;
  9. using System;
  10. /// <summary>
  11. /// 红外 + 蓝牙的使用示例脚本
  12. /// </summary>
  13. public class InfraredDemo : MonoBehaviour
  14. {
  15. public static InfraredDemo _ins;
  16. public static double MapValue(double value, double originalMin, double originalMax, double targetMin, double targetMax)
  17. {
  18. // 线性插值公式
  19. return targetMin + (value - originalMin) * (targetMax - targetMin) / (originalMax - originalMin);
  20. }
  21. private void Awake()
  22. {
  23. _ins = this;
  24. }
  25. void Start()
  26. {
  27. InitBluetoothModule();
  28. InitInfraredCamera();
  29. }
  30. void Update()
  31. {
  32. UpdateBluetoothModule();
  33. UpdateBluetoothModule6Axis();
  34. UpdateInfraredCamera();
  35. }
  36. #region 红外摄像
  37. public static bool running { get => infraredCameraHelper != null; }
  38. public static InfraredCameraHelper infraredCameraHelper { get; set; }
  39. [SerializeField] RawImage _cameraRender;
  40. [SerializeField] RawImage _imageScreenLocateManual;
  41. [SerializeField] List<RectTransform> _crosshairsInCamera;
  42. [SerializeField] Slider _sliderBrightness;
  43. [SerializeField] Slider _sliderContrast;
  44. [SerializeField] Slider _sliderShakeFilter;
  45. [SerializeField] Button _btnReset;
  46. [SerializeField] Button _btnScreenLocateManual;
  47. [SerializeField] Button _btnScreenLocateManualAuto;
  48. [SerializeField] Dropdown _dropdownResolution;
  49. [SerializeField] Text _fpsText;
  50. int frames;
  51. float lastCheckTime;
  52. //屏幕上ui的点
  53. List<Vector2> _screenLocatePoints = new();
  54. //屏幕内的点
  55. List<Vector2> _locatePointList = new();
  56. //public ParamFloatValue brightness = new ParamFloatValue("ic_brightness", 50.0f);
  57. // public ParamFloatValue contrast = new ParamFloatValue("ic_contrast", 50.0f);
  58. public ParamFloatValue shakeFilterValue = new ParamFloatValue("ic_shakeFilterValue2", 6.0f);
  59. public ParamFloatValue resoution = new ParamFloatValue("ic_resoution2", 2);
  60. string[] sliderNameArray = new string[]{
  61. "亮度", //
  62. "对比度"};
  63. string[] sliderStrArray = new string[]{
  64. "PU_BRIGHTNESS",
  65. "PU_CONTRAST"};
  66. UVCManager.CameraInfo currentCameraInfo;
  67. void InitInfraredCamera()
  68. {
  69. //SDK创建
  70. Vector2 saveResolution = GetResolution((int)resoution.Get());
  71. infraredCameraHelper = InfraredCameraHelper.GetInstance();
  72. infraredCameraHelper.Create((int)saveResolution.x, (int)saveResolution.y);
  73. //位置更新
  74. infraredCameraHelper.OnPositionUpdate += (Vector2 point) =>
  75. {
  76. Ray ray = Camera.main.ScreenPointToRay(point);
  77. Vector3 rayEndPoint = ray.GetPoint(200);
  78. Bow.Instance.transform.LookAt(rayEndPoint);
  79. };
  80. infraredCameraHelper.OnUVCIsReady += (UVCManager.CameraInfo camera) =>
  81. {
  82. if (currentCameraInfo != null) return;
  83. currentCameraInfo = camera;
  84. //生成控制摄像机的参数滑条
  85. Debug.Log("初始化摄像机!");
  86. //参数面板
  87. for (int i = 0; i < sliderStrArray.Length; i++)
  88. {
  89. string typeStr = sliderStrArray[i];
  90. UVCCtrlInfo _UVCCtrlInfo = camera.GetInfo(typeStr);
  91. int _curValue = _UVCCtrlInfo.current;
  92. //指定默认值
  93. //5、UVC亮度 - 50
  94. //6、UVC对比度 - 50
  95. if (typeStr == "PU_BRIGHTNESS")
  96. {
  97. _sliderBrightness.minValue = _UVCCtrlInfo.min;
  98. _sliderBrightness.maxValue = _UVCCtrlInfo.max;
  99. _sliderBrightness.wholeNumbers = true;
  100. SetBrightness(typeStr, _curValue);
  101. _sliderBrightness.onValueChanged.AddListener((newValue) =>
  102. {
  103. SetBrightness(typeStr, newValue);
  104. });
  105. }
  106. else if (typeStr == "PU_CONTRAST")
  107. {
  108. _sliderContrast.minValue = _UVCCtrlInfo.min;
  109. _sliderContrast.maxValue = _UVCCtrlInfo.max;
  110. _sliderContrast.wholeNumbers = true;
  111. SetContrast(typeStr, _curValue);
  112. _sliderContrast.onValueChanged.AddListener((newValue) =>
  113. {
  114. SetContrast(typeStr, newValue);
  115. });
  116. }
  117. }
  118. SetShakeFilterValue(shakeFilterValue.Get());
  119. _sliderShakeFilter.onValueChanged.AddListener(SetShakeFilterValue);
  120. //功能按钮
  121. _btnReset.onClick.AddListener(OnClick_Reset);
  122. _btnScreenLocateManual.onClick.AddListener(OnClick_ScreenLocateManual);
  123. _btnScreenLocateManualAuto.onClick.AddListener(OnClick_ScreenLocateAuto);
  124. //分辨率修改
  125. _dropdownResolution.onValueChanged.AddListener(v =>
  126. {
  127. SetResolution(v);
  128. });
  129. //算法红外阈值
  130. infraredCameraHelper.SetInfraredLocateBrightnessThreshold(0.8f);
  131. };
  132. //屏幕变化时候
  133. infraredCameraHelper.OnUVCPosUpdate += (list) =>
  134. {
  135. Debug.Log("OnUVCPosUpdate");
  136. SetLocatePointsToCameraRender(list, 1, 1);
  137. };
  138. }
  139. void UpdateInfraredCamera()
  140. {
  141. if (infraredCameraHelper == null) return;
  142. if (infraredCameraHelper.GetCameraTexture())
  143. {
  144. if (_cameraRender.texture == null || infraredCameraHelper.GetCameraTexture().GetNativeTexturePtr() != _cameraRender.texture.GetNativeTexturePtr())
  145. _cameraRender.texture = infraredCameraHelper.GetCameraTexture();
  146. }
  147. //手动定位
  148. if (infraredCameraHelper.IsScreenLocateManualDoing())
  149. {
  150. //引导提示
  151. string tipText = "单击屏幕 左下角";
  152. if (_screenLocatePoints.Count == 0) _locatePointList.Clear();
  153. if (_screenLocatePoints.Count == 1) tipText = "单击屏幕 右下角";
  154. if (_screenLocatePoints.Count == 2) tipText = "单击屏幕 右上角";
  155. if (_screenLocatePoints.Count == 3) tipText = "单击屏幕 左上角";
  156. _imageScreenLocateManual.transform.Find("Text").GetComponent<Text>().text = tipText;
  157. //点击检测
  158. if (Input.GetMouseButtonDown(0))
  159. {
  160. Vector2 mouse = Input.mousePosition;
  161. float u = Mathf.Clamp01(mouse.x / Screen.width);
  162. float v = Mathf.Clamp01(mouse.y / Screen.height);
  163. u = Math.Clamp(u, 0, 1);
  164. v = Math.Clamp(v, 0, 1);
  165. _locatePointList.Add(new Vector2(u, v));
  166. float texWidth = _imageScreenLocateManual.texture.width;
  167. float texHeight = _imageScreenLocateManual.texture.height;
  168. Vector2 texPoint = new Vector2(u * texWidth, v * texHeight);
  169. _screenLocatePoints.Add(texPoint);
  170. }
  171. //定位点显示
  172. Transform pointsTF = _imageScreenLocateManual.transform.Find("Points");
  173. for (int i = 0; i < pointsTF.childCount; i++)
  174. {
  175. Transform pointTF = pointsTF.GetChild(i);
  176. if (i < _screenLocatePoints.Count)
  177. {
  178. float texWidth = _imageScreenLocateManual.texture.width;
  179. float texHeight = _imageScreenLocateManual.texture.height;
  180. Vector2 texSize = new Vector2(texWidth, texHeight);
  181. Vector2 pos = _screenLocatePoints[i];
  182. pointTF.localPosition = pos.pixelToLocalPosition_AnchorCenter(texSize, _imageScreenLocateManual.rectTransform.rect);
  183. pointTF.gameObject.SetActive(true);
  184. }
  185. else pointTF.gameObject.SetActive(false);
  186. }
  187. //完成定位
  188. if (_screenLocatePoints.Count == 4)
  189. {
  190. _imageScreenLocateManual.gameObject.SetActive(false);
  191. SetLocatePointsToCameraRender(_screenLocatePoints, _imageScreenLocateManual.texture.width, _imageScreenLocateManual.texture.height);
  192. infraredCameraHelper.QuitScreenLocateManual(_locatePointList);
  193. }
  194. }
  195. //在相机画面显示准心
  196. if (ScreenLocate.Main)
  197. {
  198. var _sl = ScreenLocate.Main;
  199. var buffer = _sl.infraredSpotBuffer;
  200. if (buffer != null)
  201. {
  202. for (int i = 0; i < buffer.Length; i++)
  203. {
  204. if (buffer[i].CameraLocation != null)
  205. {
  206. //添加一个偏移量,使得最后输出的准心是指向正中心
  207. Vector2 newPoint2 = _sl.GetOffsetCameraLocation(buffer[i].CameraLocation.Value);
  208. // 检测到光点
  209. var pos = newPoint2.pixelToLocalPosition_AnchorCenter(_sl.mUVCCameraInfo.Size, _cameraRender.rectTransform.rect);
  210. _crosshairsInCamera[i].gameObject.SetActive(true);
  211. _crosshairsInCamera[i].anchoredPosition = pos;
  212. }
  213. else
  214. _crosshairsInCamera[i].gameObject.SetActive(false);
  215. }
  216. }
  217. }
  218. //性能检测
  219. ++frames;
  220. float timeNow = Time.realtimeSinceStartup;
  221. const float UpdateInterval = 0.5f;
  222. if (timeNow > lastCheckTime + UpdateInterval)
  223. {
  224. float fps = (float)(frames / (timeNow - lastCheckTime));
  225. frames = 0;
  226. lastCheckTime = timeNow;
  227. _fpsText.text = "FPS:" + fps.ToString("f2");
  228. }
  229. }
  230. public void SetLocatePointsToCameraRender(List<Vector2> points, float w, float h)
  231. {
  232. Transform pointsTF2 = _cameraRender.transform.Find("Points");
  233. if (pointsTF2.childCount == points.Count)
  234. {
  235. Vector2 texSize = new Vector2(w, h);
  236. for (int i = 0; i < pointsTF2.childCount; i++)
  237. {
  238. Transform pointTF = pointsTF2.GetChild(i);
  239. Vector2 pos = points[i];
  240. pointTF.localPosition = pos.pixelToLocalPosition_AnchorCenter(texSize, _cameraRender.rectTransform.rect);
  241. pointTF.gameObject.SetActive(true);
  242. }
  243. }
  244. }
  245. /// <summary>
  246. /// 亮度
  247. /// </summary>
  248. /// <param name="typeStr"></param>
  249. /// <param name="v"></param>
  250. void SetBrightness(string typeStr, float v)
  251. {
  252. var _value = Mathf.FloorToInt(v);
  253. currentCameraInfo.SetValue(typeStr, _value);
  254. //brightness.Set(v);
  255. _sliderBrightness.SetValueWithoutNotify(v);
  256. _sliderBrightness.transform.Find("Value").GetComponent<Text>().text = v.ToString("f1");
  257. }
  258. /// <summary>
  259. /// 对比度
  260. /// </summary>
  261. /// <param name="typeStr"></param>
  262. /// <param name="v"></param>
  263. void SetContrast(string typeStr, float v)
  264. {
  265. var _value = Mathf.FloorToInt(v);
  266. currentCameraInfo.SetValue(typeStr, _value);
  267. //contrast.Set(v);
  268. _sliderContrast.SetValueWithoutNotify(v);
  269. _sliderContrast.transform.Find("Value").GetComponent<Text>().text = v.ToString("f1");
  270. }
  271. void SetShakeFilterValue(float v)
  272. {
  273. shakeFilterValue.Set(v);
  274. _sliderShakeFilter.SetValueWithoutNotify(shakeFilterValue.Get());
  275. _sliderShakeFilter.transform.Find("Value").GetComponent<Text>().text = shakeFilterValue.Get().ToString("f1");
  276. InfraredCameraHelper.GetInstance().SetShakeFilterValue(shakeFilterValue.Get());
  277. }
  278. void SetResolution(int optionIndex)
  279. {
  280. resoution.Set(optionIndex);
  281. _dropdownResolution.SetValueWithoutNotify(optionIndex);
  282. switch (optionIndex)
  283. {
  284. case 0:
  285. infraredCameraHelper.SetCameraResolutionNew(1280, 720);
  286. break;
  287. case 1:
  288. infraredCameraHelper.SetCameraResolutionNew(640, 360);
  289. break;
  290. case 2:
  291. infraredCameraHelper.SetCameraResolutionNew(320, 240);
  292. break;
  293. case 3:
  294. infraredCameraHelper.SetCameraResolutionNew(160, 120);
  295. break;
  296. }
  297. }
  298. Vector2 GetResolution(int optionIndex)
  299. {
  300. _dropdownResolution.SetValueWithoutNotify(optionIndex);
  301. Vector2 vect = new Vector2(320, 240);
  302. switch (optionIndex)
  303. {
  304. case 0:
  305. vect = new Vector2(1280, 720);
  306. break;
  307. case 1:
  308. vect = new Vector2(640, 360);
  309. break;
  310. case 2:
  311. vect = new Vector2(320, 240);
  312. break;
  313. case 3:
  314. vect = new Vector2(160, 120);
  315. break;
  316. }
  317. return vect;
  318. }
  319. void OnClick_Reset()
  320. {
  321. SetBrightness("PU_BRIGHTNESS", 50);
  322. SetContrast("PU_CONTRAST", 50);
  323. SetShakeFilterValue(6);
  324. }
  325. void OnClick_ScreenLocateManual()
  326. {
  327. if (infraredCameraHelper.IsScreenLocateManualDoing()) return;
  328. Texture2D texture2D = infraredCameraHelper.EnterScreenLocateManual();
  329. if (texture2D == null)
  330. {
  331. infraredCameraHelper.QuitScreenLocateManual(null);
  332. return;
  333. }
  334. _imageScreenLocateManual.texture = texture2D;
  335. //_imageScreenLocateManual.material = infraredCameraHelper.GetCameraMaterial();
  336. _screenLocatePoints.Clear();
  337. _imageScreenLocateManual.gameObject.SetActive(true);
  338. }
  339. void OnClick_ScreenLocateAuto()
  340. {
  341. infraredCameraHelper.EnterScreenLocateManualAuto();
  342. }
  343. public void OnClick_SetAdjustPointsOffset()
  344. {
  345. var _sl = ScreenLocate.Main;
  346. var buffer = _sl.infraredSpotBuffer;
  347. if (buffer != null)
  348. {
  349. for (int i = 0; i < buffer.Length; i++)
  350. {
  351. if (buffer[i].CameraLocation != null)
  352. {
  353. Debug.Log("CameraLocation:" + buffer[i].CameraLocation.Value);
  354. var centerOffset = infraredCameraHelper.GetCenterOffset(buffer[i].CameraLocation.Value, "CameraLocation");
  355. Debug.Log("CenterOffset: " + centerOffset);
  356. var uvCenterOffset = infraredCameraHelper.GetCenterOffset(buffer[i].ScreenUV.Value, "ScreenUV");
  357. Debug.Log("UvCenterOffset: " + uvCenterOffset);
  358. }
  359. }
  360. }
  361. }
  362. #endregion
  363. #region 蓝牙模块
  364. [SerializeField] Button _btnConnect;
  365. [SerializeField] Text _textMacAddress;
  366. [SerializeField] Text _textBattery;
  367. SmartBowHelper OriginSmartBowHelper;
  368. //六轴部分按钮操作
  369. [SerializeField] Button _btnConnect6Axis;
  370. [SerializeField] Text _textMacAddress6Axis;
  371. [SerializeField] Text _textBattery6Axis;
  372. SmartBowHelper BGBoxSmartBowHelper;
  373. [SerializeField] GameObject _BGBoxObj;
  374. void InitBluetoothModule()
  375. {
  376. SmartBowLogger.isDebug = true;
  377. OriginSmartBowHelper = SmartBowHelper.NewInstance();
  378. OriginSmartBowHelper.OnBluetoothModuleInited += OnBluetoothModuleInited;
  379. OriginSmartBowHelper.OnBluetoothError += OnBluetoothError;
  380. OriginSmartBowHelper.OnShooting += OnShooting;
  381. _btnConnect.onClick.AddListener(OnClick_Connect);
  382. //6轴部分代码
  383. BGBoxSmartBowHelper = SmartBowHelper.NewInstance();
  384. BGBoxSmartBowHelper.OnBluetoothModuleInited += OnBluetoothModuleInited6Axis;
  385. BGBoxSmartBowHelper.OnBluetoothError += OnBluetoothError6Axis;
  386. BGBoxSmartBowHelper.OnSixAxisRotationUpdate += (eulerAngles) =>
  387. {
  388. _BGBoxObj.transform.eulerAngles = eulerAngles;
  389. };
  390. //识别当前手柄
  391. BGBoxSmartBowHelper.SetFilters("BGBox_202012");
  392. //设置手柄解析
  393. BGBoxSmartBowHelper.SetSensorAxisType(SensorAxisType.SixAxisSensor);
  394. _btnConnect6Axis.onClick.AddListener(OnClick_ConnectBGBox);
  395. if (BluetoothWindows.IsWindows()) {
  396. BleWinHelper.RegisterTo(OriginSmartBowHelper.gameObject, OriginSmartBowHelper.CreateBluetoothWindows());
  397. BleWinHelper.RegisterTo(BGBoxSmartBowHelper.gameObject, BGBoxSmartBowHelper.CreateBluetoothWindows());
  398. }
  399. //Debug.Log("InitBluetoothModule");
  400. }
  401. void UpdateBluetoothModule()
  402. {
  403. //更新显示蓝牙状态
  404. BluetoothStatusEnum bluetoothStatus = OriginSmartBowHelper.GetBluetoothStatus();
  405. Text btnConnectText = _btnConnect.GetComponentInChildren<Text>();
  406. if (bluetoothStatus == BluetoothStatusEnum.None) btnConnectText.text = "<color=blue>未连接</color>(点击连接)";
  407. if (bluetoothStatus == BluetoothStatusEnum.Connecting) btnConnectText.text = "<color=#FF670D>连接中</color>";
  408. if (bluetoothStatus == BluetoothStatusEnum.Connected)
  409. {
  410. if (OriginSmartBowHelper.IsBluetoothModuleInited()) btnConnectText.text = "<color=green>已连接</color>(点击断开)";
  411. else btnConnectText.text = "<color=green>已连接</color><color=blue>(正在初始化)</color>";
  412. }
  413. //更新显示电量
  414. int battery = OriginSmartBowHelper.GetBattery();
  415. _textBattery.text = battery > 0 ? $"电量值:{battery}" : "未获得电量值";
  416. //更新显示Mac地址
  417. string macAddress = OriginSmartBowHelper.GetMacAddress();
  418. _textMacAddress.text = macAddress != null ? $"Mac地址:{macAddress}" : "未获得Mac地址";
  419. }
  420. void OnBluetoothModuleInited()
  421. {
  422. OriginSmartBowHelper.StartRotationSensor();
  423. OriginSmartBowHelper.StartShootingSensor();
  424. }
  425. void OnBluetoothError(BluetoothError error, string message)
  426. {
  427. Debug.Log("OnBluetoothError:" + error);
  428. if (error == BluetoothError.ScanNotFoundTargetDevice)
  429. {
  430. TipText.Show("连接失败,未发现目标设备!");
  431. return;
  432. }
  433. TipText.Show(message);
  434. }
  435. void OnShooting(float speed)
  436. {
  437. Bow.Instance.Shoot();
  438. }
  439. void OnClick_Connect()
  440. {
  441. if (OriginSmartBowHelper.GetBluetoothStatus() == BluetoothStatusEnum.Connecting) return;
  442. if (OriginSmartBowHelper.GetBluetoothStatus() == BluetoothStatusEnum.None)
  443. {
  444. OriginSmartBowHelper.Connect("test", 1);
  445. return;
  446. }
  447. if (OriginSmartBowHelper.GetBluetoothStatus() == BluetoothStatusEnum.Connected)
  448. {
  449. OriginSmartBowHelper.Disconnect();
  450. return;
  451. }
  452. }
  453. /// <summary>
  454. /// 更新BGBox信息
  455. /// </summary>
  456. void UpdateBluetoothModule6Axis()
  457. {
  458. //更新显示蓝牙状态
  459. BluetoothStatusEnum bluetoothStatus = BGBoxSmartBowHelper.GetBluetoothStatus();
  460. Text btnConnectText = _btnConnect6Axis.GetComponentInChildren<Text>();
  461. if (bluetoothStatus == BluetoothStatusEnum.None) btnConnectText.text = "<color=blue>未连接</color>(点击连接)";
  462. if (bluetoothStatus == BluetoothStatusEnum.Connecting) btnConnectText.text = "<color=#FF670D>连接中</color>";
  463. if (bluetoothStatus == BluetoothStatusEnum.Connected)
  464. {
  465. if (BGBoxSmartBowHelper.IsBluetoothModuleInited()) btnConnectText.text = "<color=green>已连接</color>(点击断开)";
  466. else btnConnectText.text = "<color=green>已连接</color><color=blue>(正在初始化)</color>";
  467. }
  468. //更新显示电量
  469. int battery = BGBoxSmartBowHelper.GetBattery();
  470. _textBattery6Axis.text = battery > 0 ? $"电量值:{battery}" : "未获得电量值";
  471. //更新显示Mac地址
  472. string macAddress = BGBoxSmartBowHelper.GetMacAddress();
  473. _textMacAddress6Axis.text = macAddress != null ? $"Mac地址:{macAddress}" : "未获得Mac地址";
  474. }
  475. void OnBluetoothModuleInited6Axis()
  476. {
  477. BGBoxSmartBowHelper.StartRotationSensor();
  478. }
  479. public void Open6Axis()
  480. {
  481. BGBoxSmartBowHelper.StartRotationSensor();
  482. }
  483. public void Close6Axis() {
  484. BGBoxSmartBowHelper.StopRotationSensor();
  485. }
  486. public void Reset6Axis()
  487. {
  488. // if(sixAxisFusion!=null) sixAxisFusion.ResetToInitialRotation();
  489. BGBoxSmartBowHelper.ResetSixAxisIdentity();
  490. }
  491. void OnBluetoothError6Axis(BluetoothError error, string message)
  492. {
  493. Debug.Log("6Axis OnBluetoothError:" + error);
  494. if (error == BluetoothError.ScanNotFoundTargetDevice)
  495. {
  496. TipText.Show("连接失败,未发现目标设备!");
  497. return;
  498. }
  499. TipText.Show(message);
  500. }
  501. void OnClick_ConnectBGBox() {
  502. if (BGBoxSmartBowHelper.GetBluetoothStatus() == BluetoothStatusEnum.Connecting) return;
  503. if (BGBoxSmartBowHelper.GetBluetoothStatus() == BluetoothStatusEnum.None)
  504. {
  505. BGBoxSmartBowHelper.Connect("test2", 1);
  506. return;
  507. }
  508. if (BGBoxSmartBowHelper.GetBluetoothStatus() == BluetoothStatusEnum.Connected)
  509. {
  510. BGBoxSmartBowHelper.Disconnect();
  511. return;
  512. }
  513. }
  514. #endregion
  515. }
  516. public class ParamFloatValue
  517. {
  518. private string _saveKey;
  519. private float _valueDefault;
  520. private bool _valueLoaded;
  521. private float _value;
  522. public ParamFloatValue(string saveKey, float valueDefault)
  523. {
  524. _saveKey = saveKey;
  525. _valueDefault = valueDefault;
  526. }
  527. public float Get()
  528. {
  529. if (!_valueLoaded) _value = PlayerPrefs.GetFloat(_saveKey, _valueDefault);
  530. return _value;
  531. }
  532. public void Set(float value)
  533. {
  534. _value = value;
  535. PlayerPrefs.SetFloat(_saveKey, _value);
  536. PlayerPrefs.Save();
  537. }
  538. }