AimHandler.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine.UI;
  6. public enum AimDeviceType {
  7. NONE = -1,
  8. HOUYI = 0,
  9. HOUYI2 = 1,
  10. HOUYI3 = 8,
  11. ARTEMIS = 2,
  12. HOUYIPRO = 3,
  13. //枪械类,现在默认是M9
  14. Gun = 4,
  15. ARTEMISPRO = 5,
  16. //枪械类:新增设备
  17. PistolM17 = 6,
  18. RifleM416 = 7
  19. }
  20. [Serializable]//需要在转换为json格式的类的上方添加序列化
  21. public class AimDeviceInfo
  22. {
  23. public int id;
  24. public int type = -1;//类型 AimDeviceType
  25. public int pos; //位置
  26. public bool bInitMac = false; //是否初始化Mac
  27. public string mac; //记录当前
  28. public AimDeviceInfo(int _id) {
  29. this.id = _id;
  30. }
  31. public void setInitMac(string macTemp) {
  32. bInitMac = true;
  33. mac = macTemp;
  34. }
  35. public void resetInitMac() {
  36. bInitMac = false;
  37. mac = "";
  38. }
  39. }
  40. [Serializable]
  41. public class AimDeviceInfos
  42. {
  43. public List<AimDeviceInfo> arry;
  44. }
  45. /* 瞄准处理器 */
  46. public class AimHandler : MonoBehaviour
  47. {
  48. CameraToLook m_controlObj {
  49. get {
  50. return CameraToLook.ins;
  51. }
  52. }
  53. //记录一个设备
  54. public AimDeviceInfo aimDeviceInfo = null;
  55. public AimDeviceInfo tempAimDeviceInfo = null;//临时处理值。最后赋值给aimDeviceInfo
  56. public AimDeviceInfos aimDeviceInfos = new AimDeviceInfos();
  57. int deviceSelectIndex = 0;//默认选中第一个设备(1p)
  58. public Action aimDeviceInfoChangeEvent;
  59. public int DeviceType
  60. {
  61. get
  62. {
  63. if (m_axisHandler.GetType() == typeof(Axis9Handler)) return 9;
  64. if (m_axisHandler.GetType() == typeof(Axis663Handler)) return 663;
  65. return 0;
  66. }
  67. }
  68. private AxisBaseHandler m_axisHandler;
  69. //陀螺仪校准进度记录
  70. [NonSerialized] public int gyrCalibrateCompleteCount = 0;
  71. [NonSerialized] public int gyrCalibrateTotalCount = 2000;
  72. public static AimHandler ins;
  73. public bool bInitOne = false;
  74. public OnCrossBtnEventEvent OnCrossBtnEvent;
  75. public delegate void OnCrossBtnEventEvent();
  76. /// <summary>
  77. /// 准心事件
  78. /// </summary>
  79. public void InvokeOnCrossBtnEvent()
  80. {
  81. try
  82. {
  83. OnCrossBtnEvent?.Invoke();
  84. }
  85. catch (Exception e)
  86. {
  87. Debug.LogError(e);
  88. }
  89. }
  90. void Start()
  91. {
  92. ins = this;
  93. BluetoothDispatcher.aim = OnDataReceived;
  94. // m_axisHandler = new Axis9NopackHandler(this); //九轴旧
  95. m_axisHandler = new Axis9Handler(this); //九轴新
  96. // m_axisHandler = new Axis663Handler(this); //双陀螺仪
  97. m_axisHandler.Init();
  98. // StartCoroutine(TestRecord());
  99. }
  100. public void onClearAimDeviceInfosNew()
  101. {
  102. PlayerPrefs.DeleteKey("aim-device-info-" + LoginMgr.myUserInfo.id);
  103. aimDeviceInfos.arry.Clear();
  104. }
  105. /// <summary>
  106. /// 移除2p。即除了1p之后的设备
  107. /// </summary>
  108. public void onClear2PAimDeviceInfosNew()
  109. {
  110. OnGetAimDeviceInfos();
  111. if (aimDeviceInfos.arry.Count > 1)
  112. {
  113. aimDeviceInfos.arry.RemoveRange(1, aimDeviceInfos.arry.Count - 1);
  114. }
  115. OnSaveAimDeviceInfos();
  116. }
  117. public void OnGetAimDeviceInfos() {
  118. string deviceInfo = PlayerPrefs.GetString("aim-device-info-" + LoginMgr.myUserInfo.id, "");
  119. //Debug.Log("get deviceSelectIndex:" + deviceInfo);
  120. if (deviceInfo != "")
  121. {
  122. aimDeviceInfos = JsonUtility.FromJson<AimDeviceInfos>(deviceInfo);//这里的类是依据最外层{}决定的
  123. }
  124. aimDeviceInfoChangeEvent?.Invoke();
  125. }
  126. public void OnSaveAimDeviceInfos()
  127. {
  128. aimDeviceInfoChangeEvent?.Invoke();
  129. PlayerPrefs.SetString("aim-device-info-" + LoginMgr.myUserInfo.id, JsonUtility.ToJson(aimDeviceInfos));
  130. }
  131. //创建一个选择值
  132. public void onCreateTempAimDeviceInfo() {
  133. tempAimDeviceInfo = new AimDeviceInfo(deviceSelectIndex);
  134. Debug.Log("onCreateTempAimDeviceInfo deviceSelectIndex:" + deviceSelectIndex);
  135. }
  136. //是否存在AimDeviceInfo,存在更新,不存在创建;
  137. public void onCreateAimDeviceInfoById()
  138. {
  139. OnGetAimDeviceInfos();
  140. //deviceIndex 区分 1p 还是 2p
  141. bool bCanAdd = true;
  142. foreach (AimDeviceInfo p in aimDeviceInfos.arry)
  143. {
  144. if (deviceSelectIndex == p.id)
  145. {
  146. aimDeviceInfo = p;
  147. bCanAdd = false;
  148. }
  149. //Debug.Log("33deviceSelectIndex:" + deviceSelectIndex + ",bCanAdd:" + bCanAdd+ " , id:" + p.id +" , type:"+ p.type);
  150. }
  151. if (bCanAdd)
  152. {
  153. //Debug.Log("add deviceSelectIndex:" + deviceSelectIndex);
  154. aimDeviceInfo = new AimDeviceInfo(deviceSelectIndex);
  155. aimDeviceInfos.arry.Add(aimDeviceInfo);
  156. }
  157. OnSaveAimDeviceInfos();
  158. }
  159. public void SetAimDeviceSelectIndex(int selectIndex) {
  160. if (selectIndex < 0) {
  161. Debug.LogWarning("selectIndex不能小于0:"+ selectIndex);
  162. return;
  163. }
  164. deviceSelectIndex = selectIndex;
  165. //Debug.Log("SetAimDeviceSelectIndex :" + selectIndex);
  166. }
  167. public void SetTempAimDeviceType(AimDeviceType _aimDeviceType)
  168. {
  169. if (tempAimDeviceInfo == null) return;
  170. tempAimDeviceInfo.type = (int)_aimDeviceType;
  171. }
  172. public void SetAimDeviceType(AimDeviceType _aimDeviceType)
  173. {
  174. if (aimDeviceInfo == null) return;
  175. aimDeviceInfo.type = (int)_aimDeviceType;
  176. _AimDeviceInfosUpdate();
  177. OnSaveAimDeviceInfos();
  178. }
  179. public void SetAimDeviceType(int _aimDeviceType)
  180. {
  181. if (aimDeviceInfo == null) return;
  182. aimDeviceInfo.type = _aimDeviceType;
  183. _AimDeviceInfosUpdate();
  184. OnSaveAimDeviceInfos();
  185. }
  186. //APP连接需进行MAC地址的比对。
  187. //只有再引导初始化页面才保存连接使用的mac地址。
  188. public void SetAimDeviceMac(string _mac) {
  189. if (aimDeviceInfo == null) return;
  190. aimDeviceInfo.setInitMac(_mac);
  191. _AimDeviceInfosUpdate();
  192. OnSaveAimDeviceInfos();
  193. }
  194. //重置mac存储信息
  195. public void ResetAimDeviceMac() {
  196. if (aimDeviceInfo == null) return;
  197. aimDeviceInfo.resetInitMac();
  198. _AimDeviceInfosUpdate();
  199. OnSaveAimDeviceInfos();
  200. }
  201. void _AimDeviceInfosUpdate() {
  202. for (int i = 0; i < aimDeviceInfos.arry.Count; i++)
  203. {
  204. if (aimDeviceInfo.id == aimDeviceInfos.arry[i].id)
  205. {
  206. aimDeviceInfos.arry[i] = aimDeviceInfo;
  207. }
  208. }
  209. }
  210. /// <summary>
  211. /// 寻找对应的AimDeviceInfo
  212. /// </summary>
  213. /// <param name="player"></param>
  214. /// <returns></returns>
  215. public AimDeviceInfo GetAimDeviceInfo(BluetoothPlayer player)
  216. {
  217. foreach (AimDeviceInfo p in AimHandler.ins.aimDeviceInfos.arry)
  218. {
  219. if ((int)player == p.id)
  220. {
  221. return p;
  222. }
  223. }
  224. // 如果没找到设备,可以返回 null 或者抛异常
  225. Debug.LogWarning($"未找到 {player} 的 AimDeviceInfo");
  226. return null;
  227. }
  228. #region 根据设备1p或者2p 获取HOUYIPRO的状态
  229. public bool isHOUYIPRO(BluetoothPlayer bluetoothPlayer)
  230. {
  231. bool _isHOUYIPRO = false;
  232. foreach (AimDeviceInfo p in AimHandler.ins.aimDeviceInfos.arry)
  233. {
  234. if ((int)bluetoothPlayer == p.id && p.type == (int)AimDeviceType.HOUYIPRO)
  235. {
  236. _isHOUYIPRO = true;
  237. }
  238. }
  239. return _isHOUYIPRO;
  240. }
  241. #endregion
  242. #region 根据设备1p或者2p 获取ARTEMISPro的状态
  243. public bool isARTEMISPro(BluetoothPlayer bluetoothPlayer)
  244. {
  245. bool _isARTEMISPro = false;
  246. foreach (AimDeviceInfo p in ins.aimDeviceInfos.arry)
  247. {
  248. if ((int)bluetoothPlayer == p.id && p.type == (int)AimDeviceType.ARTEMISPRO)
  249. {
  250. _isARTEMISPro = true;
  251. }
  252. }
  253. return _isARTEMISPro;
  254. }
  255. #endregion
  256. public void ReinitAxisHandler()
  257. {
  258. Debug.Log("ReinitAxisHandler");
  259. m_axisHandler.Init();
  260. }
  261. // System.Collections.IEnumerator TestRecord() {
  262. // while (LoginMgr.myUserInfo.id == 0) yield return null;
  263. // UserComp.Instance.saveMac();
  264. // }
  265. [NonSerialized] private Quaternion newRotation = Quaternion.identity;
  266. public void SetNewRotation(Quaternion quat) {
  267. this.newRotation = quat;
  268. }
  269. public void SetNewRotation(o0.Geometry.Quaternion o0Quat) {
  270. Quaternion quat = o0.Bow.Extension.ToUnityQuaternion(o0Quat);
  271. if (float.IsNaN(quat.x) || float.IsNaN(quat.y) || float.IsNaN(quat.z) || float.IsNaN(quat.w)) {
  272. Debug.LogError($"九轴Rotation存在Nan值,double:{o0Quat.ToString()},float:{quat.ToString()}");
  273. return;
  274. }
  275. if (float.IsInfinity(quat.x) || float.IsInfinity(quat.y) || float.IsInfinity(quat.z) || float.IsInfinity(quat.w)) {
  276. Debug.LogError($"九轴Rotation存在Infinity值,double:{o0Quat.ToString()},float:{quat.ToString()}");
  277. return;
  278. }
  279. this.newRotation = quat;
  280. }
  281. [NonSerialized] public bool lerpForRotation = true;
  282. [NonSerialized] public float lerpTimeRate = 7;
  283. //加一个枪射击的触发时间
  284. float _lastShootTime = 0;
  285. public void Update()
  286. {
  287. //&& !InfraredDemo.running
  288. if (m_controlObj && !m_ban9AxisCalculate && bRuning9Axis())
  289. {
  290. if (lerpForRotation)
  291. m_controlObj.localRotation = Quaternion.Lerp(m_controlObj.localRotation, newRotation, Time.deltaTime * lerpTimeRate);
  292. else
  293. m_controlObj.localRotation = newRotation;
  294. }
  295. if (IsMagCompleted())
  296. {
  297. if (!m_magCompleted)
  298. {
  299. StartCoroutine(SaveMag());
  300. PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("tip_mag-calibrate_success"));
  301. }
  302. m_magCompleted = true;
  303. } else {
  304. m_magCompleted = false;
  305. }
  306. //if (Input.GetKeyDown(KeyCode.Space))
  307. //{
  308. // //AutoResetView.DoIdentity();
  309. // CrossBtnEvent();
  310. //}
  311. }
  312. public void OnDataReceived(byte[] bytes)
  313. {
  314. if (bytes.Length != 27 && bytes.Length != 39)
  315. {
  316. if (bytes.Length == 2)
  317. {
  318. if (bytes[0] == 0x66 && bytes[1] == 0x31)
  319. {
  320. if (bInitOne)
  321. {
  322. bInitOne = false;
  323. if (aimDeviceInfo.type == (int)AimDeviceType.NONE ||
  324. aimDeviceInfo.type == (int)AimDeviceType.HOUYI ||
  325. aimDeviceInfo.type == (int)AimDeviceType.HOUYI2 ||
  326. aimDeviceInfo.type == (int)AimDeviceType.HOUYI3 ||
  327. aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS)
  328. {
  329. AutoResetView.DoIdentity();
  330. }
  331. else
  332. {
  333. //准心开关
  334. CrossBtnEvent();
  335. }
  336. }
  337. else
  338. {
  339. if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked)
  340. {
  341. //模拟鼠标弹出时候
  342. InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
  343. if (infraredGuider == null)
  344. {
  345. //视角回正
  346. DoIdentity();
  347. //鼠标居中自然会居中
  348. }
  349. //流程触发红外描点
  350. InfraredScreenPositioningView infraredScreenPositioningView = FindAnyObjectByType<InfraredScreenPositioningView>();
  351. if (infraredScreenPositioningView)
  352. {
  353. InvokeOnCrossBtnEvent();
  354. }
  355. }
  356. else
  357. {
  358. if (aimDeviceInfo.type == (int)AimDeviceType.NONE ||
  359. aimDeviceInfo.type == (int)AimDeviceType.HOUYI ||
  360. aimDeviceInfo.type == (int)AimDeviceType.HOUYI2 ||
  361. aimDeviceInfo.type == (int)AimDeviceType.HOUYI3 ||
  362. aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS)
  363. {
  364. AutoResetView.DoIdentity();
  365. }
  366. else
  367. {
  368. //准心开关
  369. CrossBtnEvent();
  370. }
  371. }
  372. }
  373. }
  374. else if (bytes[0] == 0x66 && bytes[1] == 0x32)
  375. {
  376. //红外部分
  377. if (GlobalData.MyDeviceMode == DeviceMode.Gun || BluetoothAim.ins && BluetoothAim.ins.isMainConnectToInfraredDevice())
  378. {
  379. InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
  380. //‘校准'功能的调用,使用原来调出光标的功能键;即在HOUYI Pro使用长按视角归位键;在ARTEMIS Pro使用快速双击按键
  381. if (infraredGuider == null)
  382. {
  383. AutoResetView.DoIdentity();
  384. }
  385. else
  386. {
  387. //先判断是否处于校准步骤
  388. infraredGuider.onLongClickDevice();
  389. }
  390. }
  391. else if (SB_EventSystem.ins)
  392. {
  393. // if (SB_EventSystem.ins && !CommonConfig.SpecialVersion1) {
  394. //唤起/隐藏虚拟鼠标
  395. SB_EventSystem.ins.AwakenSimulateMouse();
  396. }
  397. }
  398. else if (bytes[1] == 10)
  399. {
  400. //显示电量
  401. DeviceBatteryView.ins.RenderBattery(1, bytes[0]);
  402. //DeviceView.ins.RenderBattery(1, bytes[0]);
  403. }
  404. }
  405. else if (bytes[0] == 0x5b)
  406. {
  407. if (GlobalData.MyDeviceMode == DeviceMode.Gun)
  408. {
  409. if (Time.realtimeSinceStartup - _lastShootTime >= 1)
  410. {
  411. _lastShootTime = Time.realtimeSinceStartup;
  412. InfraredScreenPositioningView view = FindAnyObjectByType<InfraredScreenPositioningView>();
  413. if (view)
  414. {
  415. InvokeOnCrossBtnEvent();
  416. }
  417. }
  418. }
  419. // 无论如何都执行红外射击检测
  420. ShootCheck.ins.ShootByInfrared(bytes);
  421. }
  422. else if (bytes[0] == 0x5C)
  423. {
  424. //00 弹夹分离,01 上弹夹
  425. ShootCheck.ins.UpdateTheMagazine(bytes);
  426. }
  427. else if (bytes[0] == 0x60)
  428. {
  429. //枪械是否上膛
  430. ShootCheck.ins.UpdateChamberState(bytes);
  431. }
  432. else if (bytes[0] == 0x5E)
  433. {
  434. // Debug.Log("接收到系统数据:" + BitConverter.ToString(bytes));
  435. var boxUserSettings = FindAnyObjectByType<CustomUIView.BoxUserSettings>();
  436. //设备类型
  437. switch (bytes[1])
  438. {
  439. case 0x01:
  440. //Debug.Log("设备类型:HOUYI Pro");
  441. UserSettings.ins.selectDevicesName = "HOUYI Pro";
  442. UserSettings.ins.Save();
  443. boxUserSettings?.OnUpdateClickInfoByName();
  444. break;
  445. case 0x02:
  446. // Debug.Log("设备类型:ARTEMIS Pro");
  447. UserSettings.ins.selectDevicesName = "ARTEMIS Pro";
  448. UserSettings.ins.Save();
  449. boxUserSettings?.OnUpdateClickInfoByName();
  450. break;
  451. case 0x03:
  452. // Debug.Log("设备类型:Pistol 1");
  453. UserSettings.ins.selectDevicesName = "Pistol M9";
  454. UserSettings.ins.Save();
  455. boxUserSettings?.OnUpdateClickInfoByName();
  456. break;
  457. }
  458. // 系统类型
  459. //switch (bytes[2])
  460. //{
  461. // case 0x01:
  462. // Debug.Log("系统类型:移动手机");
  463. // break;
  464. // case 0x02:
  465. // Debug.Log("系统类型:PC电脑");
  466. // break;
  467. // case 0x03:
  468. // Debug.Log("系统类型:VR设备");
  469. // break;
  470. //}
  471. //记录接收到系统数据
  472. ShootCheck.ins.UpdateDeviceAndSysInfo(bytes);
  473. }
  474. return;
  475. }
  476. //if (InfraredDemo.running)
  477. //{
  478. // BluetoothAim.ins.WriteData("4"); //关闭九轴
  479. // return;
  480. //}
  481. if (!bRuning9Axis())
  482. {
  483. return;
  484. }
  485. m_axisHandler.Update(bytes);
  486. if (BowQuatDebug.ins) BowQuatDebug.ins.ShowModuleQuat(newRotation.eulerAngles);
  487. if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked) SB_EventSystem.ins.MoveSimulateMouse(newRotation);
  488. }
  489. public byte[] InsertByteAtBeginning(byte[] originalArray, byte newByte)
  490. {
  491. byte[] newArray = new byte[originalArray.Length + 1];
  492. newArray[0] = newByte;
  493. Array.Copy(originalArray, 0, newArray, 1, originalArray.Length);
  494. return newArray;
  495. }
  496. private bool m_magCompleted;
  497. public void CorrectMagCompleted(bool value) { m_magCompleted = value; }
  498. private bool m_ban9AxisCalculate = false;
  499. public void Ban9AxisCalculate(bool ban)
  500. {
  501. // m_ban9AxisCalculate = ban;
  502. // if (!ban)
  503. // {
  504. // SetMsOldDefault();
  505. // if (m_controlObj) m_controlObj.localRotation = newRotation;
  506. // }
  507. }
  508. public void SetMsOldDefault()
  509. {
  510. if (m_axisHandler.GetType() == typeof(Axis9NopackHandler))
  511. (m_axisHandler as Axis9NopackHandler).msOld = default;
  512. }
  513. public void DoIdentity()
  514. {
  515. //if (InfraredDemo.running) return;
  516. m_axisHandler.DoIdentity();
  517. if (!bRuning9Axis()) return;
  518. if (m_controlObj) m_controlObj.localRotation = newRotation;
  519. }
  520. public void NotifyAxisOnShot() { m_axisHandler.NotifyAxisOnShot(); }
  521. public void CalibrateGyr(bool calibration) { m_axisHandler.CalibrateGyr(calibration); }
  522. public void InitGyr(string record) { m_axisHandler.InitGyr(record); }
  523. public void InitMag(string record) { m_axisHandler.InitMag(record); }
  524. public void ResetGyr() { m_axisHandler.ResetGyr(); }
  525. public void ResetMag() { m_axisHandler.ResetMag(); }
  526. public void ApplyImpreciseMag() { m_axisHandler.ApplyImpreciseMag(); }
  527. public bool IsGyrCompleted() { return m_axisHandler.IsGyrCompleted(); }
  528. public bool IsMagCompleted() { return m_axisHandler.IsMagCompleted(); }
  529. public IEnumerator SaveGyr() { return m_axisHandler.SaveGyr(); }
  530. public IEnumerator SaveMag() { return m_axisHandler.SaveMag(); }
  531. public void ResumeCalibrateRecord(string record) { m_axisHandler.ResumeCalibrateRecord(record); }
  532. #region 获取一个连接的设备下,对应的 Archery 是运行9轴的代码处理位置信息判断
  533. public bool bRuning9Axis() {
  534. //连接的设备下,对应的 Archery 是运行9轴的代码处理位置信息判断
  535. //弓箭类型,但是不是HOUYI Pro 情况下。运行9轴代码
  536. bool bRuning = GlobalData.MyDeviceMode == DeviceMode.Archery && !BluetoothAim.ins.isMainConnectToInfraredDevice();
  537. return bRuning;
  538. }
  539. #endregion
  540. /// <summary>
  541. /// 操作准心开关事件
  542. /// </summary>
  543. private void CrossBtnEvent()
  544. {
  545. Debug.Log("CrossBtnEvent");
  546. //准心开关
  547. InvokeOnCrossBtnEvent();
  548. //b端不处理准心
  549. if (CommonConfig.StandaloneModeOrPlatformB) {
  550. InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
  551. if (infraredGuider)
  552. {
  553. infraredGuider.onClickDevice();
  554. }
  555. return;
  556. }
  557. if (GameAssistUI.ins)
  558. {
  559. InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
  560. if (infraredGuider == null)
  561. {
  562. //显示控制准心按钮
  563. Transform _button5 = GameAssistUI.ins.transform.Find("Button5");
  564. if (_button5.gameObject.activeSelf)
  565. {
  566. Button crossHairBtn = _button5.GetComponent<Button>();
  567. crossHairBtn.onClick.Invoke();
  568. }
  569. else
  570. {
  571. bool onlyShow = !CrossHair.ins.GetOnlyShow();
  572. CrossHair.ins.SetOnlyShow(onlyShow);
  573. //保存准心状态
  574. if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow);
  575. }
  576. }
  577. else {
  578. infraredGuider.onClickDevice();
  579. }
  580. //if (GameMgr.bShowDistance)
  581. //{
  582. // //显示控制准心按钮
  583. // Button crossHairBtn = GameAssistUI.ins.transform.Find("Button5").GetComponent<Button>();
  584. // crossHairBtn.onClick.Invoke();
  585. //}
  586. //else {
  587. // //校准
  588. // InfraredDemo._ins?.OnClick_SetAdjustPointsOffset();
  589. //}
  590. }
  591. else if (DuckHunter.GameUI.Instance)
  592. {
  593. //显示控制准心按钮
  594. Transform _btnCrosshair = DuckHunter.GameUI.Instance.transform.Find("BtnCrosshair");
  595. if (_btnCrosshair.gameObject.activeSelf)
  596. {
  597. Button crossHairBtn = _btnCrosshair.GetComponent<Button>();
  598. crossHairBtn.onClick.Invoke();
  599. }
  600. else {
  601. bool onlyShow = !DuckHunter.CrossHair.Instance.GetOnlyShow();
  602. DuckHunter.CrossHair.Instance.SetOnlyShow(onlyShow);
  603. //记录准心值
  604. if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow);
  605. }
  606. }
  607. else if (HyperspaceGame.UIManager._ins) {
  608. //打枪
  609. Transform _btnCrosshair = HyperspaceGame.UIManager._ins.transform.Find("BtnCrosshair");
  610. if (_btnCrosshair.gameObject.activeSelf)
  611. {
  612. Button crossHairBtn = _btnCrosshair.GetComponent<Button>();
  613. crossHairBtn.onClick.Invoke();
  614. }
  615. else {
  616. bool onlyShow = !HyperspaceGame.UIManager._ins.GetOnlyShow();
  617. HyperspaceGame.UIManager._ins.SetOnlyShow(onlyShow);
  618. //记录准心值
  619. if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow);
  620. }
  621. }
  622. else
  623. {
  624. if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("FruitMaster")){
  625. //水果
  626. GameObject _crosshairBtn = GameObject.Find("PermanentCanvas/CrossHair_Btn");
  627. if (_crosshairBtn.gameObject.activeSelf)
  628. {
  629. Button crossHairBtn = _crosshairBtn.GetComponent<Button>();
  630. crossHairBtn.onClick.Invoke();
  631. }
  632. else {
  633. bool onlyShow = !JCFruitMaster.ins.GetOnlyShow();
  634. JCFruitMaster.ins.SetOnlyShow(onlyShow);
  635. //记录准心值
  636. if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow);
  637. }
  638. }
  639. }
  640. }
  641. }