SmartBowHelper.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. using System;
  2. using UnityEngine;
  3. namespace SmartBowSDK
  4. {
  5. public class SmartBowHelper : MonoBehaviour
  6. {
  7. private static SmartBowHelper _Instance;
  8. internal SmartBowNetwork smartBowNetwork;
  9. internal BluetoothAim_SDK bluetoothAim;
  10. internal AimHandler_SDK aimHandler;
  11. internal ShootChecker_SDK shootChecker;
  12. public CalibrateDataStorageMode calibrateDataStorageMode = CalibrateDataStorageMode.Remote;
  13. void Awake()
  14. {
  15. DontDestroyOnLoad(gameObject);
  16. gameObject.AddComponent<AOTAdapter_SDK>();
  17. smartBowNetwork = gameObject.AddComponent<SmartBowNetwork>();
  18. bluetoothAim = gameObject.AddComponent<BluetoothAim_SDK>();
  19. aimHandler = gameObject.AddComponent<AimHandler_SDK>();
  20. shootChecker = gameObject.AddComponent<ShootChecker_SDK>();
  21. smartBowNetwork.smartBowHelper = this;
  22. bluetoothAim.smartBowHelper = this;
  23. aimHandler.smartBowHelper = this;
  24. shootChecker.smartBowHelper = this;
  25. }
  26. /// <summary>
  27. /// 获取唯一实例
  28. /// </summary>
  29. /// <returns></returns>
  30. public static SmartBowHelper GetInstance()
  31. {
  32. if (!_Instance) _Instance = new GameObject(typeof(SmartBowHelper).Name).AddComponent<SmartBowHelper>();
  33. return _Instance;
  34. }
  35. /// <summary>
  36. /// 创建新的实例
  37. /// </summary>
  38. /// <returns></returns>
  39. public static SmartBowHelper NewInstance()
  40. {
  41. return new GameObject(typeof(SmartBowHelper).Name).AddComponent<SmartBowHelper>();
  42. }
  43. /// <summary>
  44. /// 获取一个window 蓝牙用例
  45. /// </summary>
  46. /// <returns></returns>
  47. public BluetoothWindows CreateBluetoothWindows()
  48. {
  49. return bluetoothAim.CreateWindowBLE();
  50. }
  51. #region 手机验证
  52. /// <summary>
  53. /// 发送手机验证码
  54. /// </summary>
  55. public void SendPhoneValidateCode(string phone, int language, Action<RequestResult> callback)
  56. {
  57. smartBowNetwork.SendPhoneValidateCode(phone, language, callback);
  58. }
  59. /// <summary>
  60. /// 验证手机验证码
  61. /// </summary>
  62. public void ValidatePhone(string phone, int code, Action<RequestResult> callback)
  63. {
  64. smartBowNetwork.ValidatePhoneCode(phone, code, callback);
  65. }
  66. #endregion
  67. #region 邮箱验证
  68. /// <summary>
  69. /// 发送邮箱验证码
  70. /// </summary>
  71. public void SendEmailValidateCode(string email, int language, Action<RequestResult> callback)
  72. {
  73. smartBowNetwork.SendEmailValidateCode(email, language, callback);
  74. }
  75. /// <summary>
  76. /// 验证邮箱验证码
  77. /// </summary>
  78. public void ValidateEmail(string email, int code, Action<RequestResult> callback)
  79. {
  80. smartBowNetwork.SendEmailValidateCode(email, code, callback);
  81. }
  82. #endregion
  83. #region 注册
  84. /// <summary>
  85. /// 用户注册
  86. /// </summary>
  87. /// <param name="serverIndex">服务器索引</param>
  88. /// <param name="username">用户名</param>
  89. /// <param name="password">密码</param>
  90. /// <param name="email">邮箱</param>
  91. /// <param name="phone">手机号</param>
  92. /// <param name="code">当前接收的code,海外用邮箱 serverIndex = 1,国内 serverIndex = 0用手机号</param>
  93. /// <param name="callback">回调</param>
  94. public void Register(int serverIndex, string username, string password, string email, string phone,int code, Action<RequestResult> callback)
  95. {
  96. smartBowNetwork.RegisterByCode(serverIndex, username, password, email, phone, code, callback);
  97. }
  98. /// <summary>
  99. /// 重置密码(支持邮箱或手机号)
  100. /// </summary>
  101. /// <param name="serverIndex">服务器索引</param>
  102. /// <param name="account">账号(邮箱或手机号,现在国内用手机,海外用邮箱)</param>
  103. /// <param name="code">验证码</param>
  104. /// <param name="newPassword">新密码</param>
  105. /// <param name="callback">回调结果</param>
  106. public void ResetPassword(int serverIndex,string account, string codeAccount, int code, string newPassword, Action<RequestResult> callback)
  107. {
  108. smartBowNetwork.ResetPasswordByAccount(serverIndex, account, codeAccount, code, newPassword, callback);
  109. }
  110. #endregion
  111. #region 登录
  112. /// <summary>
  113. /// 用户登录
  114. /// </summary>
  115. /// <param name="gameID">游戏ID</param>
  116. /// <param name="channelID">渠道ID</param>
  117. /// <param name="username">账号</param>
  118. /// <param name="password">密码</param>
  119. /// <param name="callback">回调函数</param>
  120. public void Login(string gameID, string channelID, string username, string password, Action<LoginResult> callback)
  121. {
  122. smartBowNetwork.Login(gameID, channelID, username, password, callback);
  123. }
  124. /// <summary>
  125. /// 用户登出
  126. /// </summary>
  127. /// <param name="callback">回调函数</param>
  128. public void Logout(Action<bool> callback)
  129. {
  130. smartBowNetwork.Logout(callback);
  131. }
  132. /// <summary>
  133. /// 获取用户基本信息
  134. /// </summary>
  135. /// <param name="callback">回调函数</param>
  136. public void GetUserInfo(Action<GetUserInfoResult> callback)
  137. {
  138. smartBowNetwork.GetUserInfo(callback);
  139. }
  140. /// <summary>
  141. /// 设置用户名
  142. /// </summary>
  143. public void SaveUserName(string nickname, Action<RequestResult> callback)
  144. {
  145. smartBowNetwork.SaveUserName(nickname, callback);
  146. }
  147. /// <summary>
  148. /// 设置用户扩展信息
  149. /// </summary>
  150. public void SaveUserInfo(UserInfoExtended userInfo, Action<RequestResult> callback)
  151. {
  152. smartBowNetwork.SaveUserInfo(userInfo, callback);
  153. }
  154. #endregion
  155. #region 分数上传
  156. /// <summary>
  157. /// 上传单人赛季成绩
  158. /// </summary>
  159. public void UploadSeasonSinglePlayerGameRes(string secret, int score, Action<RequestResult> callback)
  160. {
  161. smartBowNetwork.UploadSeasonSinglePlayerGameRes(secret, score, callback);
  162. }
  163. /// <summary>
  164. /// 上传PK赛季成绩
  165. /// </summary>
  166. public void UploadSeasonPKGameRes(string roomKey, string secret, int p2ID, int gameRes, Action<RequestResult> callback)
  167. {
  168. smartBowNetwork.UploadSeasonPKGameRes(roomKey, secret, p2ID, gameRes, callback);
  169. }
  170. #endregion
  171. #region 排行榜
  172. /// <summary>
  173. /// 获取排行榜(按游戏类型)
  174. /// </summary>
  175. public void GetSeasonRankListByGameType(string secret, int rankArea, string country, string state, string city, Action<RequestResult> callback)
  176. {
  177. smartBowNetwork.GetSeasonRankListByGameType(secret, rankArea, country, state, city, callback);
  178. }
  179. /// <summary>
  180. /// 获取自定义排行榜
  181. /// </summary>
  182. public void GetSeasonRankListByCustom(string secret, int rankArea, string country, string state, string city, int rankType, int count, Action<RequestResult> callback)
  183. {
  184. smartBowNetwork.GetSeasonRankListByCustom(secret, rankArea, country, state, city, rankType, count, callback);
  185. }
  186. /// <summary>
  187. /// 获取当前用户的排名信息
  188. /// </summary>
  189. public void GetUserRankByGameType(string secret, int rankArea, string country, string state, string city, int rankType, int count, Action<RequestResult> callback)
  190. {
  191. smartBowNetwork.GetUserRankByGameType(secret, rankArea, country, state, city, rankType, count, callback);
  192. }
  193. #endregion
  194. #region 定制游戏上传接口
  195. /// <summary>
  196. /// 上传自定义排行榜分数
  197. /// </summary>
  198. public void UploadCustomLeaderboardScore(string secret, int taskId, int difficultType, int modeType, int deviceType, int score, Action<RequestResult> callback)
  199. {
  200. smartBowNetwork.UploadCustomLeaderboardScore(secret, taskId, difficultType, modeType, deviceType, score, callback);
  201. }
  202. /// <summary>
  203. /// 获取自定义排行榜数据
  204. /// </summary>
  205. public void GetCustomLeaderboard(string secret, int taskId, int difficultType, int modeType, int deviceType, int timeType, Action<RequestResult> callback)
  206. {
  207. smartBowNetwork.GetCustomLeaderboard(secret, taskId, difficultType, modeType, deviceType, timeType, callback);
  208. }
  209. #endregion
  210. #region 蓝牙:蓝牙部分新增修改,添加当前判断设备mac
  211. ///// <summary>
  212. ///// 连接蓝牙模块
  213. ///// </summary>
  214. //public void Connect()
  215. //{
  216. // //之前的默认不用判断mac
  217. // //当前连接不需要需要检测设备,设置为null
  218. // bluetoothAim.ResetAimDeviceInfoToNull();
  219. // bluetoothAim.Connect();
  220. //}
  221. /// <summary>
  222. /// 设置蓝牙过滤名称
  223. /// </summary>
  224. /// <param name="name">不传参数时候,设置值 ""</param>
  225. public void SetFilters(string name = "") {
  226. if (!string.IsNullOrWhiteSpace(name))
  227. {
  228. bluetoothAim.filters = name;
  229. }
  230. else {
  231. bluetoothAim.filters = "";
  232. }
  233. }
  234. /// <summary>
  235. /// 设置是否使用名称连接
  236. /// </summary>
  237. /// <param name="useName">是否使用名称连接</param>
  238. public void SetIsConnectName(bool useName)
  239. {
  240. bluetoothAim.isConnectName = useName;
  241. }
  242. /// <summary>
  243. /// 设置连接的MAC地址
  244. /// </summary>
  245. /// <param name="macStr">MAC地址字符串</param>
  246. public void SetConnectMacStr(string macStr)
  247. {
  248. if (!string.IsNullOrWhiteSpace(macStr))
  249. {
  250. bluetoothAim.connectMacStr = macStr;
  251. }
  252. }
  253. /// <summary>
  254. /// 设置传感器类型,用来区分解析
  255. /// </summary>
  256. /// <param name="sensorAxisType"></param>
  257. public void SetSensorAxisType(SensorAxisType sensorAxisType)
  258. {
  259. bluetoothAim.sensorAxisType = sensorAxisType;
  260. SmartBowLogger.Log(this, "SetSensorAxisType:" + bluetoothAim.sensorAxisType);
  261. }
  262. /// <summary>
  263. /// 连接蓝牙模块
  264. /// 新增连接操作,需要用户标签和设备id
  265. /// userTags: 存储的信息标签,按实际用户区分
  266. /// deviceId:对应设备id,同一个用户下的不同设备
  267. /// bRecreateDeviceInfo: 重新创建设备信息。false 的情况下默认限制mac
  268. /// </summary>
  269. public void Connect(string userTags,int deviceId, bool bRecreateDeviceInfo = false)
  270. {
  271. if (userTags == null || userTags.Length == 0)
  272. {
  273. SmartBowLogger.LogError(this, $"清除信息错误,userTags不能为空!");
  274. return;
  275. }
  276. if (deviceId <= 0)
  277. {
  278. SmartBowLogger.LogError(this, $"清除信息错误,deviceId 不能小于等于 0!");
  279. return;
  280. }
  281. //判断mac需要创建一个连接信息
  282. bluetoothAim.initAimDeviceInfo(userTags,deviceId,bRecreateDeviceInfo);
  283. //进行蓝牙连接
  284. bluetoothAim.Connect();
  285. }
  286. /// <summary>
  287. /// 清空建立的蓝牙判断数据
  288. /// userTags: 存储的信息标签,按实际用户区分
  289. /// deviceId:对应设备id,同一个用户下的不同设备
  290. /// </summary>
  291. public void ClearDeviceInfo(string userTags,int deviceId)
  292. {
  293. if (userTags == null || userTags.Length == 0)
  294. {
  295. SmartBowLogger.LogError(this, $"清除信息错误,userTags不能为空!");
  296. return;
  297. }
  298. if (deviceId <= 0)
  299. {
  300. SmartBowLogger.LogError(this, $"清除信息错误,deviceId 不能小于等于 0!");
  301. return ;
  302. }
  303. bluetoothAim.onClearAimDeviceInfoByDeviceId(userTags, deviceId);
  304. }
  305. /// <summary>
  306. /// 获取存储的数据
  307. /// userTags: 存储的信息标签,按实际用户区分
  308. /// deviceId:对应设备id,同一个用户下的不同设备
  309. /// </summary>
  310. public AimDeviceInfo GetDeviceInfo(string userTags, int deviceId) {
  311. if (userTags == null || userTags.Length == 0)
  312. {
  313. SmartBowLogger.LogError(this, $"清除信息错误,userTags不能为空!");
  314. return null;
  315. }
  316. if (deviceId <= 0)
  317. {
  318. SmartBowLogger.LogError(this, $"清除信息错误,deviceId 不能小于等于 0!");
  319. return null;
  320. }
  321. return bluetoothAim.onGetAimDeviceInfos(userTags, deviceId);
  322. }
  323. /// <summary>
  324. /// 断开蓝牙模块
  325. /// </summary>
  326. public void Disconnect()
  327. {
  328. bluetoothAim.Disconnect();
  329. }
  330. /// <summary>
  331. /// 获取蓝牙状态
  332. /// </summary>
  333. /// <returns>蓝牙状态</returns>
  334. public BluetoothStatusEnum GetBluetoothStatus()
  335. {
  336. return bluetoothAim.bluetoothStatus;
  337. }
  338. /// <summary>
  339. /// 监听蓝牙状态变化
  340. /// </summary>
  341. public event BluetoothStatusChangedEvent OnBluetoothStatusChanged;
  342. /// <summary>
  343. /// 判断蓝牙模块是否初始化完成
  344. /// </summary>
  345. /// <returns>蓝牙模块是否初始化完成</returns>
  346. public bool IsBluetoothModuleInited()
  347. {
  348. return bluetoothAim.moduleInited;
  349. }
  350. /// <summary>
  351. /// 监听蓝牙模块初始化完成
  352. /// Tip:连接蓝牙模块成功后会有几秒的初始化过程,初始化完成后才能进行传感器相关的函数调用。
  353. /// </summary>
  354. public Action OnBluetoothModuleInited;
  355. /// <summary>
  356. /// 监听蓝牙错误
  357. /// </summary>
  358. public event BluetoothErrorEvent OnBluetoothError;
  359. /// <summary>
  360. /// 获取Mac地址
  361. /// Tip:需要模块初始化完成才能获取
  362. /// </summary>
  363. /// <returns>如果返回null则是获取失败</returns>
  364. public string GetMacAddress()
  365. {
  366. return bluetoothAim.macAddress;
  367. }
  368. /// <summary>
  369. /// 获取硬件固件版本
  370. /// Tip:需要模块初始化完成才能获取
  371. /// </summary>
  372. /// <returns>如果返回null则是获取失败</returns>
  373. public string GetDeviceVersion()
  374. {
  375. return bluetoothAim.deviceVersion;
  376. }
  377. /// <summary>
  378. /// 获取电量
  379. /// Tip:需要模块初始化完成才能获取
  380. /// </summary>
  381. /// <returns>电量值(范围0~100),值为0时也代表获取失败</returns>
  382. public int GetBattery()
  383. {
  384. return bluetoothAim.battery;
  385. }
  386. /// <summary>
  387. /// 设置目标设备名称(用于搜索和连接)
  388. /// </summary>
  389. /// <param name="deviceName">设备名称</param>
  390. public void SetTargetDeviceName(string deviceName)
  391. {
  392. bluetoothAim.deviceConfig.deviceName = deviceName;
  393. }
  394. #endregion
  395. #region 传感器
  396. /// <summary>
  397. /// 开启九轴传感
  398. /// </summary>
  399. /// <returns>请求是否发送成功</returns>
  400. public bool StartRotationSensor()
  401. {
  402. return bluetoothAim.RequestOpen9Axis();
  403. }
  404. /// <summary>
  405. /// 停止九轴传感
  406. /// </summary>
  407. /// <returns>请求是否发送成功</returns>
  408. public bool StopRotationSensor()
  409. {
  410. return bluetoothAim.RequestClose9Axis();
  411. }
  412. /// <summary>
  413. /// 监听姿态角更新
  414. /// </summary>
  415. public event RotationUpdateEvent OnRotationUpdate;
  416. /// <summary>
  417. /// 开启射箭传感
  418. /// </summary>
  419. /// <returns>请求是否发送成功</returns>
  420. public bool StartShootingSensor()
  421. {
  422. return bluetoothAim.RequestOpenInfrared();
  423. }
  424. /// <summary>
  425. /// 停止射箭传感
  426. /// </summary>
  427. /// <returns>请求是否发送成功</returns>
  428. public bool StopShootingSensor()
  429. {
  430. return bluetoothAim.RequestCloseInfrared();
  431. }
  432. /// <summary>
  433. /// 监听射箭
  434. /// </summary>
  435. public ShootingEvent OnShooting;
  436. /// <summary>
  437. /// 开始陀螺仪校准
  438. /// </summary>
  439. public void StartGyrCalibration()
  440. {
  441. aimHandler.StartGyrCalibration();
  442. }
  443. /// <summary>
  444. /// 停止陀螺仪校准
  445. /// </summary>
  446. public void StopGyrCalibration()
  447. {
  448. aimHandler.StopGyrCalibration();
  449. }
  450. /// <summary>
  451. /// 判断陀螺仪是否正在校准
  452. /// </summary>
  453. /// <returns>陀螺仪是否正在校准</returns>
  454. public bool IsGyrCalibrating()
  455. {
  456. return aimHandler.IsGyrCalibrating();
  457. }
  458. /// <summary>
  459. /// 获取陀螺仪校准进度
  460. /// </summary>
  461. /// <returns>陀螺仪校准进度</returns>
  462. public float GetGyrProgress()
  463. {
  464. return aimHandler.GetGyrProgress();
  465. }
  466. /// <summary>
  467. /// 判断陀螺仪是否校准完成
  468. /// </summary>
  469. /// <returns>陀螺仪是否校准完成</returns>
  470. public bool IsGyrCompleted()
  471. {
  472. return aimHandler.IsGyrCompleted();
  473. }
  474. /// <summary>
  475. /// 开始地磁计校准
  476. /// </summary>
  477. public void StartMagCalibration()
  478. {
  479. aimHandler.StartMagCalibration();
  480. }
  481. /// <summary>
  482. /// 判断地磁计是否校准完成
  483. /// </summary>
  484. /// <returns>地磁计是否校准完成</returns>
  485. public bool IsMagCompleted()
  486. {
  487. return aimHandler.IsMagCompleted();
  488. }
  489. /// <summary>
  490. /// 视角归位
  491. /// </summary>
  492. public void ResetAim()
  493. {
  494. aimHandler.DoIdentity();
  495. }
  496. /// <summary>
  497. /// 监听模块的功能键短按
  498. /// </summary>
  499. public Action OnFunctionKeyPress;
  500. /// <summary>
  501. /// 监听模块的功能键长按
  502. /// </summary>
  503. public Action OnFunctionKeyLongPress;
  504. #endregion
  505. /// <summary>
  506. /// 蓝牙状态变化事件
  507. /// </summary>
  508. /// <param name="oldStatus">旧状态</param>
  509. /// <param name="newStatus">新状态</param>
  510. public delegate void BluetoothStatusChangedEvent(BluetoothStatusEnum oldStatus, BluetoothStatusEnum newStatus);
  511. internal void InvokeOnBluetoothStatusChanged(BluetoothStatusEnum oldStatus, BluetoothStatusEnum newStatus)
  512. {
  513. try
  514. {
  515. OnBluetoothStatusChanged?.Invoke(oldStatus, newStatus);
  516. }
  517. catch (Exception e)
  518. {
  519. Debug.LogError(e);
  520. }
  521. }
  522. /// <summary>
  523. /// 蓝牙错误事件
  524. /// </summary>
  525. /// <param name="error">错误类型</param>
  526. /// <param name="message">消息描述</param>
  527. public delegate void BluetoothErrorEvent(BluetoothError error, string message);
  528. internal void InvokeOnBluetoothError(BluetoothError error, string message)
  529. {
  530. try
  531. {
  532. OnBluetoothError?.Invoke(error, message);
  533. }
  534. catch (Exception e)
  535. {
  536. Debug.LogError(e);
  537. }
  538. }
  539. internal void InvokeOnFunctionKeyPress()
  540. {
  541. try
  542. {
  543. OnFunctionKeyPress?.Invoke();
  544. }
  545. catch (Exception e)
  546. {
  547. Debug.LogError(e);
  548. }
  549. }
  550. internal void InvokeOnFunctionKeyLongPress()
  551. {
  552. try
  553. {
  554. OnFunctionKeyLongPress?.Invoke();
  555. }
  556. catch (Exception e)
  557. {
  558. Debug.LogError(e);
  559. }
  560. }
  561. /// <summary>
  562. /// 姿态角更新事件
  563. /// </summary>
  564. /// <param name="rotation">姿态角</param>
  565. public delegate void RotationUpdateEvent(Quaternion rotation);
  566. internal void InvokeOnRotationUpdate(Quaternion rotation)
  567. {
  568. if (bluetoothAim.bluetoothStatus != BluetoothStatusEnum.Connected) return;
  569. try
  570. {
  571. OnRotationUpdate?.Invoke(rotation);
  572. }
  573. catch (Exception e)
  574. {
  575. Debug.LogError(e);
  576. }
  577. }
  578. /// <summary>
  579. /// 射箭事件
  580. /// </summary>
  581. /// <param name="speed">速度(m/s)</param>
  582. public delegate void ShootingEvent(float speed);
  583. internal void InvokeOnShooting(float speed)
  584. {
  585. try
  586. {
  587. OnShooting?.Invoke(speed);
  588. }
  589. catch (Exception e)
  590. {
  591. Debug.LogError(e);
  592. }
  593. }
  594. internal void InvokeOnBluetoothModuleInited()
  595. {
  596. try
  597. {
  598. OnBluetoothModuleInited?.Invoke();
  599. }
  600. catch (Exception e)
  601. {
  602. Debug.LogError(e);
  603. }
  604. }
  605. /// <summary>
  606. /// 监听枪状态
  607. /// </summary>
  608. public BleDeviceEvent OnBleDeviceState;
  609. /// <summary>
  610. /// 硬件对应的事件
  611. /// </summary>
  612. public delegate void BleDeviceEvent(BluetoothDeviceType bleDeviceType, BluetoothDeviceStatus gunStatusEnum);
  613. internal void InvokeOnBleDevice(BluetoothDeviceType bleDeviceType, BluetoothDeviceStatus gunStatusEnum)
  614. {
  615. try
  616. {
  617. OnBleDeviceState?.Invoke(bleDeviceType,gunStatusEnum);
  618. }
  619. catch (Exception e)
  620. {
  621. Debug.LogError(e);
  622. }
  623. }
  624. /// <summary>
  625. /// 监听设备状态和连接的设备平台信息
  626. /// </summary>
  627. public DeviceAndSystemInfoEvent OnDeviceAndSystemInfoEvent;
  628. /// <summary>
  629. /// 硬件对应的事件初始化回调
  630. /// </summary>
  631. public delegate void DeviceAndSystemInfoEvent(ConnectPlatform connectPlatform,BluetoothDeviceType bleDeviceType);
  632. internal void InvokeOnDeviceAndSystemInfoEvent(ConnectPlatform connectPlatform, BluetoothDeviceType bleDeviceType)
  633. {
  634. try
  635. {
  636. OnDeviceAndSystemInfoEvent?.Invoke(connectPlatform, bleDeviceType);
  637. }
  638. catch (Exception e)
  639. {
  640. Debug.LogError(e);
  641. }
  642. }
  643. #region 6轴部分接口
  644. /// <summary>
  645. /// 6轴数据重置初始位置数据
  646. /// </summary>
  647. public void ResetSixAxisIdentity()
  648. {
  649. bluetoothAim.ResetSixAxisFusion();
  650. }
  651. /// <summary>
  652. /// 监听姿态角更新
  653. /// </summary>
  654. public event SixAxisRotationUpdateEvent OnSixAxisRotationUpdate;
  655. /// <summary>
  656. /// 姿态角更新事件
  657. /// </summary>
  658. /// <param name="rotation">姿态角</param>
  659. public delegate void SixAxisRotationUpdateEvent(Vector3 eulerAngles);
  660. internal void InvokeOnSixAxisRotationUpdate(Vector3 eulerAngles)
  661. {
  662. if (bluetoothAim.bluetoothStatus != BluetoothStatusEnum.Connected) return;
  663. try
  664. {
  665. OnSixAxisRotationUpdate?.Invoke(eulerAngles);
  666. }
  667. catch (Exception e)
  668. {
  669. Debug.LogError(e);
  670. }
  671. }
  672. ///// <summary>
  673. ///// 芯片数据更新事件
  674. ///// </summary>
  675. ///// <param name="rotation">姿态角</param>
  676. //public delegate void AxisDataUpdateEvent(byte[] value);
  677. //internal void InvokeOnAxisDataUpdateEvent(byte[] value)
  678. //{
  679. // if (bluetoothAim.bluetoothStatus != BluetoothStatusEnum.Connected) return;
  680. // try
  681. // {
  682. // OnAxisDataUpdate?.Invoke(value);
  683. // }
  684. // catch (Exception e)
  685. // {
  686. // Debug.LogError(e);
  687. // }
  688. //}
  689. ///// <summary>
  690. ///// 芯片数据更新
  691. ///// </summary>
  692. //public event AxisDataUpdateEvent OnAxisDataUpdate;
  693. #endregion
  694. }
  695. }