AimHandler.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. /// <summary>
  210. /// 寻找对应的AimDeviceInfo
  211. /// </summary>
  212. /// <param name="player"></param>
  213. /// <returns></returns>
  214. public AimDeviceInfo GetAimDeviceInfo(BluetoothPlayer player)
  215. {
  216. foreach (AimDeviceInfo p in AimHandler.ins.aimDeviceInfos.arry)
  217. {
  218. if ((int)player == p.id)
  219. {
  220. return p;
  221. }
  222. }
  223. // 如果没找到设备,可以返回 null 或者抛异常
  224. Debug.LogWarning($"未找到 {player} 的 AimDeviceInfo");
  225. return null;
  226. }
  227. #region 根据设备1p或者2p 获取HOUYIPRO的状态
  228. public bool isHOUYIPRO(BluetoothPlayer bluetoothPlayer)
  229. {
  230. bool _isHOUYIPRO = false;
  231. foreach (AimDeviceInfo p in AimHandler.ins.aimDeviceInfos.arry)
  232. {
  233. if ((int)bluetoothPlayer == p.id && p.type == (int)AimDeviceType.HOUYIPRO)
  234. {
  235. _isHOUYIPRO = true;
  236. }
  237. }
  238. return _isHOUYIPRO;
  239. }
  240. #endregion
  241. #region 根据设备1p或者2p 获取ARTEMISPro的状态
  242. public bool isARTEMISPro(BluetoothPlayer bluetoothPlayer)
  243. {
  244. bool _isARTEMISPro = false;
  245. foreach (AimDeviceInfo p in ins.aimDeviceInfos.arry)
  246. {
  247. if ((int)bluetoothPlayer == p.id && p.type == (int)AimDeviceType.ARTEMISPRO)
  248. {
  249. _isARTEMISPro = true;
  250. }
  251. }
  252. return _isARTEMISPro;
  253. }
  254. #endregion
  255. public void ReinitAxisHandler()
  256. {
  257. Debug.Log("ReinitAxisHandler");
  258. m_axisHandler.Init();
  259. }
  260. // System.Collections.IEnumerator TestRecord() {
  261. // while (LoginMgr.myUserInfo.id == 0) yield return null;
  262. // UserComp.Instance.saveMac();
  263. // }
  264. [NonSerialized] private Quaternion newRotation = Quaternion.identity;
  265. public void SetNewRotation(Quaternion quat) {
  266. this.newRotation = quat;
  267. }
  268. public void SetNewRotation(o0.Geometry.Quaternion o0Quat) {
  269. Quaternion quat = o0.Bow.Extension.ToUnityQuaternion(o0Quat);
  270. if (float.IsNaN(quat.x) || float.IsNaN(quat.y) || float.IsNaN(quat.z) || float.IsNaN(quat.w)) {
  271. Debug.LogError($"九轴Rotation存在Nan值,double:{o0Quat.ToString()},float:{quat.ToString()}");
  272. return;
  273. }
  274. if (float.IsInfinity(quat.x) || float.IsInfinity(quat.y) || float.IsInfinity(quat.z) || float.IsInfinity(quat.w)) {
  275. Debug.LogError($"九轴Rotation存在Infinity值,double:{o0Quat.ToString()},float:{quat.ToString()}");
  276. return;
  277. }
  278. this.newRotation = quat;
  279. }
  280. [NonSerialized] public bool lerpForRotation = true;
  281. [NonSerialized] public float lerpTimeRate = 7;
  282. //加一个枪射击的触发时间
  283. float _lastShootTime = 0;
  284. public void Update()
  285. {
  286. //&& !InfraredDemo.running
  287. if (m_controlObj && !m_ban9AxisCalculate && bRuning9Axis())
  288. {
  289. if (lerpForRotation)
  290. m_controlObj.localRotation = Quaternion.Lerp(m_controlObj.localRotation, newRotation, Time.deltaTime * lerpTimeRate);
  291. else
  292. m_controlObj.localRotation = newRotation;
  293. }
  294. if (IsMagCompleted())
  295. {
  296. if (!m_magCompleted)
  297. {
  298. StartCoroutine(SaveMag());
  299. PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("tip_mag-calibrate_success"));
  300. }
  301. m_magCompleted = true;
  302. } else {
  303. m_magCompleted = false;
  304. }
  305. //if (Input.GetKeyDown(KeyCode.Space))
  306. //{
  307. // //AutoResetView.DoIdentity();
  308. // CrossBtnEvent();
  309. //}
  310. }
  311. public void OnDataReceived(byte[] bytes)
  312. {
  313. if (bytes.Length != 27 && bytes.Length != 39)
  314. {
  315. if (bytes.Length == 2)
  316. {
  317. if (bytes[0] == 0x66 && bytes[1] == 0x31)
  318. {
  319. if (bInitOne)
  320. {
  321. bInitOne = false;
  322. if (aimDeviceInfo.type == (int)AimDeviceType.NONE ||
  323. aimDeviceInfo.type == (int)AimDeviceType.HOUYI ||
  324. aimDeviceInfo.type == (int)AimDeviceType.HOUYI2 ||
  325. aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS)
  326. {
  327. AutoResetView.DoIdentity();
  328. }
  329. else
  330. {
  331. //准心开关
  332. CrossBtnEvent();
  333. }
  334. }
  335. else
  336. {
  337. if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked)
  338. {
  339. //模拟鼠标弹出时候
  340. InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
  341. if (infraredGuider == null)
  342. {
  343. //视角回正
  344. DoIdentity();
  345. //鼠标居中自然会居中
  346. }
  347. //流程触发红外描点
  348. InfraredScreenPositioningView infraredScreenPositioningView = FindAnyObjectByType<InfraredScreenPositioningView>();
  349. if (infraredScreenPositioningView)
  350. {
  351. InvokeOnCrossBtnEvent();
  352. }
  353. }
  354. else
  355. {
  356. if (aimDeviceInfo.type == (int)AimDeviceType.NONE ||
  357. aimDeviceInfo.type == (int)AimDeviceType.HOUYI ||
  358. aimDeviceInfo.type == (int)AimDeviceType.HOUYI2 ||
  359. aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS)
  360. {
  361. AutoResetView.DoIdentity();
  362. }
  363. else
  364. {
  365. //准心开关
  366. CrossBtnEvent();
  367. }
  368. }
  369. }
  370. }
  371. else if (bytes[0] == 0x66 && bytes[1] == 0x32)
  372. {
  373. //红外部分
  374. if (GlobalData.MyDeviceMode == DeviceMode.Gun || BluetoothAim.ins && BluetoothAim.ins.isMainConnectToInfraredDevice())
  375. {
  376. InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
  377. //‘校准'功能的调用,使用原来调出光标的功能键;即在HOUYI Pro使用长按视角归位键;在ARTEMIS Pro使用快速双击按键
  378. if (infraredGuider == null)
  379. {
  380. AutoResetView.DoIdentity();
  381. }
  382. else
  383. {
  384. //先判断是否处于校准步骤
  385. infraredGuider.onLongClickDevice();
  386. }
  387. }
  388. else if (SB_EventSystem.ins)
  389. {
  390. // if (SB_EventSystem.ins && !CommonConfig.SpecialVersion1) {
  391. //唤起/隐藏虚拟鼠标
  392. SB_EventSystem.ins.AwakenSimulateMouse();
  393. }
  394. }
  395. else if (bytes[1] == 10)
  396. {
  397. //显示电量
  398. DeviceBatteryView.ins.RenderBattery(1, bytes[0]);
  399. //DeviceView.ins.RenderBattery(1, bytes[0]);
  400. }
  401. }
  402. else if (bytes[0] == 0x5b)
  403. {
  404. if (GlobalData.MyDeviceMode == DeviceMode.Gun)
  405. {
  406. if (Time.realtimeSinceStartup - _lastShootTime >= 1)
  407. {
  408. _lastShootTime = Time.realtimeSinceStartup;
  409. InfraredScreenPositioningView view = FindAnyObjectByType<InfraredScreenPositioningView>();
  410. if (view)
  411. {
  412. InvokeOnCrossBtnEvent();
  413. }
  414. }
  415. }
  416. // 无论如何都执行红外射击检测
  417. ShootCheck.ins.ShootByInfrared(bytes);
  418. }
  419. else if (bytes[0] == 0x5C)
  420. {
  421. //00 弹夹分离,01 上弹夹
  422. ShootCheck.ins.UpdateTheMagazine(bytes);
  423. }
  424. else if (bytes[0] == 0x60)
  425. {
  426. //枪械是否上膛
  427. ShootCheck.ins.UpdateChamberState(bytes);
  428. }
  429. else if (bytes[0] == 0x5E)
  430. {
  431. // Debug.Log("接收到系统数据:" + BitConverter.ToString(bytes));
  432. var boxUserSettings = FindAnyObjectByType<CustomUIView.BoxUserSettings>();
  433. //设备类型
  434. switch (bytes[1])
  435. {
  436. case 0x01:
  437. //Debug.Log("设备类型:HOUYI Pro");
  438. UserSettings.ins.selectDevicesName = "HOUYI Pro";
  439. UserSettings.ins.Save();
  440. boxUserSettings?.OnUpdateClickInfoByName();
  441. break;
  442. case 0x02:
  443. // Debug.Log("设备类型:ARTEMIS Pro");
  444. UserSettings.ins.selectDevicesName = "ARTEMIS Pro";
  445. UserSettings.ins.Save();
  446. boxUserSettings?.OnUpdateClickInfoByName();
  447. break;
  448. case 0x03:
  449. // Debug.Log("设备类型:Pistol 1");
  450. UserSettings.ins.selectDevicesName = "Pistol M9";
  451. UserSettings.ins.Save();
  452. boxUserSettings?.OnUpdateClickInfoByName();
  453. break;
  454. }
  455. // 系统类型
  456. //switch (bytes[2])
  457. //{
  458. // case 0x01:
  459. // Debug.Log("系统类型:移动手机");
  460. // break;
  461. // case 0x02:
  462. // Debug.Log("系统类型:PC电脑");
  463. // break;
  464. // case 0x03:
  465. // Debug.Log("系统类型:VR设备");
  466. // break;
  467. //}
  468. //记录接收到系统数据
  469. ShootCheck.ins.UpdateDeviceAndSysInfo(bytes);
  470. }
  471. return;
  472. }
  473. //if (InfraredDemo.running)
  474. //{
  475. // BluetoothAim.ins.WriteData("4"); //关闭九轴
  476. // return;
  477. //}
  478. if (!bRuning9Axis())
  479. {
  480. return;
  481. }
  482. m_axisHandler.Update(bytes);
  483. if (BowQuatDebug.ins) BowQuatDebug.ins.ShowModuleQuat(newRotation.eulerAngles);
  484. if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked) SB_EventSystem.ins.MoveSimulateMouse(newRotation);
  485. }
  486. public byte[] InsertByteAtBeginning(byte[] originalArray, byte newByte)
  487. {
  488. byte[] newArray = new byte[originalArray.Length + 1];
  489. newArray[0] = newByte;
  490. Array.Copy(originalArray, 0, newArray, 1, originalArray.Length);
  491. return newArray;
  492. }
  493. private bool m_magCompleted;
  494. public void CorrectMagCompleted(bool value) { m_magCompleted = value; }
  495. private bool m_ban9AxisCalculate = false;
  496. public void Ban9AxisCalculate(bool ban)
  497. {
  498. // m_ban9AxisCalculate = ban;
  499. // if (!ban)
  500. // {
  501. // SetMsOldDefault();
  502. // if (m_controlObj) m_controlObj.localRotation = newRotation;
  503. // }
  504. }
  505. public void SetMsOldDefault()
  506. {
  507. if (m_axisHandler.GetType() == typeof(Axis9NopackHandler))
  508. (m_axisHandler as Axis9NopackHandler).msOld = default;
  509. }
  510. public void DoIdentity()
  511. {
  512. //if (InfraredDemo.running) return;
  513. m_axisHandler.DoIdentity();
  514. if (!bRuning9Axis()) return;
  515. if (m_controlObj) m_controlObj.localRotation = newRotation;
  516. }
  517. public void NotifyAxisOnShot() { m_axisHandler.NotifyAxisOnShot(); }
  518. public void CalibrateGyr(bool calibration) { m_axisHandler.CalibrateGyr(calibration); }
  519. public void InitGyr(string record) { m_axisHandler.InitGyr(record); }
  520. public void InitMag(string record) { m_axisHandler.InitMag(record); }
  521. public void ResetGyr() { m_axisHandler.ResetGyr(); }
  522. public void ResetMag() { m_axisHandler.ResetMag(); }
  523. public void ApplyImpreciseMag() { m_axisHandler.ApplyImpreciseMag(); }
  524. public bool IsGyrCompleted() { return m_axisHandler.IsGyrCompleted(); }
  525. public bool IsMagCompleted() { return m_axisHandler.IsMagCompleted(); }
  526. public IEnumerator SaveGyr() { return m_axisHandler.SaveGyr(); }
  527. public IEnumerator SaveMag() { return m_axisHandler.SaveMag(); }
  528. public void ResumeCalibrateRecord(string record) { m_axisHandler.ResumeCalibrateRecord(record); }
  529. #region 获取一个连接的设备下,对应的 Archery 是运行9轴的代码处理位置信息判断
  530. public bool bRuning9Axis() {
  531. //连接的设备下,对应的 Archery 是运行9轴的代码处理位置信息判断
  532. //弓箭类型,但是不是HOUYI Pro 情况下。运行9轴代码
  533. bool bRuning = GlobalData.MyDeviceMode == DeviceMode.Archery && !BluetoothAim.ins.isMainConnectToInfraredDevice();
  534. return bRuning;
  535. }
  536. #endregion
  537. /// <summary>
  538. /// 操作准心开关事件
  539. /// </summary>
  540. private void CrossBtnEvent()
  541. {
  542. Debug.Log("CrossBtnEvent");
  543. //准心开关
  544. InvokeOnCrossBtnEvent();
  545. //b端不处理准心
  546. if (CommonConfig.StandaloneModeOrPlatformB) {
  547. InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
  548. if (infraredGuider)
  549. {
  550. infraredGuider.onClickDevice();
  551. }
  552. return;
  553. }
  554. if (GameAssistUI.ins)
  555. {
  556. InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
  557. if (infraredGuider == null)
  558. {
  559. //显示控制准心按钮
  560. Transform _button5 = GameAssistUI.ins.transform.Find("Button5");
  561. if (_button5.gameObject.activeSelf)
  562. {
  563. Button crossHairBtn = _button5.GetComponent<Button>();
  564. crossHairBtn.onClick.Invoke();
  565. }
  566. else
  567. {
  568. bool onlyShow = !CrossHair.ins.GetOnlyShow();
  569. CrossHair.ins.SetOnlyShow(onlyShow);
  570. //保存准心状态
  571. if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow);
  572. }
  573. }
  574. else {
  575. infraredGuider.onClickDevice();
  576. }
  577. //if (GameMgr.bShowDistance)
  578. //{
  579. // //显示控制准心按钮
  580. // Button crossHairBtn = GameAssistUI.ins.transform.Find("Button5").GetComponent<Button>();
  581. // crossHairBtn.onClick.Invoke();
  582. //}
  583. //else {
  584. // //校准
  585. // InfraredDemo._ins?.OnClick_SetAdjustPointsOffset();
  586. //}
  587. }
  588. else if (DuckHunter.GameUI.Instance)
  589. {
  590. //显示控制准心按钮
  591. Transform _btnCrosshair = DuckHunter.GameUI.Instance.transform.Find("BtnCrosshair");
  592. if (_btnCrosshair.gameObject.activeSelf)
  593. {
  594. Button crossHairBtn = _btnCrosshair.GetComponent<Button>();
  595. crossHairBtn.onClick.Invoke();
  596. }
  597. else {
  598. bool onlyShow = !DuckHunter.CrossHair.Instance.GetOnlyShow();
  599. DuckHunter.CrossHair.Instance.SetOnlyShow(onlyShow);
  600. //记录准心值
  601. if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow);
  602. }
  603. }
  604. else if (HyperspaceGame.UIManager._ins) {
  605. //打枪
  606. Transform _btnCrosshair = HyperspaceGame.UIManager._ins.transform.Find("BtnCrosshair");
  607. if (_btnCrosshair.gameObject.activeSelf)
  608. {
  609. Button crossHairBtn = _btnCrosshair.GetComponent<Button>();
  610. crossHairBtn.onClick.Invoke();
  611. }
  612. else {
  613. bool onlyShow = !HyperspaceGame.UIManager._ins.GetOnlyShow();
  614. HyperspaceGame.UIManager._ins.SetOnlyShow(onlyShow);
  615. //记录准心值
  616. if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow);
  617. }
  618. }
  619. else
  620. {
  621. if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("FruitMaster")){
  622. //水果
  623. GameObject _crosshairBtn = GameObject.Find("PermanentCanvas/CrossHair_Btn");
  624. if (_crosshairBtn.gameObject.activeSelf)
  625. {
  626. Button crossHairBtn = _crosshairBtn.GetComponent<Button>();
  627. crossHairBtn.onClick.Invoke();
  628. }
  629. else {
  630. bool onlyShow = !JCFruitMaster.ins.GetOnlyShow();
  631. JCFruitMaster.ins.SetOnlyShow(onlyShow);
  632. //记录准心值
  633. if (InfraredDemo._ins) InfraredDemo._ins.setCrosshairValue(onlyShow);
  634. }
  635. }
  636. }
  637. }
  638. }