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