|
|
@ -37,12 +37,21 @@ public class CameraControl : MonoBehaviour |
|
|
public float xMinMove; |
|
|
public float xMinMove; |
|
|
public float yMaxMove; |
|
|
public float yMaxMove; |
|
|
public float yMinMove; |
|
|
public float yMinMove; |
|
|
|
|
|
Vector3 xMaxPos; |
|
|
|
|
|
Vector3 xMinPos; |
|
|
|
|
|
Vector3 yMaxPos; |
|
|
|
|
|
Vector3 yMinPos; |
|
|
|
|
|
|
|
|
void Start() |
|
|
void Start() |
|
|
{ |
|
|
{ |
|
|
rotationX = transform.localEulerAngles.y; |
|
|
rotationX = transform.localEulerAngles.y; |
|
|
rotationY = -transform .localEulerAngles.x; |
|
|
rotationY = -transform .localEulerAngles.x; |
|
|
startRotation = transform.localEulerAngles; |
|
|
startRotation = transform.localEulerAngles; |
|
|
startPos = transform.position; |
|
|
startPos = transform.position; |
|
|
|
|
|
xMaxPos = transform.position + new Vector3(xMaxMove, 0, 0); |
|
|
|
|
|
xMinPos = transform .position + new Vector3 (xMinMove, 0, 0); |
|
|
|
|
|
yMaxPos = transform.position + new Vector3(0, 0, yMaxMove); |
|
|
|
|
|
yMinPos = transform .position + new Vector3 ( 0, 0, yMinMove); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void LateUpdate() |
|
|
private void LateUpdate() |
|
|
@ -56,23 +65,88 @@ public class CameraControl : MonoBehaviour |
|
|
//平面向量
|
|
|
//平面向量
|
|
|
Quaternion rotation = Quaternion.AngleAxis(90 - transform.localEulerAngles.x, transform.right); |
|
|
Quaternion rotation = Quaternion.AngleAxis(90 - transform.localEulerAngles.x, transform.right); |
|
|
Vector3 dir = rotation * transform.up; |
|
|
Vector3 dir = rotation * transform.up; |
|
|
|
|
|
if (transform.position.x > xMaxPos.x) |
|
|
|
|
|
{ |
|
|
|
|
|
if (moveX < 0) |
|
|
|
|
|
{ |
|
|
|
|
|
moveX = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (transform.position.x < xMinPos.x) |
|
|
|
|
|
{ |
|
|
|
|
|
if (moveX > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
moveX = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (transform.position.z > yMaxPos.z) |
|
|
|
|
|
{ |
|
|
|
|
|
if (moveY < 0) |
|
|
|
|
|
{ |
|
|
|
|
|
moveY = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (transform.position.z < yMinPos.z) |
|
|
|
|
|
{ |
|
|
|
|
|
if (moveY > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
moveY = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
Vector3 x = Vector3.right * -moveX * Time.deltaTime; |
|
|
|
|
|
if (Mathf.Abs(x.x) > 0.2f) |
|
|
|
|
|
{ |
|
|
|
|
|
x.x = 0f; |
|
|
|
|
|
} |
|
|
|
|
|
transform.Translate(x); |
|
|
|
|
|
|
|
|
transform.Translate(dir * -moveY * Time.deltaTime, Space.World); |
|
|
Vector3 z = dir * -moveY * Time.deltaTime; |
|
|
transform.Translate(Vector3.right * -moveX * Time.deltaTime); |
|
|
if(Mathf .Abs (z.z)>0.2f) |
|
|
|
|
|
{ |
|
|
|
|
|
z.z = 0f; |
|
|
|
|
|
} |
|
|
|
|
|
transform.Translate(z, Space.World); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
keyBoardMoveX = Input.GetAxis("Vertical") * moveSpeed / 2.0f; |
|
|
keyBoardMoveY = Input.GetAxis("Vertical") * moveSpeed / 2.0f; |
|
|
keyBoardMoveY = Input.GetAxis("Horizontal") * moveSpeed / 2.0f; |
|
|
keyBoardMoveX = Input.GetAxis("Horizontal") * moveSpeed / 2.0f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//平面向量
|
|
|
//平面向量
|
|
|
Quaternion rotation = Quaternion.AngleAxis(90 - transform.localEulerAngles.x, transform.right); |
|
|
Quaternion rotation = Quaternion.AngleAxis(90 - transform.localEulerAngles.x, transform.right); |
|
|
Vector3 dir = rotation * transform.up; |
|
|
Vector3 dir = rotation * transform.up; |
|
|
|
|
|
if (transform.position.x > xMaxPos.x) |
|
|
|
|
|
{ |
|
|
|
|
|
if (keyBoardMoveX > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
keyBoardMoveX = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (transform.position.x < xMinPos.x) |
|
|
|
|
|
{ |
|
|
|
|
|
if (keyBoardMoveX < 0) |
|
|
|
|
|
{ |
|
|
|
|
|
keyBoardMoveX = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (transform.position.z > yMaxPos.z) |
|
|
|
|
|
{ |
|
|
|
|
|
if (keyBoardMoveY > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
keyBoardMoveY = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (transform.position.z < yMinPos.z) |
|
|
|
|
|
{ |
|
|
|
|
|
if (keyBoardMoveY < 0) |
|
|
|
|
|
{ |
|
|
|
|
|
keyBoardMoveY = 0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
transform.Translate(Vector3.right * keyBoardMoveX * Time.deltaTime); |
|
|
|
|
|
transform.Translate(dir * keyBoardMoveY * Time.deltaTime, Space.World); |
|
|
|
|
|
|
|
|
transform.Translate(dir * keyBoardMoveX * Time.deltaTime, Space.World); |
|
|
|
|
|
transform.Translate(Vector3.right * keyBoardMoveY * Time.deltaTime); |
|
|
|
|
|
} |
|
|
} |
|
|
//按下鼠标右键-旋转
|
|
|
//按下鼠标右键-旋转
|
|
|
if (Input.GetMouseButton(1)) |
|
|
if (Input.GetMouseButton(1)) |
|
|
@ -90,14 +164,24 @@ public class CameraControl : MonoBehaviour |
|
|
if (scrollWheelInput > 0f && virtualCamera.m_Lens.FieldOfView < yMaxDistance) |
|
|
if (scrollWheelInput > 0f && virtualCamera.m_Lens.FieldOfView < yMaxDistance) |
|
|
{ |
|
|
{ |
|
|
// Debug.Log("向上滚动鼠标滚轮");
|
|
|
// Debug.Log("向上滚动鼠标滚轮");
|
|
|
virtualCamera.m_Lens.FieldOfView += Time.deltaTime * fovSpeed * scrollWheelInput; |
|
|
float fovMove = Time.deltaTime * fovSpeed * scrollWheelInput; |
|
|
|
|
|
if (fovMove > 2) |
|
|
|
|
|
{ |
|
|
|
|
|
fovMove = 0; |
|
|
|
|
|
} |
|
|
|
|
|
virtualCamera.m_Lens.FieldOfView += fovMove; |
|
|
//transform.position += new Vector3(0, Time.deltaTime * fovSpeed * scrollWheelInput, 0);
|
|
|
//transform.position += new Vector3(0, Time.deltaTime * fovSpeed * scrollWheelInput, 0);
|
|
|
} |
|
|
} |
|
|
else if (scrollWheelInput < 0f && virtualCamera.m_Lens.FieldOfView > yMinDistance) |
|
|
else if (scrollWheelInput < 0f && virtualCamera.m_Lens.FieldOfView > yMinDistance) |
|
|
{ |
|
|
{ |
|
|
// Debug.Log("向下滚动鼠标滚轮");
|
|
|
// Debug.Log("向下滚动鼠标滚轮");
|
|
|
virtualCamera.m_Lens.FieldOfView += Time.deltaTime * fovSpeed * scrollWheelInput; |
|
|
float fovMove = Time.deltaTime * fovSpeed * scrollWheelInput; |
|
|
// transform.position += new Vector3(0, Time.deltaTime * fovSpeed * scrollWheelInput, 0);
|
|
|
if (fovMove > 2) |
|
|
|
|
|
{ |
|
|
|
|
|
fovMove = 0; |
|
|
|
|
|
} |
|
|
|
|
|
virtualCamera.m_Lens.FieldOfView += fovMove; |
|
|
|
|
|
// transform.position += new Vector3(0, Time.deltaTime * fovSpeed * scrollWheelInput, 0);
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
void Update() |
|
|
void Update() |
|
|
|