SmartBowController.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. InfraredDemo.infraredCameraHelper.OnPositionUpdate += OnScreenPointUpdate;
  15. StartCoroutine(SetOutBoundChecker());
  16. }
  17. IEnumerator SetOutBoundChecker()
  18. {
  19. yield return null;
  20. CrossHairOutBoundChecker1 outBoundChecker = Instantiate(Resources.Load<GameObject>("Prefabs/CrossHairOutBoundChecker1")).GetComponent<CrossHairOutBoundChecker1>();
  21. outBoundChecker.FetchOutBoundIndex = () => GameMananger.GetInstance().outBoundIndex;
  22. }
  23. void OnDestroy()
  24. {
  25. if (Instance == this) Instance = null;
  26. InfraredDemo.infraredCameraHelper.OnPositionUpdate -= OnScreenPointUpdate;
  27. }
  28. public void OnRotationUpdate(Quaternion rotation)
  29. {
  30. if (SB_EventSystem.ins.simulateMouseIsAwaked) return;
  31. GameMananger.GetInstance()?.OnRotationUpdate(rotation);
  32. }
  33. public void OnScreenPointUpdate(Vector2 point, Vector2 cameraLocation)
  34. {
  35. var gameManager = GameMananger.GetInstance();
  36. if (SB_EventSystem.ins == null || gameManager == null)
  37. {
  38. return;
  39. }
  40. if (SB_EventSystem.ins.simulateMouseIsAwaked) return;
  41. GameMananger.GetInstance()?.OnScreenPointUpdate(point);
  42. }
  43. float _lastShootTime = 0;
  44. public void OnShooting(float speed)
  45. {
  46. if (Time.time == 0) return;
  47. if (Time.realtimeSinceStartup - _lastShootTime < 1) return;
  48. _lastShootTime = Time.realtimeSinceStartup;
  49. GameMananger.GetInstance().OnModuleShooting(speed);
  50. }
  51. public bool IsBluetoothModuleInited()
  52. {
  53. return BluetoothAim.ins && BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess;
  54. }
  55. }
  56. }