fix(fix-system): 修复维修场景鼠标视差偏移
This commit is contained in:
@@ -183,12 +183,25 @@ namespace AibisDream
|
||||
Vector3 worldMousePosition = cameraForInput.ScreenToWorldPoint(mousePosition);
|
||||
worldMousePosition.z = 0;
|
||||
|
||||
// 视差锚点用 initialPosition,避免相机跟随平移后 delta 被抵消
|
||||
Vector3 parallaxAnchor = UsesCinemachinePan ? initialPosition : ViewPosition;
|
||||
parallaxAnchor.z = 0;
|
||||
Vector3 delta = UsesCinemachinePan
|
||||
? worldMousePosition - parallaxAnchor
|
||||
: parallaxAnchor - worldMousePosition;
|
||||
Vector3 delta;
|
||||
if (UsesCinemachinePan)
|
||||
{
|
||||
// 只使用鼠标相对视口中心的偏移,避免将相机自身的平移重复计入视差。
|
||||
Vector3 screenCenter = new(
|
||||
cameraForInput.pixelRect.center.x,
|
||||
cameraForInput.pixelRect.center.y,
|
||||
mousePosition.z);
|
||||
Vector3 worldScreenCenter = cameraForInput.ScreenToWorldPoint(screenCenter);
|
||||
worldScreenCenter.z = 0;
|
||||
delta = worldMousePosition - worldScreenCenter;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3 parallaxAnchor = ViewPosition;
|
||||
parallaxAnchor.z = 0;
|
||||
delta = parallaxAnchor - worldMousePosition;
|
||||
}
|
||||
|
||||
Vector3 targetOffset = delta * parallaxEffectMultiplier;
|
||||
targetOffset.x = Mathf.Clamp(targetOffset.x, -maxOffset.x, maxOffset.x);
|
||||
targetOffset.y = Mathf.Clamp(targetOffset.y, -maxOffset.y, maxOffset.y);
|
||||
@@ -198,13 +211,11 @@ namespace AibisDream
|
||||
Vector3 targetPosition = initialPosition + currentOffset;
|
||||
if (UsesCinemachinePan)
|
||||
{
|
||||
Vector2 parallaxSlack = maxOffset * parallaxEffectMultiplier;
|
||||
targetPosition = ClampFocusPositionWithSlack(
|
||||
targetPosition = ClampFocusPosition(
|
||||
targetPosition,
|
||||
worldRegionMin,
|
||||
worldRegionMax,
|
||||
GetViewportSize(),
|
||||
parallaxSlack);
|
||||
GetViewportSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -323,34 +334,6 @@ namespace AibisDream
|
||||
return new Vector2(height * cam.aspect, height);
|
||||
}
|
||||
|
||||
private static Vector3 ClampFocusPositionWithSlack(
|
||||
Vector3 targetPosition,
|
||||
Vector2 minBounds,
|
||||
Vector2 maxBounds,
|
||||
Vector2 viewportSize,
|
||||
Vector2 slack)
|
||||
{
|
||||
if (maxBounds.x > minBounds.x)
|
||||
{
|
||||
float halfWidth = Mathf.Max(0f, viewportSize.x * 0.5f);
|
||||
targetPosition.x = Mathf.Clamp(
|
||||
targetPosition.x,
|
||||
minBounds.x + halfWidth - slack.x,
|
||||
maxBounds.x - halfWidth + slack.x);
|
||||
}
|
||||
|
||||
if (maxBounds.y > minBounds.y)
|
||||
{
|
||||
float halfHeight = Mathf.Max(0f, viewportSize.y * 0.5f);
|
||||
targetPosition.y = Mathf.Clamp(
|
||||
targetPosition.y,
|
||||
minBounds.y + halfHeight - slack.y,
|
||||
maxBounds.y - halfHeight + slack.y);
|
||||
}
|
||||
|
||||
return targetPosition;
|
||||
}
|
||||
|
||||
private static Vector3 ClampFocusPosition(Vector3 targetPosition, Vector2 minBounds, Vector2 maxBounds, Vector2 viewportSize)
|
||||
{
|
||||
if (maxBounds.x > minBounds.x)
|
||||
|
||||
Reference in New Issue
Block a user