SmartBowController.cs 3.8 KB

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