AimHandler.cs 23 KB

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