SmartBowHelper.cs 26 KB

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