Main.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using Newtonsoft.Json;
  2. using ProjectBase.UI;
  3. using ShotSimulator.Screen;
  4. using ShotSimulator.Train;
  5. using ShotSimulator.UI;
  6. using ShotSimulator.User;
  7. using SmartBowSDK;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using UnityEngine;
  11. using UnityEngine.SceneManagement;
  12. namespace ShotSimulator
  13. {
  14. public class Main : MonoSingleton<Main>
  15. {
  16. private void Awake()
  17. {
  18. //Application.targetFrameRate = 60;
  19. SoundManager.GetInstance().InitManager();
  20. ScreenEffectManager.GetInstance().InitManager();
  21. VirtualMouse.GetInstance().InitManager();
  22. UIManager.GetInstance().InitManager();
  23. UserManager.GetInstance().InitManager();
  24. InitExternalCallback();
  25. }
  26. private void Start()
  27. {
  28. SimulateMouseController.ins?.RemoveOpenLocker("NotGame");
  29. UIManager.GetInstance().ShowUIView("CursorUIView", CursorType.UICursor);
  30. UIManager.GetInstance().ShowUIView("TrainTaskInfoUIView");
  31. //UIManager.GetInstance().ShowUIView("MainScreenUIView");
  32. }
  33. private void Update()
  34. {
  35. //if (Input.GetKeyDown(KeyCode.U))
  36. //{
  37. // RankingFilter filter = new RankingFilter()
  38. // {
  39. // trainTaskType = TrainTaskType.MemoryShot ,
  40. // difficultyType = DifficultyType.Advance ,
  41. // modeType = ModeType.Tactical,
  42. // firearmDeviceType = FirearmDeviceType.M17
  43. // };
  44. // UserManager.GetInstance().UploadCustomLeaderboard(filter, 800, (result) =>
  45. // {
  46. // List<RankingData> datas = JsonConvert.DeserializeObject<List<RankingData>>(JsonConvert.SerializeObject(result.data, Formatting.Indented));
  47. // foreach (var item in datas)
  48. // {
  49. // Debug.Log($"Rank: {item.rank}, Name: {item.userName}, Score: {item.score}, Avatar: {item.avatarUrl}, IsSelf: {item.isSelf}");
  50. // }
  51. // });
  52. //}
  53. }
  54. private void OnDestroy()
  55. {
  56. ResetExternalCallback();
  57. }
  58. private void InitExternalCallback()
  59. {
  60. if (ShootCheck.ins) {
  61. ShootCheck.ins.OnGameShoot += MainShoot;
  62. }
  63. if (BluetoothAim.ins) {
  64. BluetoothAim.ins.OnBleDeviceState += TrainTaskLoader.GetInstance().ChangedMagazineStatus;
  65. BluetoothAim.ins.OnDeviceAndSystemInfoEvent += OnDeviceAndSystemInfoEvent;
  66. //获取一次响应的信息
  67. BluetoothAim.ins.GetDeviceAndSystemInfoEvent();
  68. }
  69. // UserManager.GetInstance().Login(LoginCallBack);
  70. }
  71. float _lastShootTime = 0;
  72. /// <summary>
  73. /// 添加一个设计间隔,防止多次触发
  74. /// </summary>
  75. /// <param name="speed"></param>
  76. private void MainShoot(float speed) {
  77. if (CurrentFirearmDevice == FirearmDeviceType.M416)
  78. {
  79. //Rifle M416在训练游戏(新)中,要响应连发,APP正常响应蓝牙发过来的射击命令
  80. VirtualMouse.GetInstance().OnShooting(speed);
  81. TrainTaskLoader.GetInstance().Shoot(speed);
  82. }
  83. else {
  84. //Pisto1M17在新游戏中保持和M9一样的功能
  85. //枪情况下间隔时间0.2,弓箭按0.5
  86. float interval = GlobalData.MyDeviceMode == DeviceMode.Gun ? 0.2f : 0.5f;
  87. //加个间隔
  88. if (Time.realtimeSinceStartup - _lastShootTime < interval) return;
  89. _lastShootTime = Time.realtimeSinceStartup;
  90. VirtualMouse.GetInstance().OnShooting(speed);
  91. TrainTaskLoader.GetInstance().Shoot(speed);
  92. }
  93. }
  94. private void LoginCallBack(LoginResult result)
  95. {
  96. }
  97. private void ResetExternalCallback()
  98. {
  99. if (ShootCheck.ins)
  100. {
  101. ShootCheck.ins.OnGameShoot -= MainShoot;
  102. }
  103. if (BluetoothAim.ins)
  104. {
  105. BluetoothAim.ins.OnBleDeviceState -= TrainTaskLoader.GetInstance().ChangedMagazineStatus;
  106. BluetoothAim.ins.OnDeviceAndSystemInfoEvent -= OnDeviceAndSystemInfoEvent;
  107. }
  108. }
  109. public void ResetAim()
  110. {
  111. InfraredDemo._ins.SetAdjustPointsOffset(PlayerType.FirstPlayer);
  112. }
  113. #region 接入训练游戏时候添加
  114. public FirearmDeviceType CurrentFirearmDevice;
  115. public void OnDeviceAndSystemInfoEvent(ConnectPlatform connectPlatform, BluetoothDeviceType bleDeviceType)
  116. {
  117. Debug.Log("[Main]OnDeviceAndSystemInfoEvent:" + connectPlatform + ",bleDeviceType:" + bleDeviceType);
  118. switch (bleDeviceType)
  119. {
  120. case BluetoothDeviceType.NONE:
  121. break;
  122. case BluetoothDeviceType.HOUYIPro:
  123. break;
  124. case BluetoothDeviceType.ARTEMISPro:
  125. break;
  126. case BluetoothDeviceType.Pistol1:
  127. case BluetoothDeviceType.PistolM9:
  128. CurrentFirearmDevice = FirearmDeviceType.M9;
  129. break;
  130. case BluetoothDeviceType.APOLLO:
  131. break;
  132. case BluetoothDeviceType.PistolM17:
  133. CurrentFirearmDevice = FirearmDeviceType.M17;
  134. break;
  135. case BluetoothDeviceType.RifleM416:
  136. CurrentFirearmDevice = FirearmDeviceType.M416;
  137. break;
  138. default:
  139. break;
  140. }
  141. }
  142. #endregion
  143. }
  144. }