Files
2026-03-04 10:03:45 +08:00

58 lines
1.4 KiB
C#

using UnityEngine;
namespace AQUAS
{
[AddComponentMenu("AQUAS/Utils/Camera Navigation")]
public class AQUAS_CamNav : MonoBehaviour
{
public bool freeLookEnabled = true;
public bool showCursor = true;
public float lookSpeed = 5f;
public float moveSpeed = 5f;
public float sprintSpeed = 50f;
private float m_yaw;
private float m_pitch;
private bool rotate;
private void Start()
{
m_yaw = base.transform.rotation.eulerAngles.y;
m_pitch = base.transform.rotation.eulerAngles.x;
Cursor.visible = showCursor;
}
private void Update()
{
if (freeLookEnabled)
{
m_yaw = (m_yaw + lookSpeed * Input.GetAxis("Mouse X")) % 360f;
m_pitch = (m_pitch - lookSpeed * Input.GetAxis("Mouse Y")) % 360f;
if (Input.GetMouseButtonDown(0))
{
rotate = true;
}
if (Input.GetMouseButtonUp(0))
{
rotate = false;
}
if (rotate)
{
base.transform.rotation = Quaternion.AngleAxis(m_yaw, Vector3.up) * Quaternion.AngleAxis(m_pitch, Vector3.right);
}
float num = Time.deltaTime * (Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : moveSpeed);
float num2 = num * Input.GetAxis("Vertical");
float num3 = num * Input.GetAxis("Horizontal");
float num4 = num * ((Input.GetKey(KeyCode.Q) ? 1f : 0f) - (Input.GetKey(KeyCode.E) ? 1f : 0f));
base.transform.position += base.transform.forward * num2 + base.transform.right * num3 + Vector3.up * num4;
}
}
}
}