SmartBowController.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using LightGlue.Unity.Custom;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace WildAttack
  7. {
  8. public class SmartBowController : MonoBehaviour
  9. {
  10. public static SmartBowController Instance;
  11. void Start()
  12. {
  13. Instance = this;
  14. SimulateMouseController.ins?.RemoveOpenLocker("NotGame");
  15. StartCoroutine(SetOutBoundChecker());
  16. }
  17. public void onInit() {
  18. if (GameMananger.GetInstance().CurrentGameType == GameTypeEnum.SinglePlayer)
  19. {
  20. if (CommonConfig.UseRomaSdk)
  21. {
  22. LightGlueGameManager._ins.OnPositionUpdate += OnScreenPointUpdate;
  23. return;
  24. }
  25. if (AimHandler.ins.bRuning9Axis())
  26. {
  27. CameraToLook.ins.onParseRotation += OnRotationUpdate;
  28. }
  29. else
  30. {
  31. InfraredDemo.infraredCameraHelper.OnPositionUpdate += OnScreenPointUpdate;
  32. }
  33. }
  34. else
  35. InfraredDemo.infraredCameraHelper.OnPositionUpdate2 += OnScreenPointsUpdate;
  36. }
  37. IEnumerator SetOutBoundChecker()
  38. {
  39. yield return null;
  40. CrossHairOutBoundChecker1 outBoundChecker = Instantiate(Resources.Load<GameObject>("Prefabs/CrossHairOutBoundChecker1")).GetComponent<CrossHairOutBoundChecker1>();
  41. outBoundChecker.FetchOutBoundIndex = () => GameMananger.GetInstance().outBoundIndex;
  42. }
  43. void OnDestroy()
  44. {
  45. if (Instance == this) Instance = null;
  46. if (GameMananger.GetInstance().CurrentGameType == GameTypeEnum.SinglePlayer)
  47. {
  48. if (CommonConfig.UseRomaSdk) {
  49. LightGlueGameManager._ins.OnPositionUpdate -= OnScreenPointUpdate;
  50. return;
  51. }
  52. if (AimHandler.ins.bRuning9Axis())
  53. {
  54. CameraToLook.ins.onParseRotation -= OnRotationUpdate;
  55. }
  56. else
  57. {
  58. InfraredDemo.infraredCameraHelper.OnPositionUpdate -= OnScreenPointUpdate;
  59. }
  60. }
  61. else
  62. InfraredDemo.infraredCameraHelper.OnPositionUpdate2 -= OnScreenPointsUpdate;
  63. }
  64. public void OnRotationUpdate(Quaternion rotation)
  65. {
  66. if (SB_EventSystem.ins.simulateMouseIsAwaked) return;
  67. GameMananger.GetInstance().OnRotationUpdate(rotation);
  68. }
  69. public void OnScreenPointUpdate(Vector2 point, Vector2 cameraLocation)
  70. {
  71. if (SB_EventSystem.ins.simulateMouseIsAwaked) return;
  72. GameMananger.GetInstance().OnScreenPointUpdate(point);
  73. }
  74. public void OnScreenPointsUpdate(Vector2[] points, Vector2[] cameraLocations)
  75. {
  76. if (points == null || cameraLocations == null) return;
  77. if (SB_EventSystem.ins.simulateMouseIsAwaked) return;
  78. for (int i = 0; i < points.Length; i++)
  79. {
  80. Vector2 point = points[i];
  81. PlayerTypeEnum playerType = (i == 0) ? PlayerTypeEnum.First : PlayerTypeEnum.Second;
  82. // 传给 GameManager 逻辑(准星控制)
  83. GameMananger.GetInstance()?.OnScreenPointUpdate(point, playerType);
  84. }
  85. }
  86. float _lastShootTime = 0;
  87. public void OnShooting(float speed)
  88. {
  89. if (Time.time == 0) return;
  90. if (Time.realtimeSinceStartup - _lastShootTime < 1) return;
  91. _lastShootTime = Time.realtimeSinceStartup;
  92. GameMananger.GetInstance().OnModuleShooting(speed);
  93. }
  94. float _lastShootTime_2P = 0;
  95. public void OnShooting2P(float speed)
  96. {
  97. if (Time.time == 0) return;
  98. if (Time.realtimeSinceStartup - _lastShootTime_2P < 1) return;
  99. _lastShootTime_2P = Time.realtimeSinceStartup;
  100. GameMananger.GetInstance().OnModuleShooting(speed,PlayerTypeEnum.Second);
  101. }
  102. public bool IsBluetoothModuleInited()
  103. {
  104. return BluetoothAim.ins && BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess;
  105. }
  106. }
  107. }