72 lines
2.2 KiB
C#
72 lines
2.2 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 MyCharacterController _CameraCtrl;
|
|
|
|
private float rotX = 0.0f;
|
|
private float rotY = 0.0f;
|
|
public float _RotSpeed = 256;
|
|
|
|
[ReadOnly]//点击操作说明或者系统设置后,禁止操作
|
|
public bool _AllForbid = false;
|
|
private void Awake()
|
|
{
|
|
#if VR
|
|
gameObject.SetActive(false);
|
|
#endif
|
|
}
|
|
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);//防止翻跟头
|
|
|
|
|
|
|
|
|
|
//Quaternion rotation = Quaternion.Euler(rotY, rotX, 0);//利用欧拉角防止万向锁
|
|
//transform.rotation = rotation;
|
|
transform.localEulerAngles = new Vector3(rotY, rotX);
|
|
}
|
|
}
|
|
}
|
|
}
|