diff --git a/Assets/CameraBehaviour.cs b/Assets/CameraBehaviour.cs index 445877b..775ec22 100644 --- a/Assets/CameraBehaviour.cs +++ b/Assets/CameraBehaviour.cs @@ -7,15 +7,14 @@ public class CameraBehaviour : MonoBehaviour private const int MouseWheelSensitivity = 1; //滚轮灵敏度设置 private const int MouseZoomMin = 1; //相机距离最小值 private const int MouseZoomMax = 20; //相机距离最大值 - private const float XSpeed = 250.0f; - private const float YSpeed = 120.0f; + private const float XSpeed = 120.0f; + private const float YSpeed = 250.0f; private const int YMinLimit = -360; private const int YMaxLimit = 360; private float _eulerX; //存储相机的euler角 private float _eulerY; //存储相机的euler角 - - private float _distance = 5; //相机和target之间的距离,因为相机的Z轴总是指向target,也就是相机z轴方向上的距离 + private float _distance; //相机和target之间的距离,因为相机的Z轴总是指向target,也就是相机z轴方向上的距离 private Vector3 _targetOnScreenPosition; //目标的屏幕坐标,第三个值为z轴距离 private Quaternion _cameraRotation; //存储相机的姿态四元数 private Vector3 _targetPosition; //target的位置 @@ -31,10 +30,12 @@ private void Start() { //这里就是设置一下初始的相机视角以及一些其他变量,这里的x和y。。。是和下面getAxis的mouse x与mouse y对应 var angles = transform.eulerAngles; - _eulerX = angles.y; - _eulerY = angles.x; - _targetPosition = target.position; - _cameraRotation = Quaternion.Euler(_eulerY + 60, _eulerX, 0); + _eulerX = angles.x; + _eulerY = angles.y; + var position = target.position; + _targetPosition = position; + _cameraRotation = Quaternion.Euler(_eulerX, _eulerY, 0); + _distance = Vector3.Distance(position, transform.position); // 引入中间变量 提高代码效率 var transform1 = transform; @@ -52,12 +53,12 @@ private void Update() //鼠标右键旋转功能 if (Input.GetMouseButton(1)) { - _eulerX += Input.GetAxis("Mouse X") * XSpeed * 0.02f; - _eulerY -= Input.GetAxis("Mouse Y") * YSpeed * 0.02f; + // 鼠标控制需要反转X、Y轴 + _eulerX += Input.GetAxis("Mouse Y") * XSpeed * 0.02f; + _eulerX = ClampAngle(_eulerX, YMinLimit, YMaxLimit); + _eulerY -= Input.GetAxis("Mouse X") * YSpeed * 0.02f; - _eulerY = ClampAngle(_eulerY, YMinLimit, YMaxLimit); - - _cameraRotation = Quaternion.Euler(_eulerY + 60, _eulerX, 0); + _cameraRotation = Quaternion.Euler(_eulerX, _eulerY, 0); var position = _cameraRotation * new Vector3(0.0f, 0.0f, -_distance) + _targetPosition; // 引入中间变量 提高代码效率 @@ -65,7 +66,8 @@ private void Update() transform1.rotation = _cameraRotation; transform1.position = position; } - else if (Input.GetAxis("Mouse ScrollWheel") != 0) //鼠标滚轮缩放功能 + + if (Input.GetAxis("Mouse ScrollWheel") != 0) //鼠标滚轮缩放功能 { if (_distance is >= MouseZoomMin and <= MouseZoomMax) { diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 0465b9b..73b3b62 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -406,7 +406,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 963194225} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -10} + m_LocalPosition: {x: -0.3, y: 1.06, z: -8.26} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] diff --git a/Packages/manifest.json b/Packages/manifest.json index de2f422..18cb02c 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -2,7 +2,7 @@ "dependencies": { "com.unity.collab-proxy": "1.17.7", "com.unity.feature.development": "1.0.1", - "com.unity.ide.rider": "3.0.16", + "com.unity.ide.rider": "3.0.18", "com.unity.ide.visualstudio": "2.0.16", "com.unity.ide.vscode": "1.2.5", "com.unity.test-framework": "1.1.31", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 5bc5a0b..9e9f9a2 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -38,7 +38,7 @@ } }, "com.unity.ide.rider": { - "version": "3.0.16", + "version": "3.0.18", "depth": 0, "source": "registry", "dependencies": {