BowCamera.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. public class BowCamera : MonoBehaviour
  6. {
  7. private Vector3 eualrAngles = new Vector3();
  8. private float mouseSensitivity = 2f;
  9. public Camera cameraComp;
  10. public bool debugInEditor = false;
  11. void Start() {
  12. if (this.debugInEditor) {
  13. // Cursor.lockState = CursorLockMode.Locked;
  14. }
  15. }
  16. void Update()
  17. {
  18. if (GameMgr.ins.gameOver) {
  19. return;
  20. }
  21. if (debugInEditor) {
  22. this.eualrAngles.x = Mathf.Clamp(this.eualrAngles.x - this.mouseSensitivity * Input.GetAxis("Mouse Y"), -36, 36);
  23. this.eualrAngles.y = Mathf.Clamp(this.eualrAngles.y + this.mouseSensitivity * Input.GetAxis("Mouse X"), -20, 20);
  24. this.transform.eulerAngles = this.eualrAngles;
  25. // if (EventSystem.current.IsPointerOverGameObject())
  26. // {
  27. // return;
  28. // }
  29. // if (Input.GetMouseButtonDown(0)) {
  30. // ArmBow.ins.mouseDown();
  31. // }
  32. // else if (Input.GetMouseButtonUp(0)) {
  33. // ArmBow.ins.mouseUp();
  34. // }
  35. } else {
  36. if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Moved)
  37. {
  38. if (!EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId))
  39. {
  40. this.eualrAngles.x = Mathf.Clamp(this.eualrAngles.x - Input.touches[0].deltaPosition.y * Time.deltaTime * 5, -36, 36);
  41. this.eualrAngles.y = Mathf.Clamp(this.eualrAngles.y + Input.touches[0].deltaPosition.x * Time.deltaTime * 5, -25, 25);
  42. this.transform.eulerAngles = this.eualrAngles;
  43. }
  44. }
  45. // Transform transform = GameObject.Find("CameraRoot/Rotate/Sphere").transform;
  46. // this.transform.LookAt(transform);
  47. // if (Input.touches.Length > 0)
  48. // {
  49. // foreach (Touch touch in Input.touches)
  50. // {
  51. // if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) return;
  52. // }
  53. // ArmBow.ins.mouseDown();
  54. // }
  55. // if (Input.touches.Length == 0)
  56. // {
  57. // ArmBow.ins.mouseUp();
  58. // }
  59. }
  60. }
  61. public void setFieldOfView(float value, bool isPlus) {
  62. cameraComp.fieldOfView = isPlus ? cameraComp.fieldOfView + value : value;
  63. }
  64. public void resumeFieldOfView() {
  65. cameraComp.fieldOfView = 60;
  66. }
  67. public void updateFollowPullBow() {
  68. if (cameraComp.fieldOfView > 40) {
  69. cameraComp.fieldOfView -= 20 * Time.deltaTime;
  70. } else {
  71. cameraComp.fieldOfView = 40;
  72. }
  73. }
  74. public void updateGiveUpPullBow() {
  75. if (cameraComp.fieldOfView < 60) {
  76. cameraComp.fieldOfView += 20 * Time.deltaTime;
  77. } else {
  78. cameraComp.fieldOfView = 60;
  79. }
  80. }
  81. }