72 lines
2.2 KiB
C#
Raw Permalink Normal View History

2025-01-02 12:15:45 +08:00
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;
2025-01-19 13:45:40 +08:00
private float rotX = 0.0f;
private float rotY = 0.0f;
public float _RotSpeed = 256;
2025-01-02 12:15:45 +08:00
[ReadOnly]//点击操作说明或者系统设置后,禁止操作
public bool _AllForbid = false;
2025-04-01 16:16:45 +08:00
private void Awake()
{
#if VR
gameObject.SetActive(false);
#endif
}
2025-01-19 13:45:40 +08:00
private void OnEnable()
{
RstCameraR();
}
public void RstCameraR()
{
Vector3 angles = transform.eulerAngles;
rotX = angles.y;
rotY = angles.x;
}
2025-01-02 12:15:45 +08:00
private void Update()
{
_CameraCtrl.NoClipMoveSpeed = _MoveSpeed;
2025-01-19 13:45:40 +08:00
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);
}
2025-01-02 12:15:45 +08:00
}
}
}