Integrated terrain, mouse drag and rotation
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Cinemachine;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraSystem : MonoBehaviour
|
||||
@@ -22,14 +21,25 @@ public class CameraSystem : MonoBehaviour
|
||||
private bool _useEdgeScrolling;
|
||||
[SerializeField]
|
||||
private bool _useMouseDrag;
|
||||
[SerializeField]
|
||||
private bool _useMouseRotate;
|
||||
|
||||
private Vector3 _followOffset;
|
||||
[SerializeField]
|
||||
private float _rotateSpeed = 100f;
|
||||
[SerializeField]
|
||||
private float _mouseRotationSpeed = 3f;
|
||||
[SerializeField]
|
||||
private float _moveSpeed = 25f;
|
||||
[SerializeField]
|
||||
private int _edgeScrollSize = 20;
|
||||
private bool _dragPanMoveActive = false;
|
||||
private bool _dragRotateMoveActive = false;
|
||||
[SerializeField]
|
||||
private float _dragPanSpeed = 2f;
|
||||
[SerializeField]
|
||||
private float _zoomSpeed = 2f;
|
||||
[SerializeField]
|
||||
private float _zoomAmount = 3f;
|
||||
private Vector2 _lastMousePosition;
|
||||
private float _targetFieldOfView = 60f;
|
||||
@@ -38,7 +48,7 @@ public class CameraSystem : MonoBehaviour
|
||||
private void Awake()
|
||||
{
|
||||
_cinemachineTransposer = _camera.GetCinemachineComponent<CinemachineTransposer>();
|
||||
_followOffset = _cinemachineTransposer.m_FollowOffset;
|
||||
_followOffset = _cinemachineTransposer.m_FollowOffset;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
@@ -78,9 +88,9 @@ public class CameraSystem : MonoBehaviour
|
||||
private void HandleCameraZoom_MoveY()
|
||||
{
|
||||
if (Input.mouseScrollDelta.y > 0)
|
||||
_followOffset.y -= _zoomAmount;
|
||||
_followOffset.y -= _zoomAmount;
|
||||
if (Input.mouseScrollDelta.y < 0)
|
||||
_followOffset.y += _zoomAmount;
|
||||
_followOffset.y += _zoomAmount;
|
||||
|
||||
_followOffset.y = Mathf.Clamp(_followOffset.y, _followOffsetMinY, _followOffsetMaxY);
|
||||
|
||||
@@ -90,7 +100,7 @@ public class CameraSystem : MonoBehaviour
|
||||
if (_followOffset.magnitude > _followOffsetMax)
|
||||
_followOffset.y = _zoomAmount * _followOffsetMax;
|
||||
|
||||
|
||||
|
||||
|
||||
Vector3.Lerp(_cinemachineTransposer.m_FollowOffset, _followOffset, Time.deltaTime * _zoomSpeed);
|
||||
|
||||
@@ -167,8 +177,23 @@ public class CameraSystem : MonoBehaviour
|
||||
|
||||
if (Input.GetKey(KeyCode.E)) rotateDir = 1f;
|
||||
if (Input.GetKey(KeyCode.Q)) rotateDir = -1f;
|
||||
if (_useMouseRotate)
|
||||
{
|
||||
if (Input.GetMouseButtonDown(2))
|
||||
{
|
||||
_dragRotateMoveActive = true;
|
||||
_lastMousePosition = Input.mousePosition;
|
||||
}
|
||||
if (Input.GetMouseButtonUp(2)) { _dragRotateMoveActive = false; }
|
||||
if (_dragRotateMoveActive)
|
||||
{
|
||||
Vector2 mouseMovementDelta = ((Vector2)Input.mousePosition - _lastMousePosition);
|
||||
rotateDir = mouseMovementDelta.x;
|
||||
|
||||
|
||||
transform.eulerAngles += new Vector3(0, rotateDir * _rotateSpeed * Time.deltaTime, 0);
|
||||
_lastMousePosition = Input.mousePosition;
|
||||
}
|
||||
}
|
||||
var speed = _dragRotateMoveActive ? _mouseRotationSpeed : _rotateSpeed;
|
||||
transform.eulerAngles += new Vector3(0, rotateDir * speed * Time.deltaTime, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user