SmartBowController.cs 2.2 KB

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