BowCamera.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. void Update()
  15. {
  16. if (cameraComp && !banCameraFieldOfView) {
  17. cameraComp.fieldOfView = cameraFieldOfView;
  18. }
  19. if (GameMgr.ins.gameOver || banRotate) {
  20. return;
  21. }
  22. if (GameMgr.debugInEditor) {
  23. this.eualrAngles.x = Mathf.Clamp(this.eualrAngles.x - this.mouseSensitivity * Input.GetAxis("Mouse Y"), -36, 36);
  24. this.eualrAngles.y = Mathf.Clamp(this.eualrAngles.y + this.mouseSensitivity * Input.GetAxis("Mouse X"), -20, 20);
  25. this.transform.eulerAngles = this.eualrAngles;
  26. if (EventSystem.current.IsPointerOverGameObject())
  27. {
  28. return;
  29. }
  30. if (Input.GetMouseButtonDown(0)) {
  31. ArmBow.ins.mouseDown();
  32. }
  33. else if (Input.GetMouseButtonUp(0)) {
  34. ArmBow.ins.mouseUp();
  35. }
  36. } else {
  37. this.transform.LookAt(GameObject.Find("CameraToLook/Point").transform);
  38. // if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Moved)
  39. // {
  40. // if (!EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId))
  41. // {
  42. // this.eualrAngles.x = Mathf.Clamp(this.eualrAngles.x - Input.touches[0].deltaPosition.y * Time.deltaTime * 5, -36, 36);
  43. // this.eualrAngles.y = Mathf.Clamp(this.eualrAngles.y + Input.touches[0].deltaPosition.x * Time.deltaTime * 5, -25, 25);
  44. // this.transform.eulerAngles = this.eualrAngles;
  45. // }
  46. // }
  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. float cameraFieldOfView = 60;
  62. public void SetCameraFieldOfView(float value)
  63. {
  64. cameraComp.fieldOfView = value;
  65. }
  66. public void setFieldOfView(float value, bool isPlus) {
  67. cameraFieldOfView = isPlus ? cameraFieldOfView + value : value;
  68. }
  69. public void updateFollowPullBow() {
  70. if (cameraFieldOfView > 40) {
  71. cameraFieldOfView -= 20 * Time.deltaTime;
  72. } else {
  73. cameraFieldOfView = 40;
  74. }
  75. }
  76. public Action onViewRecovery = null;
  77. public void updateGiveUpPullBow() {
  78. if (cameraFieldOfView < 60) {
  79. cameraFieldOfView += 20 * Time.deltaTime;
  80. } else {
  81. cameraFieldOfView = 60;
  82. if (onViewRecovery != null) {
  83. onViewRecovery();
  84. onViewRecovery = null;
  85. }
  86. }
  87. }
  88. }