Skip to content

Commit abfcc51

Browse files
committed
Fix an bug where the content zoom out become out of boundary when movement type is Clamped.
Fixed - Fix PinchableScrollRect Editor to inherit ScrollRect Editor.
1 parent a30b00d commit abfcc51

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.0.6] - 2023-04-19
8+
### Fixed
9+
- Fix an bug where the content zoom out become out of boundary when movement type is Clamped.
10+
- Fix PinchableScrollRect Editor to inherit ScrollRect Editor.
11+
712
## [1.0.5] - 2022-12-22
813
### Fixed
914
- Fix an incorrect zooming behaviour on ScreenSpace-Camera render mode.

Runtime/PinchableScrollRect.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ protected virtual void Update() {
123123
}
124124

125125
protected override void LateUpdate() {
126+
if (movementType == MovementType.Clamped) {
127+
base.LateUpdate(); // Apply clamp on every update
128+
return;
129+
}
130+
126131
if (isZooming) {
127132
isZooming = false;
128133
this.UpdatePrevData(); // Avoid dragging in next frame produces inaccurate velocity
@@ -175,8 +180,8 @@ protected virtual void SetContentPivotPosition(Vector2 pivot) {
175180
}
176181

177182
protected virtual void SetContentLocalScale(Vector3 newScale) {
178-
Rect _rect = content.rect;
179-
Rect _viewRect = viewRect.rect;
183+
// Rect _rect = content.rect;
184+
// Rect _viewRect = viewRect.rect;
180185
// bool invalidX = _rect.width * newScale.x < _viewRect.width;
181186
// bool invalidY = _rect.height * newScale.y < _viewRect.height;
182187
// if (invalidX) newScale.x = _viewRect.width / _rect.width;
@@ -228,7 +233,7 @@ public override void OnEndDrag(PointerEventData eventData) {
228233

229234
#if UNITY_EDITOR
230235
[UnityEditor.CustomEditor(typeof(PinchableScrollRect))]
231-
public class PinchableScrollRectEditor : UnityEditor.Editor {
236+
public class PinchableScrollRectEditor : UnityEditor.UI.ScrollRectEditor {
232237
public override void OnInspectorGUI() {
233238
PinchableScrollRect script = (PinchableScrollRect)target;
234239
if (script.GetComponent<PinchInputDetector>() == null) {
@@ -238,6 +243,16 @@ public override void OnInspectorGUI() {
238243
}
239244
}
240245
base.OnInspectorGUI();
246+
247+
var flag = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
248+
foreach (var field in typeof(PinchableScrollRect).GetFields(flag)) {
249+
var property = serializedObject.FindProperty(field.Name);
250+
if (property != null) {
251+
UnityEditor.EditorGUILayout.PropertyField(property);
252+
}
253+
}
254+
serializedObject.ApplyModifiedProperties();
255+
241256
var _lowerScale = script.lowerScale;
242257
if (_lowerScale.x < 1f || _lowerScale.y < 1f || _lowerScale.z < 1f) {
243258
UnityEditor.EditorGUILayout.HelpBox("Lower Scale cannot be less than 1", UnityEditor.MessageType.Error);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.lokosolo.pinchable-scrollrect",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"displayName": "Pinchable ScrollRect",
55
"description": "Pinchable ScrollRect allows users to zoom in and out on the ScrollRect with both touches pinching input or mouse scroll input.",
66
"unity": "2018.4",

0 commit comments

Comments
 (0)