SmartBowController.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. var gameManager = GameMananger.GetInstance();
  59. if (SB_EventSystem.ins == null || gameManager == null)
  60. {
  61. return;
  62. }
  63. if (SB_EventSystem.ins.simulateMouseIsAwaked) return;
  64. GameMananger.GetInstance().OnScreenPointUpdate(point);
  65. }
  66. float _lastShootTime = 0;
  67. public void OnShooting(float speed)
  68. {
  69. if (Time.time == 0) return;
  70. if (Time.realtimeSinceStartup - _lastShootTime < 1) return;
  71. _lastShootTime = Time.realtimeSinceStartup;
  72. GameMananger.GetInstance().OnModuleShooting(speed);
  73. }
  74. public bool IsBluetoothModuleInited()
  75. {
  76. return BluetoothAim.ins && BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess;
  77. }
  78. }
  79. }