|
|
|
|
@ -5,11 +5,22 @@ using UnityEngine.Serialization;
|
|
|
|
|
public class CameraController : MonoBehaviour {
|
|
|
|
|
private const float minFollowYOffset = 2f;
|
|
|
|
|
private const float maxFollowYOffset = 12f;
|
|
|
|
|
[FormerlySerializedAs("MoveSpeed")] [SerializeField] private float moveSpeed = 10f;
|
|
|
|
|
[FormerlySerializedAs("RotationSpeed")] [SerializeField] private float rotationSpeed = 100f;
|
|
|
|
|
[FormerlySerializedAs("ZoomAmount")] [SerializeField] private float zoomAmount = 1f;
|
|
|
|
|
[FormerlySerializedAs("ZoomSpeed")] [SerializeField] private float zoomSpeed = 5f;
|
|
|
|
|
[FormerlySerializedAs("CinemachineVirtualCamera")] [SerializeField] private CinemachineVirtualCamera cinemachineVirtualCamera;
|
|
|
|
|
|
|
|
|
|
[FormerlySerializedAs("MoveSpeed")] [SerializeField]
|
|
|
|
|
private float moveSpeed = 10f;
|
|
|
|
|
|
|
|
|
|
[FormerlySerializedAs("RotationSpeed")] [SerializeField]
|
|
|
|
|
private float rotationSpeed = 100f;
|
|
|
|
|
|
|
|
|
|
[FormerlySerializedAs("zoomAmount")] [FormerlySerializedAs("ZoomAmount")] [SerializeField]
|
|
|
|
|
private float zoomIncreaseAmount = 1f;
|
|
|
|
|
|
|
|
|
|
[FormerlySerializedAs("ZoomSpeed")] [SerializeField]
|
|
|
|
|
private float zoomSpeed = 5f;
|
|
|
|
|
|
|
|
|
|
[FormerlySerializedAs("CinemachineVirtualCamera")] [SerializeField]
|
|
|
|
|
private CinemachineVirtualCamera cinemachineVirtualCamera;
|
|
|
|
|
|
|
|
|
|
private CinemachineTransposer cinemachineTransposer;
|
|
|
|
|
private Vector3 targetFollowOffset;
|
|
|
|
|
|
|
|
|
|
@ -24,31 +35,17 @@ public class CameraController : MonoBehaviour {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleMovement() {
|
|
|
|
|
Vector3 inputMoveDir = new();
|
|
|
|
|
if (Input.GetKey(KeyCode.W)) inputMoveDir.z = +1f;
|
|
|
|
|
if (Input.GetKey(KeyCode.S)) inputMoveDir.z = -1f;
|
|
|
|
|
if (Input.GetKey(KeyCode.A)) inputMoveDir.x = -1f;
|
|
|
|
|
if (Input.GetKey(KeyCode.D)) inputMoveDir.x = +1f;
|
|
|
|
|
transform.position += Time.deltaTime * moveSpeed * (transform.forward * inputMoveDir.z + transform.right * inputMoveDir.x);
|
|
|
|
|
Vector2 inputMoveDir = InputManager.Instance.GetCameraMoveVector();
|
|
|
|
|
transform.position += Time.deltaTime * moveSpeed * (transform.forward * inputMoveDir.y + transform.right * inputMoveDir.x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleRotation() {
|
|
|
|
|
Vector3 rotationVector = new();
|
|
|
|
|
if (Input.GetKey(KeyCode.Q)) rotationVector.y = +1f;
|
|
|
|
|
if (Input.GetKey(KeyCode.E)) rotationVector.y = -1f;
|
|
|
|
|
Vector3 rotationVector = new() { y = InputManager.Instance.GetCameraRotateAmount() };
|
|
|
|
|
transform.eulerAngles += Time.deltaTime * rotationSpeed * rotationVector;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleZoom() {
|
|
|
|
|
switch (Input.mouseScrollDelta.y) {
|
|
|
|
|
case > 0:
|
|
|
|
|
targetFollowOffset.y -= zoomAmount;
|
|
|
|
|
break;
|
|
|
|
|
case < 0:
|
|
|
|
|
targetFollowOffset.y += zoomAmount;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
targetFollowOffset.y += InputManager.Instance.GetCameraZoomAmount() * zoomIncreaseAmount;
|
|
|
|
|
targetFollowOffset.y = Mathf.Clamp(targetFollowOffset.y, minFollowYOffset, maxFollowYOffset);
|
|
|
|
|
cinemachineTransposer.m_FollowOffset = Vector3.Lerp(cinemachineTransposer.m_FollowOffset, targetFollowOffset, zoomSpeed * Time.deltaTime);
|
|
|
|
|
}
|
|
|
|
|
|