Skip to content

Commit

Permalink
Fix an incorrect zooming behaviour on ScreenSpace-Camera & WorldSpace…
Browse files Browse the repository at this point in the history
… render mode
  • Loading branch information
LokoSoloGames committed Sep 15, 2022
1 parent f931396 commit 75d60d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.4] - 2022-09-15
### Fixed
- Fix an incorrect zooming behaviour on ScreenSpace-Camera & WorldSpace render mode.

## [1.0.3] - 2022-08-20
### Fixed
- Fix an incorrect zooming behaviour with Canvas Scalar.
Expand Down
15 changes: 14 additions & 1 deletion Runtime/PinchableScrollRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,24 @@ protected virtual void HandleZoom(float zoomValue) {
Mathf.Clamp(newScale.z, lowerScale.z, upperScale.z));
this.SetContentLocalScale(newScale);
// The world position should remain the same
content.position = _worldPos + (Vector3)pixelDelta * _canvas.scaleFactor; // compensate for value due to pivot change
content.position = _worldPos + (Vector3)pixelDelta * getScaleFactor(); // compensate for value due to pivot change
// Reset delta since zooming deceleration take place at the same pivot
zoomPosDelta = Vector2.zero;
}

float getScaleFactor() {
switch (_canvas.renderMode) {
case RenderMode.ScreenSpaceOverlay:
return _canvas.scaleFactor;
case RenderMode.ScreenSpaceCamera:
return _canvas.scaleFactor / _canvas.referencePixelsPerUnit;
case RenderMode.WorldSpace:
return _canvas.transform.localScale.x;
default:
throw new ArgumentOutOfRangeException();
}
}

protected virtual void SetContentPivotPosition(Vector2 pivot) {
Vector2 _pivot = content.pivot;
if (!this.horizontal) pivot.x = _pivot.x;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.lokosolo.pinchable-scrollrect",
"version": "1.0.3",
"version": "1.0.4",
"displayName": "Pinchable ScrollRect",
"description": "Pinchable ScrollRect allows users to zoom in and out on the ScrollRect with both touches pinching input or mouse scroll input.",
"unity": "2018.4",
Expand Down

0 comments on commit 75d60d0

Please sign in to comment.