BowCamera.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. this.transform.LookAt(GameObject.Find("CameraToLook/Point").transform);
  37. // if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Moved)
  38. // {
  39. // if (!EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId))
  40. // {
  41. // this.eualrAngles.x = Mathf.Clamp(this.eualrAngles.x - Input.touches[0].deltaPosition.y * Time.deltaTime * 5, -36, 36);
  42. // this.eualrAngles.y = Mathf.Clamp(this.eualrAngles.y + Input.touches[0].deltaPosition.x * Time.deltaTime * 5, -25, 25);
  43. // this.transform.eulerAngles = this.eualrAngles;
  44. // }
  45. // }
  46. // if (Input.touches.Length > 0)
  47. // {
  48. // foreach (Touch touch in Input.touches)
  49. // {
  50. // if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) return;
  51. // }
  52. // ArmBow.ins.mouseDown();
  53. // }
  54. // if (Input.touches.Length == 0)
  55. // {
  56. // ArmBow.ins.mouseUp();
  57. // }
  58. }
  59. }
  60. public void setFieldOfView(float value, bool isPlus) {
  61. cameraComp.fieldOfView = isPlus ? cameraComp.fieldOfView + value : value;
  62. }
  63. public void resumeFieldOfView() {
  64. cameraComp.fieldOfView = 60;
  65. }
  66. public void updateFollowPullBow() {
  67. if (cameraComp.fieldOfView > 40) {
  68. cameraComp.fieldOfView -= 20 * Time.deltaTime;
  69. } else {
  70. cameraComp.fieldOfView = 40;
  71. }
  72. }
  73. public void updateGiveUpPullBow() {
  74. if (cameraComp.fieldOfView < 60) {
  75. cameraComp.fieldOfView += 20 * Time.deltaTime;
  76. } else {
  77. cameraComp.fieldOfView = 60;
  78. }
  79. }
  80. }