AimHandler.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine.UI;
  6. using UnityEngine.SceneManagement;
  7. using WildAttack;
  8. using DuckHunter;
  9. public enum AimDeviceType {
  10. NONE = -1,
  11. HOUYI = 0,
  12. HOUYI2 = 1,
  13. ARTEMIS = 2,
  14. HOUYIPRO = 3,
  15. //枪械类
  16. Gun = 4,
  17. ARTEMISPRO = 5,
  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. InvokeOnCrossBtnEvent();
  333. }
  334. }
  335. else
  336. {
  337. if (aimDeviceInfo.type == (int)AimDeviceType.NONE ||
  338. aimDeviceInfo.type == (int)AimDeviceType.HOUYI ||
  339. aimDeviceInfo.type == (int)AimDeviceType.HOUYI2 ||
  340. aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS)
  341. {
  342. AutoResetView.DoIdentity();
  343. }
  344. else
  345. {
  346. //准心开关
  347. CrossBtnEvent();
  348. }
  349. }
  350. }
  351. }
  352. else if (bytes[0] == 0x66 && bytes[1] == 0x32)
  353. {
  354. //红外部分
  355. if (GlobalData.MyDeviceMode == DeviceMode.Gun || BluetoothAim.ins && BluetoothAim.ins.isMainConnectToInfraredDevice())
  356. {
  357. InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
  358. //‘校准'功能的调用,使用原来调出光标的功能键;即在HOUYI Pro使用长按视角归位键;在ARTEMIS Pro使用快速双击按键
  359. if (infraredGuider == null)
  360. {
  361. AutoResetView.DoIdentity();
  362. }
  363. else {
  364. //先判断是否处于校准步骤
  365. infraredGuider.onLongClickDevice();
  366. }
  367. }
  368. else if (SB_EventSystem.ins)
  369. {
  370. // if (SB_EventSystem.ins && !CommonConfig.SpecialVersion1) {
  371. //唤起/隐藏虚拟鼠标
  372. SB_EventSystem.ins.AwakenSimulateMouse();
  373. }
  374. }
  375. else if (bytes[1] == 10)
  376. {
  377. //显示电量
  378. DeviceBatteryView.ins.RenderBattery(1, bytes[0]);
  379. //DeviceView.ins.RenderBattery(1, bytes[0]);
  380. }
  381. }
  382. else if (bytes[0] == 0x5b)
  383. {
  384. if (GlobalData.MyDeviceMode == DeviceMode.Gun) {
  385. if (Time.realtimeSinceStartup - _lastShootTime < 1) return;
  386. _lastShootTime = Time.realtimeSinceStartup;
  387. //流程触发红外描点
  388. InfraredScreenPositioningView infraredScreenPositioningView = FindAnyObjectByType<InfraredScreenPositioningView>();
  389. if (infraredScreenPositioningView)
  390. {
  391. InvokeOnCrossBtnEvent();
  392. }
  393. }
  394. //红外射击检测
  395. ShootCheck.ins.ShootByInfrared(bytes);
  396. }
  397. else if (bytes[0] == 0x5C)
  398. {
  399. //00 弹夹分离,01 上弹夹
  400. ShootCheck.ins.UpdateTheMagazine(bytes);
  401. }
  402. else if (bytes[0] == 0x5E)
  403. {
  404. Debug.Log("接收到系统数据:" + BitConverter.ToString(bytes));
  405. //设备类型
  406. switch (bytes[1])
  407. {
  408. case 0x01:
  409. Debug.Log("设备类型:HOUYI Pro");
  410. break;
  411. case 0x02:
  412. Debug.Log("设备类型:ARTEMIS Pro");
  413. break;
  414. case 0x03:
  415. Debug.Log("设备类型:Pistol 1");
  416. break;
  417. }
  418. // 系统类型
  419. switch (bytes[2])
  420. {
  421. case 0x01:
  422. Debug.Log("系统类型:移动手机");
  423. break;
  424. case 0x02:
  425. Debug.Log("系统类型:PC电脑");
  426. break;
  427. case 0x03:
  428. Debug.Log("系统类型:VR设备");
  429. break;
  430. }
  431. }
  432. return;
  433. }
  434. //if (InfraredDemo.running)
  435. //{
  436. // BluetoothAim.ins.WriteData("4"); //关闭九轴
  437. // return;
  438. //}
  439. if (!bRuning9Axis())
  440. {
  441. return;
  442. }
  443. m_axisHandler.Update(bytes);
  444. if (BowQuatDebug.ins) BowQuatDebug.ins.ShowModuleQuat(newRotation.eulerAngles);
  445. if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked) SB_EventSystem.ins.MoveSimulateMouse(newRotation);
  446. }
  447. public byte[] InsertByteAtBeginning(byte[] originalArray, byte newByte)
  448. {
  449. byte[] newArray = new byte[originalArray.Length + 1];
  450. newArray[0] = newByte;
  451. Array.Copy(originalArray, 0, newArray, 1, originalArray.Length);
  452. return newArray;
  453. }
  454. private bool m_magCompleted;
  455. public void CorrectMagCompleted(bool value) { m_magCompleted = value; }
  456. private bool m_ban9AxisCalculate = false;
  457. public void Ban9AxisCalculate(bool ban)
  458. {
  459. // m_ban9AxisCalculate = ban;
  460. // if (!ban)
  461. // {
  462. // SetMsOldDefault();
  463. // if (m_controlObj) m_controlObj.localRotation = newRotation;
  464. // }
  465. }
  466. public void SetMsOldDefault()
  467. {
  468. if (m_axisHandler.GetType() == typeof(Axis9NopackHandler))
  469. (m_axisHandler as Axis9NopackHandler).msOld = default;
  470. }
  471. public void DoIdentity()
  472. {
  473. //if (InfraredDemo.running) return;
  474. m_axisHandler.DoIdentity();
  475. if (!bRuning9Axis()) return;
  476. if (m_controlObj) m_controlObj.localRotation = newRotation;
  477. }
  478. public void NotifyAxisOnShot() { m_axisHandler.NotifyAxisOnShot(); }
  479. public void CalibrateGyr(bool calibration) { m_axisHandler.CalibrateGyr(calibration); }
  480. public void InitGyr(string record) { m_axisHandler.InitGyr(record); }
  481. public void InitMag(string record) { m_axisHandler.InitMag(record); }
  482. public void ResetGyr() { m_axisHandler.ResetGyr(); }
  483. public void ResetMag() { m_axisHandler.ResetMag(); }
  484. public void ApplyImpreciseMag() { m_axisHandler.ApplyImpreciseMag(); }
  485. public bool IsGyrCompleted() { return m_axisHandler.IsGyrCompleted(); }
  486. public bool IsMagCompleted() { return m_axisHandler.IsMagCompleted(); }
  487. public IEnumerator SaveGyr() { return m_axisHandler.SaveGyr(); }
  488. public IEnumerator SaveMag() { return m_axisHandler.SaveMag(); }
  489. public void ResumeCalibrateRecord(string record) { m_axisHandler.ResumeCalibrateRecord(record); }
  490. #region 获取一个连接的设备下,对应的 Archery 是运行9轴的代码处理位置信息判断
  491. public bool bRuning9Axis() {
  492. //连接的设备下,对应的 Archery 是运行9轴的代码处理位置信息判断
  493. //弓箭类型,但是不是HOUYI Pro 情况下。运行9轴代码
  494. bool bRuning = GlobalData.MyDeviceMode == DeviceMode.Archery && !BluetoothAim.ins.isMainConnectToInfraredDevice();
  495. return bRuning;
  496. }
  497. #endregion
  498. /// <summary>
  499. /// 操作准心开关事件
  500. /// </summary>
  501. private void CrossBtnEvent()
  502. {
  503. Debug.Log("CrossBtnEvent");
  504. //准心开关
  505. InvokeOnCrossBtnEvent();
  506. if (GameAssistUI.ins)
  507. {
  508. InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
  509. if (infraredGuider == null)
  510. {
  511. //显示控制准心按钮
  512. Button crossHairBtn = GameAssistUI.ins.transform.Find("Button5").GetComponent<Button>();
  513. crossHairBtn.onClick.Invoke();
  514. }
  515. else {
  516. infraredGuider.onClickDevice();
  517. }
  518. //if (GameMgr.bShowDistance)
  519. //{
  520. // //显示控制准心按钮
  521. // Button crossHairBtn = GameAssistUI.ins.transform.Find("Button5").GetComponent<Button>();
  522. // crossHairBtn.onClick.Invoke();
  523. //}
  524. //else {
  525. // //校准
  526. // InfraredDemo._ins?.OnClick_SetAdjustPointsOffset();
  527. //}
  528. }
  529. else if (DuckHunter.GameUI.Instance)
  530. {
  531. //显示控制准心按钮
  532. Button crossHairBtn = DuckHunter.GameUI.Instance.transform.Find("BtnCrosshair").GetComponent<Button>();
  533. crossHairBtn.onClick.Invoke();
  534. }
  535. else if (HyperspaceGame.UIManager._ins) {
  536. //打枪
  537. Button crossHairBtn = HyperspaceGame.UIManager._ins.transform.Find("BtnCrosshair").GetComponent<Button>();
  538. crossHairBtn.onClick.Invoke();
  539. }
  540. else
  541. {
  542. if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.StartsWith("FruitMaster")){
  543. //水果
  544. Button crossHairBtn = GameObject.Find("PermanentCanvas/CrossHair_Btn").GetComponent<Button>();
  545. crossHairBtn.onClick.Invoke();
  546. }
  547. }
  548. }
  549. /// <summary>
  550. /// 退出进入游戏事件
  551. /// </summary>
  552. public void ExitIntoEvent()
  553. {
  554. string sceneName = SceneManager.GetActiveScene().name;
  555. if (sceneName == "Home")
  556. {
  557. //进入游戏
  558. //EnterTheGame();
  559. return;
  560. }
  561. switch (sceneName)
  562. {
  563. //退出游戏
  564. case "Game":
  565. GameAssistUI.ins.onBtnBack();
  566. break;
  567. case "GameChallenge":
  568. GameAssistUI.ins.onBtnBack();
  569. break;
  570. case "GameDouble":
  571. GameAssistUI.ins.onBtnBack();
  572. break;
  573. case "Hyperspace03":
  574. HyperspaceGame.UIManager._ins.OnShutDown();
  575. break;
  576. case "Hyperspace02":
  577. HyperspaceGame.UIManager._ins.OnShutDown();
  578. break;
  579. case "Hyperspace01":
  580. HyperspaceGame.UIManager._ins.OnShutDown();
  581. break;
  582. case "FruitMaster":
  583. GamingManager.gaming.onShowResultView();
  584. break;
  585. case "WildAttack":
  586. UIManager.GetInstance().onShowResultView();
  587. break;
  588. case "DuckHunter":
  589. GameUI.Instance.onShowResultView();
  590. break;
  591. }
  592. }
  593. public int gameNum = 0;
  594. void EnterTheGame()
  595. {
  596. if (gameNum == 0)
  597. {
  598. HomeView_ChallengeOption.homeView_.OnSelectionChanged(HomeView_ChallengeOption.homeView_.gameIndex, true);
  599. gameNum += 1;
  600. }
  601. if(gameNum == 1)
  602. {
  603. Debug.Log("进入单人游戏模式");
  604. ModeSelectView.ins.OnChangeButton(0);
  605. gameNum = 0;
  606. }
  607. }
  608. }