Merge branch 'master' into feature-binding
# Conflicts: # Assets/Behaviours/CameraBehaviour.cs # Assets/Scenes/SampleScene.unity # Packages/manifest.json
This commit is contained in:
commit
9a09585f01
|
@ -7,15 +7,14 @@ public class CameraBehaviour : MonoBehaviour
|
||||||
private const int MouseWheelSensitivity = 1; //滚轮灵敏度设置
|
private const int MouseWheelSensitivity = 1; //滚轮灵敏度设置
|
||||||
private const int MouseZoomMin = 1; //相机距离最小值
|
private const int MouseZoomMin = 1; //相机距离最小值
|
||||||
private const int MouseZoomMax = 20; //相机距离最大值
|
private const int MouseZoomMax = 20; //相机距离最大值
|
||||||
private const float XSpeed = 250.0f;
|
private const float XSpeed = 120.0f;
|
||||||
private const float YSpeed = 120.0f;
|
private const float YSpeed = 250.0f;
|
||||||
private const int YMinLimit = -360;
|
private const int YMinLimit = -360;
|
||||||
private const int YMaxLimit = 360;
|
private const int YMaxLimit = 360;
|
||||||
|
|
||||||
private float _eulerX; //存储相机的euler角
|
private float _eulerX; //存储相机的euler角
|
||||||
private float _eulerY; //存储相机的euler角
|
private float _eulerY; //存储相机的euler角
|
||||||
|
private float _distance; //相机和target之间的距离,因为相机的Z轴总是指向target,也就是相机z轴方向上的距离
|
||||||
private float _distance = 5; //相机和target之间的距离,因为相机的Z轴总是指向target,也就是相机z轴方向上的距离
|
|
||||||
private Vector3 _targetOnScreenPosition; //目标的屏幕坐标,第三个值为z轴距离
|
private Vector3 _targetOnScreenPosition; //目标的屏幕坐标,第三个值为z轴距离
|
||||||
private Quaternion _cameraRotation; //存储相机的姿态四元数
|
private Quaternion _cameraRotation; //存储相机的姿态四元数
|
||||||
private Vector3 _targetPosition; //target的位置
|
private Vector3 _targetPosition; //target的位置
|
||||||
|
@ -31,11 +30,13 @@ private void Start()
|
||||||
{
|
{
|
||||||
//这里就是设置一下初始的相机视角以及一些其他变量,这里的x和y。。。是和下面getAxis的mouse x与mouse y对应
|
//这里就是设置一下初始的相机视角以及一些其他变量,这里的x和y。。。是和下面getAxis的mouse x与mouse y对应
|
||||||
var angles = transform.eulerAngles;
|
var angles = transform.eulerAngles;
|
||||||
_eulerX = angles.y;
|
_eulerX = angles.x;
|
||||||
_eulerY = angles.x;
|
_eulerY = angles.y;
|
||||||
_targetPosition = target.position;
|
var position = target.position;
|
||||||
//_cameraRotation = Quaternion.Euler(_eulerY + 60, _eulerX, 0);
|
_targetPosition = position;
|
||||||
_cameraRotation = Quaternion.Euler(_eulerY, _eulerX, 0);
|
_cameraRotation = Quaternion.Euler(_eulerX, _eulerY, 0);
|
||||||
|
_distance = Vector3.Distance(position, transform.position);
|
||||||
|
|
||||||
// 引入中间变量 提高代码效率
|
// 引入中间变量 提高代码效率
|
||||||
var transform1 = transform;
|
var transform1 = transform;
|
||||||
//设置相机姿态
|
//设置相机姿态
|
||||||
|
@ -52,13 +53,12 @@ private void Update()
|
||||||
//鼠标右键旋转功能
|
//鼠标右键旋转功能
|
||||||
if (Input.GetMouseButton(1))
|
if (Input.GetMouseButton(1))
|
||||||
{
|
{
|
||||||
_eulerX += Input.GetAxis("Mouse X") * XSpeed * 0.02f;
|
// 鼠标控制需要反转X、Y轴
|
||||||
_eulerY -= Input.GetAxis("Mouse Y") * YSpeed * 0.02f;
|
_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(_eulerX, _eulerY, 0);
|
||||||
|
|
||||||
//_cameraRotation = Quaternion.Euler(_eulerY + 60, _eulerX, 0);
|
|
||||||
_cameraRotation = Quaternion.Euler(_eulerY, _eulerX, 0);
|
|
||||||
var position = _cameraRotation * new Vector3(0.0f, 0.0f, -_distance) + _targetPosition;
|
var position = _cameraRotation * new Vector3(0.0f, 0.0f, -_distance) + _targetPosition;
|
||||||
|
|
||||||
// 引入中间变量 提高代码效率
|
// 引入中间变量 提高代码效率
|
||||||
|
@ -66,7 +66,8 @@ private void Update()
|
||||||
transform1.rotation = _cameraRotation;
|
transform1.rotation = _cameraRotation;
|
||||||
transform1.position = position;
|
transform1.position = position;
|
||||||
}
|
}
|
||||||
else if (Input.GetAxis("Mouse ScrollWheel") != 0) //鼠标滚轮缩放功能
|
|
||||||
|
if (Input.GetAxis("Mouse ScrollWheel") != 0) //鼠标滚轮缩放功能
|
||||||
{
|
{
|
||||||
if (_distance is >= MouseZoomMin and <= MouseZoomMax)
|
if (_distance is >= MouseZoomMin and <= MouseZoomMax)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user