You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.4 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//-----------------------------------------------------------------
//1把本类作为一个组件包含在 GameObject 中。
//2左手坐标系。
//-----------------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//-----------------------------------------------------------------
public class FiCameraControl : MonoBehaviour
{
public float moveSpeed = 30.0f;
public float rotateSpeed = 0.2f;
public float m_DampTime = 2f;
public static Vector3 kUpDirection = new Vector3(0.0f, 1.0f, 0.0f);
//控制摄像机旋转的成员变量。
private float m_fLastMousePosX = 0.0f;
private float m_fLastMousePosY = 0.0f;
private bool m_bMouseRightKeyDown = false;
private Camera m_Camera;
private float m_ZoomSpeed;
private Vector3 m_MoveVelocity = Vector3.zero;
private Vector3 m_originPos;
private Vector3 m_targetPos;
private float m_size;
//-----------------------------------------------------------------
void Start()
{
m_Camera = GetComponent<Camera>();
m_targetPos = transform.position;
m_originPos = transform.position;
m_size = m_Camera.fieldOfView;
}
public void Move(Vector3 targetPos)
{
m_originPos = transform.position;
m_targetPos = targetPos;
}
private void Move()
{
transform.position = Vector3.SmoothDamp(transform.position, m_targetPos, ref m_MoveVelocity, m_DampTime);
}
public void Zoom(float size)
{
m_size = size;
}
public void Zoom()
{
m_Camera.fieldOfView = Mathf.SmoothDamp(m_Camera.fieldOfView, m_size, ref m_ZoomSpeed, m_DampTime);
}
private void FixedUpdate()
{
Move();
Zoom();
}
    //-----------------------------------------------------------------
    void Update()
{
        //判断旋转
        //if (Input.GetMouseButtonDown(1)) //鼠标右键刚刚按下了
        //{
// var missle = GameObject.Find("CJ_Missile_Tests_daodangM_001");
// if (m_bMouseRightKeyDown == false)
// {
// m_bMouseRightKeyDown = true;
// Vector3 kMousePos = Input.mousePosition;
// m_fLastMousePosX = kMousePos.x;
// m_fLastMousePosY = kMousePos.y;
// }
//}
//else if (Input.GetMouseButtonUp(1)) //鼠标右键刚刚抬起了
        //{
// if (m_bMouseRightKeyDown == true)
// {
// m_bMouseRightKeyDown = false;
// m_fLastMousePosX = 0;
// m_fLastMousePosY = 0;
// }
//}
//else if (Input.GetMouseButton(1)) //鼠标右键处于按下状态中
        //{
// if (m_bMouseRightKeyDown)
// {
// Vector3 kMousePos = Input.mousePosition;
// float fDeltaX = kMousePos.x - m_fLastMousePosX;
// float fDeltaY = kMousePos.y - m_fLastMousePosY;
// m_fLastMousePosX = kMousePos.x;
// m_fLastMousePosY = kMousePos.y;
// Vector3 kNewEuler = transform.eulerAngles;
// kNewEuler.x += (fDeltaY * rotateSpeed);
// kNewEuler.y += -(fDeltaX * rotateSpeed);
// transform.eulerAngles = kNewEuler;
// }
//}
////判断位移
//float fMoveDeltaX = 0.0f;
//float fMoveDeltaZ = 0.0f;
//float fDeltaTime = Time.deltaTime;
//if (Input.GetKey(KeyCode.A))
//{
// fMoveDeltaX -= moveSpeed * fDeltaTime;
//}
//if (Input.GetKey(KeyCode.D))
//{
// fMoveDeltaX += moveSpeed * fDeltaTime;
//}
//if (Input.GetKey(KeyCode.W))
//{
// fMoveDeltaZ += moveSpeed * fDeltaTime;
//}
//if (Input.GetKey(KeyCode.S))
//{
// fMoveDeltaZ -= moveSpeed * fDeltaTime;
//}
//if (fMoveDeltaX != 0.0f || fMoveDeltaZ != 0.0f)
//{
// Vector3 kForward = transform.forward;
// Vector3 kRight = Vector3.Cross(kUpDirection, kForward);
// Vector3 kNewPos = transform.position;
// kNewPos += kRight * fMoveDeltaX;
// kNewPos += kForward * fMoveDeltaZ;
// transform.position = kNewPos;
//}
}
}
//-----------------------------------------------------------------