60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using KinematicCharacterController.Walkthrough.NoClipState;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
/********************************************************************************
|
|
*Create By CG
|
|
*Function 摄像机自身控制控制
|
|
*WSAD:前后左右-QE:上下-鼠标滚轮:镜头远近-按住鼠标右键,拖动鼠标:摄像机上下左右旋转
|
|
*********************************************************************************/
|
|
namespace CG.UTility
|
|
{
|
|
public class CameraControl : MonoBehaviour
|
|
{
|
|
public float _moveSpeed = 0.06f;// 3.0f;
|
|
//public float _MoveSpeed { get => _moveSpeed * ZXK.LouDiXvMuNiu.GameManager.Instance._CurMouseFlexible; }
|
|
public float _MoveSpeed = 18f;
|
|
public MyCharacterController _CameraCtrl;
|
|
|
|
private float rotX = 0.0f;
|
|
private float rotY = 0.0f;
|
|
public float _RotSpeed = 256;
|
|
//点击操作说明或者系统设置后,禁止操作
|
|
public bool _AllForbid = false;
|
|
private void OnEnable()
|
|
{
|
|
RstCameraR();
|
|
}
|
|
//重置相机内容
|
|
public void RstCameraR()
|
|
{
|
|
Vector3 angles = transform.eulerAngles;
|
|
rotX = angles.y;
|
|
rotY = angles.x;
|
|
}
|
|
private void Update()
|
|
{
|
|
_CameraCtrl.NoClipMoveSpeed = _MoveSpeed;
|
|
//if (CG.UTility.PopUpMng._TriAble)
|
|
//{
|
|
SetCamRotation();
|
|
//}
|
|
}
|
|
private void SetCamRotation()
|
|
{
|
|
|
|
//鼠标右键,控制相机旋转
|
|
if (Input.GetKey(KeyCode.Mouse1))
|
|
{
|
|
float mouse_x = Input.GetAxis("Mouse X");
|
|
float mouse_y = Input.GetAxis("Mouse Y");
|
|
rotX += mouse_x * _RotSpeed * Time.deltaTime;
|
|
rotY -= mouse_y * _RotSpeed * Time.deltaTime;
|
|
rotY = Mathf.Clamp(rotY, -90, 90);//防止翻跟头
|
|
transform.localEulerAngles = new Vector3(rotY, rotX);
|
|
}
|
|
}
|
|
}
|
|
}
|