切换主武器
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using DG.Tweening;
|
||||
using Sirenix.OdinInspector;
|
||||
using SLSFramework.General;
|
||||
using UnityEngine;
|
||||
using Ease = DG.Tweening.Ease;
|
||||
|
||||
namespace Cielonos.MainGame.Characters
|
||||
{
|
||||
@@ -18,7 +20,6 @@ namespace Cielonos.MainGame.Characters
|
||||
public float cinemachineTargetPitch;
|
||||
public float topClamp = 70.0f;
|
||||
public float bottomClamp = -30.0f;
|
||||
public float cameraAngleOverride = 0.0f;
|
||||
public bool lockCameraPosition = false;
|
||||
|
||||
[Title("Combat Recenter Settings")]
|
||||
@@ -61,13 +62,16 @@ namespace Cielonos.MainGame.Characters
|
||||
|
||||
cinemachineTargetYaw = MathExtensions.ClampAngle(cinemachineTargetYaw, float.MinValue, float.MaxValue);
|
||||
cinemachineTargetPitch = MathExtensions.ClampAngle(cinemachineTargetPitch, bottomClamp, topClamp);
|
||||
|
||||
viewSc.cameraRoot.rotation = Quaternion.Euler(
|
||||
cinemachineTargetPitch + cameraAngleOverride /*- viewSc.muzzleLiftModule.currentMuzzlePositionY*/, cinemachineTargetYaw, 0.0f);
|
||||
|
||||
if (viewSc.isLockingTarget)
|
||||
|
||||
|
||||
if (viewSc.lockTargetModule.isUsingLockTargetCamera)
|
||||
{
|
||||
cinemachineEndLockYaw = viewSc.lockOnCamera.transform.eulerAngles.y;
|
||||
cinemachineEndLockYaw = viewSc.lockingTargetCamera.transform.eulerAngles.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
viewSc.cameraRoot.rotation = Quaternion.Euler(
|
||||
cinemachineTargetPitch /*- viewSc.muzzleLiftModule.currentMuzzlePositionY*/, cinemachineTargetYaw, 0.0f);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -108,23 +112,34 @@ namespace Cielonos.MainGame.Characters
|
||||
recenterTimer = duration;
|
||||
isRecentering = true;
|
||||
}
|
||||
|
||||
private bool tt;
|
||||
|
||||
// 将此方法添加到你控制相机旋转的脚本中 (例如 PlayerCameraController)
|
||||
public void SyncRotationWithCamera(Camera camera = null)
|
||||
/// <summary>
|
||||
/// 同步相机旋转到当前摄像机朝向
|
||||
/// </summary>
|
||||
public void SyncRotationWithCamera()
|
||||
{
|
||||
camera ??= viewSc.playerCamera;
|
||||
// 确保获取的是当前正在起作用的锁定相机的旋转
|
||||
var camera = viewSc.currentCamera;
|
||||
Vector3 currentEuler = camera.transform.eulerAngles;
|
||||
cinemachineTargetYaw = currentEuler.y;
|
||||
float currentPitch = currentEuler.x;
|
||||
if (currentPitch > 180)
|
||||
{
|
||||
currentPitch -= 360;
|
||||
}
|
||||
cinemachineTargetPitch = currentPitch - cameraAngleOverride;
|
||||
|
||||
float yaw = currentEuler.y;
|
||||
float pitch = currentEuler.x;
|
||||
|
||||
// --- 核心修复:处理欧拉角跨度问题 ---
|
||||
// 如果 pitch > 180 (例如 355), 则转为负数 ( -5 )
|
||||
if (pitch > 180) pitch -= 360;
|
||||
|
||||
isRecentering = false;
|
||||
// 强制执行一次旋转更新,防止下一帧才生效导致的微小跳动 (可选)
|
||||
// viewSc.cameraRoot.rotation = Quaternion.Euler(
|
||||
// cinemachineTargetPitch + cameraAngleOverride, cinemachineTargetYaw, 0.0f);
|
||||
|
||||
// 更新目标值
|
||||
cinemachineTargetYaw = yaw;
|
||||
cinemachineTargetPitch = pitch;
|
||||
|
||||
// --- 立即应用旋转 ---
|
||||
// 强制立即更新一次 cameraRoot,防止等待下一帧 Update 产生的跳变
|
||||
viewSc.cameraRoot.rotation = Quaternion.Euler(cinemachineTargetPitch, cinemachineTargetYaw, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user