SmartBowController.cs 2.7 KB

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