//旋转参数
public float x = 0.0f;//相机旋转角度
public float y = 0.0f;
public float z = 0.0f;
private float xSpeed = 250.0f;//鼠标在x、y轴方向旋转的速度
private float ySpeed = 120.0f;
//缩放参数
private float nomalscale;
private float MouseWheelSensitivity;
private float MouseZoomMin;
private float MouseZoomMax;
//平移参数
private Vector3 screenPoint;
private Vector3 offset;
// Use this for initialization
void Start()
{
Vector3 angles = this.transform.eulerAngles;
x = angles.y;
y = angles.x;
z = angles.z;
nomalscale = Mathf.Abs(this.transform.localScale.x /** 2.0f*/);
MouseWheelSensitivity = /*Mathf.Abs(this.transform.localScale.x)*/0.3f;
MouseZoomMin = 0.1f * nomalscale;
MouseZoomMax = 6.0f * nomalscale;
}
// Update is called once per frame
void LateUpdate()
{
if (Input.GetMouseButton(1))
{
x -= Input.GetAxis("Mouse X") * xSpeed * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
//z = this.transform.eulerAngles.z;
//y = ClampAngle(y, yMinLimit, yMaxLimit);
Quaternion rotation = Quaternion.Euler(y, x, z);
this.transform.rotation = rotation;
// this.transform.Rotate(y,x,0,Space.World);
}
else if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
if (nomalscale >= MouseZoomMin && nomalscale <= MouseZoomMax)
{
nomalscale += Input.GetAxis("Mouse ScrollWheel") * MouseWheelSensitivity;
}
if (nomalscale < MouseZoomMin)
{
nomalscale = MouseZoomMin;
}
if (nomalscale > MouseZoomMax)
{
nomalscale = MouseZoomMax;
}
this.transform.localScale = new Vector3(nomalscale, nomalscale, nomalscale);
}
}
static float ClampAngle (float angle , float min ,float max)
{
// print ( " angle" + angle);
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}