修复双击导致镜头跳动

This commit is contained in:
shenjianxing 2025-03-26 16:27:45 +08:00
parent 2f3ba8bb5e
commit dd3460dae1

View File

@ -27,7 +27,7 @@ public class Show3DCamera : MonoBehaviour
public RenderTexture texture;
public bool lockMove = false;
private const float DRAG_THRESHOLD = 1f; // 拖拽阈值
private Vector2 mouseDownPosition; // 记录鼠标按下时的位置
@ -162,10 +162,17 @@ public class Show3DCamera : MonoBehaviour
mouseDownPosition = Input.mousePosition;
}
// 修改后的旋转条件(排除缩放状态)
if (!isZooming && (isTouching ? (Input.GetTouch(0).phase == TouchPhase.Moved) : Input.GetMouseButton(0)))
bool shouldRotate = false;
if (Input.GetMouseButton(0))
{
// 移除距离判断直接响应
// 使用现有参数计算拖拽距离
float dragDistance = Vector2.Distance(Input.mousePosition, mouseDownPosition);
shouldRotate = dragDistance > DRAG_THRESHOLD;
}
// 修改后的旋转条件(排除缩放状态)
if (!isZooming && (isTouching ? (Input.GetTouch(0).phase == TouchPhase.Moved) : shouldRotate))
{
RotateCamera();
}
@ -322,7 +329,6 @@ public class Show3DCamera : MonoBehaviour
/// </summary>
public void FocusObj(Vector3 target, float distance = 1f, float moveTime = -1)
{
// 计算相机前方一定距离的位置作为Cube的目标位置
// 可以根据需要调整这个距离
Vector3 cameraPos = target - transform.forward * distance;
@ -398,6 +404,9 @@ public class Show3DCamera : MonoBehaviour
{
deltaX = Input.GetAxis("Mouse X") * 10; // 保持原有灵敏度
deltaY = Input.GetAxis("Mouse Y") * 10;
// 当累计移动量超过阈值时才生效
if (Mathf.Abs(deltaX) < DRAG_THRESHOLD && Mathf.Abs(deltaY) < DRAG_THRESHOLD)
return;
}
// 应用DPI缩放关键