BowCamera.cs 3.2 KB

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