BowCamera.cs 3.4 KB

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