feat():大改前的提交,这个版本保存了所有冗余的代码
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
using Input;
|
||||
using Script.Gameplay.Input;
|
||||
|
||||
namespace Gameplay.Player
|
||||
{
|
||||
@@ -10,34 +10,28 @@ namespace Gameplay.Player
|
||||
/// </summary>
|
||||
public class PlayerCameraController : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[Tooltip("角色根 Transform,用于水平旋转(yaw)")]
|
||||
[Header("References")] [Tooltip("角色根 Transform,用于水平旋转(yaw)")]
|
||||
public Transform playerBody;
|
||||
|
||||
[Tooltip("如果相机不是挂载在同一物体上,可以指定相机 Transform(可选)")]
|
||||
public Transform cameraTransform;
|
||||
|
||||
[Header("Sensitivity & Invert")]
|
||||
[Tooltip("鼠标灵敏度")]
|
||||
[Range(0.01f, 1f)]
|
||||
[Header("Sensitivity & Invert")] [Tooltip("鼠标灵敏度")] [Range(0.01f, 1f)]
|
||||
public float mouseSensitivity = 0.2f;
|
||||
|
||||
[Tooltip("反转垂直轴")]
|
||||
public bool invertY = false;
|
||||
[Tooltip("反转垂直轴")] public bool invertY = false;
|
||||
|
||||
[Header("Vertical Limits")]
|
||||
[Tooltip("向上最大仰角(度)")]
|
||||
[Header("Vertical Limits")] [Tooltip("向上最大仰角(度)")]
|
||||
public float maxUpAngle = 60f;
|
||||
[Tooltip("向下最大俯角(度)")]
|
||||
public float maxDownAngle = 60f;
|
||||
|
||||
[Header("Smoothing")]
|
||||
public bool enableSmoothing = false;
|
||||
[Tooltip("旋转平滑时间(秒)")]
|
||||
public float smoothTime = 0.05f;
|
||||
[Tooltip("向下最大俯角(度)")] public float maxDownAngle = 60f;
|
||||
|
||||
[Header("Smoothing")] public bool enableSmoothing = false;
|
||||
[Tooltip("旋转平滑时间(秒)")] public float smoothTime = 0.05f;
|
||||
|
||||
// internal state
|
||||
private float xRotation = 0f; // 垂直角(pitch)
|
||||
private float yaw = 0f; // 水平角(yaw)
|
||||
private float yaw = 0f; // 水平角(yaw)
|
||||
private float smoothVelocityPitch = 0f;
|
||||
private float smoothVelocityYaw = 0f;
|
||||
|
||||
@@ -50,7 +44,6 @@ namespace Gameplay.Player
|
||||
Vector3 euler = cameraTransform.localEulerAngles;
|
||||
xRotation = NormalizeAngle(euler.x);
|
||||
yaw = NormalizeAngle(playerBody ? playerBody.eulerAngles.y : transform.eulerAngles.y);
|
||||
|
||||
}
|
||||
|
||||
void Update()
|
||||
@@ -71,8 +64,10 @@ namespace Gameplay.Player
|
||||
|
||||
if (enableSmoothing)
|
||||
{
|
||||
float smoothPitch = Mathf.SmoothDampAngle(cameraTransform.localEulerAngles.x, xRotation, ref smoothVelocityPitch, smoothTime);
|
||||
float smoothYaw = Mathf.SmoothDampAngle(playerBody ? playerBody.eulerAngles.y : transform.eulerAngles.y, yaw, ref smoothVelocityYaw, smoothTime);
|
||||
float smoothPitch = Mathf.SmoothDampAngle(cameraTransform.localEulerAngles.x, xRotation,
|
||||
ref smoothVelocityPitch, smoothTime);
|
||||
float smoothYaw = Mathf.SmoothDampAngle(playerBody ? playerBody.eulerAngles.y : transform.eulerAngles.y,
|
||||
yaw, ref smoothVelocityYaw, smoothTime);
|
||||
|
||||
cameraTransform.localRotation = Quaternion.Euler(smoothPitch, 0f, 0f);
|
||||
if (playerBody)
|
||||
@@ -97,5 +92,7 @@ namespace Gameplay.Player
|
||||
angle = (angle + 180f) % 360f - 180f;
|
||||
return angle;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user