SmartBowController.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. InfraredDemo.infraredCameraHelper.OnPositionUpdate += OnScreenPointUpdate;
  19. else
  20. InfraredDemo.infraredCameraHelper.OnPositionUpdate2 += OnScreenPointsUpdate;
  21. }
  22. IEnumerator SetOutBoundChecker()
  23. {
  24. yield return null;
  25. CrossHairOutBoundChecker1 outBoundChecker = Instantiate(Resources.Load<GameObject>("Prefabs/CrossHairOutBoundChecker1")).GetComponent<CrossHairOutBoundChecker1>();
  26. outBoundChecker.FetchOutBoundIndex = () => GameMananger.GetInstance().outBoundIndex;
  27. }
  28. void OnDestroy()
  29. {
  30. if (Instance == this) Instance = null;
  31. if (GameMananger.GetInstance().CurrentGameType == GameTypeEnum.SinglePlayer)
  32. InfraredDemo.infraredCameraHelper.OnPositionUpdate -= OnScreenPointUpdate;
  33. else
  34. InfraredDemo.infraredCameraHelper.OnPositionUpdate2 -= OnScreenPointsUpdate;
  35. }
  36. public void OnRotationUpdate(Quaternion rotation)
  37. {
  38. if (SB_EventSystem.ins.simulateMouseIsAwaked) return;
  39. GameMananger.GetInstance()?.OnRotationUpdate(rotation);
  40. }
  41. public void OnScreenPointUpdate(Vector2 point, Vector2 cameraLocation)
  42. {
  43. if (SB_EventSystem.ins.simulateMouseIsAwaked) return;
  44. GameMananger.GetInstance()?.OnScreenPointUpdate(point);
  45. }
  46. public void OnScreenPointsUpdate(Vector2[] points, Vector2[] cameraLocations)
  47. {
  48. if (points == null || cameraLocations == null) return;
  49. if (SB_EventSystem.ins.simulateMouseIsAwaked) return;
  50. for (int i = 0; i < points.Length; i++)
  51. {
  52. Vector2 point = points[i];
  53. PlayerTypeEnum playerType = (i == 0) ? PlayerTypeEnum.First : PlayerTypeEnum.Second;
  54. // 传给 GameManager 逻辑(准星控制)
  55. GameMananger.GetInstance()?.OnScreenPointUpdate(point, playerType);
  56. }
  57. }
  58. float _lastShootTime = 0;
  59. public void OnShooting(float speed)
  60. {
  61. if (Time.time == 0) return;
  62. if (Time.realtimeSinceStartup - _lastShootTime < 1) return;
  63. _lastShootTime = Time.realtimeSinceStartup;
  64. GameMananger.GetInstance().OnModuleShooting(speed);
  65. }
  66. float _lastShootTime_2P = 0;
  67. public void OnShooting2P(float speed)
  68. {
  69. if (Time.time == 0) return;
  70. if (Time.realtimeSinceStartup - _lastShootTime_2P < 1) return;
  71. _lastShootTime_2P = Time.realtimeSinceStartup;
  72. GameMananger.GetInstance().OnModuleShooting(speed,PlayerTypeEnum.Second);
  73. }
  74. public bool IsBluetoothModuleInited()
  75. {
  76. return BluetoothAim.ins && BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess;
  77. }
  78. }
  79. }