BowCamera.cs 2.9 KB

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