AimHandler.cs 24 KB

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