Skip to content

Commit

Permalink
Fix an bug where the content zoom out become out of boundary when mov…
Browse files Browse the repository at this point in the history
…ement type is Clamped.

Fixed
- Fix PinchableScrollRect Editor to inherit ScrollRect Editor.
  • Loading branch information
LokoSoloGames committed Apr 18, 2023
1 parent a30b00d commit abfcc51
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ 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.6] - 2023-04-19
### Fixed
- Fix an bug where the content zoom out become out of boundary when movement type is Clamped.
- Fix PinchableScrollRect Editor to inherit ScrollRect Editor.

## [1.0.5] - 2022-12-22
### Fixed
- Fix an incorrect zooming behaviour on ScreenSpace-Camera render mode.
Expand Down
21 changes: 18 additions & 3 deletions Runtime/PinchableScrollRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ protected virtual void Update() {
}

protected override void LateUpdate() {
if (movementType == MovementType.Clamped) {
base.LateUpdate(); // Apply clamp on every update
return;
}

if (isZooming) {
isZooming = false;
this.UpdatePrevData(); // Avoid dragging in next frame produces inaccurate velocity
Expand Down Expand Up @@ -175,8 +180,8 @@ protected virtual void SetContentPivotPosition(Vector2 pivot) {
}

protected virtual void SetContentLocalScale(Vector3 newScale) {
Rect _rect = content.rect;
Rect _viewRect = viewRect.rect;
// Rect _rect = content.rect;
// Rect _viewRect = viewRect.rect;
// bool invalidX = _rect.width * newScale.x < _viewRect.width;
// bool invalidY = _rect.height * newScale.y < _viewRect.height;
// if (invalidX) newScale.x = _viewRect.width / _rect.width;
Expand Down Expand Up @@ -228,7 +233,7 @@ public override void OnEndDrag(PointerEventData eventData) {

#if UNITY_EDITOR
[UnityEditor.CustomEditor(typeof(PinchableScrollRect))]
public class PinchableScrollRectEditor : UnityEditor.Editor {
public class PinchableScrollRectEditor : UnityEditor.UI.ScrollRectEditor {
public override void OnInspectorGUI() {
PinchableScrollRect script = (PinchableScrollRect)target;
if (script.GetComponent<PinchInputDetector>() == null) {
Expand All @@ -238,6 +243,16 @@ public override void OnInspectorGUI() {
}
}
base.OnInspectorGUI();

var flag = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
foreach (var field in typeof(PinchableScrollRect).GetFields(flag)) {
var property = serializedObject.FindProperty(field.Name);
if (property != null) {
UnityEditor.EditorGUILayout.PropertyField(property);
}
}
serializedObject.ApplyModifiedProperties();

var _lowerScale = script.lowerScale;
if (_lowerScale.x < 1f || _lowerScale.y < 1f || _lowerScale.z < 1f) {
UnityEditor.EditorGUILayout.HelpBox("Lower Scale cannot be less than 1", UnityEditor.MessageType.Error);
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.5",
"version": "1.0.6",
"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 abfcc51

Please sign in to comment.