Adopts changes proposed in #150 ScrollTo now works with Pivot

Resolves #150
release
Simon Jackson 2017-07-02 14:43:10 +01:00
parent f49c8564ac
commit 50c41198db
1 changed files with 6 additions and 6 deletions

View File

@ -1,11 +1,11 @@
using System.Collections.Generic; /// Credit zero3growlithe
/// Credit zero3growlithe
/// sourced from: http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-2011648 /// sourced from: http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-2011648
/*USAGE: /*USAGE:
Simply place the script on the ScrollRect that contains the selectable children we'll be scroling to Simply place the script on the ScrollRect that contains the selectable children we'll be scroling to
and drag'n'drop the RectTransform of the options "container" that we'll be scrolling.*/ and drag'n'drop the RectTransform of the options "container" that we'll be scrolling.*/
using System.Collections.Generic;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
@ -170,7 +170,7 @@ namespace UnityEngine.UI.Extensions
private void UpdateVerticalScrollPosition(RectTransform selection) private void UpdateVerticalScrollPosition(RectTransform selection)
{ {
// move the current scroll rect to correct position // move the current scroll rect to correct position
float selectionPosition = -selection.anchoredPosition.y; float selectionPosition = -selection.anchoredPosition.y - (selection.rect.height * (1 - selection.pivot.y));
float elementHeight = selection.rect.height; float elementHeight = selection.rect.height;
float maskHeight = ScrollWindow.rect.height; float maskHeight = ScrollWindow.rect.height;
@ -181,13 +181,13 @@ namespace UnityEngine.UI.Extensions
// move the target scroll rect // move the target scroll rect
TargetScrollRect.verticalNormalizedPosition += TargetScrollRect.verticalNormalizedPosition +=
(offlimitsValue / LayoutListGroup.rect.height) * Time.deltaTime * scrollSpeed; (offlimitsValue / LayoutListGroup.rect.height) * Time.unscaledDeltaTime * scrollSpeed;
} }
private void UpdateHorizontalScrollPosition(RectTransform selection) private void UpdateHorizontalScrollPosition(RectTransform selection)
{ {
// move the current scroll rect to correct position // move the current scroll rect to correct position
float selectionPosition = selection.anchoredPosition.x; float selectionPosition = -selection.anchoredPosition.x - (selection.rect.width * (1 - selection.pivot.x));
float elementWidth = selection.rect.width; float elementWidth = selection.rect.width;
float maskWidth = ScrollWindow.rect.width; float maskWidth = ScrollWindow.rect.width;
@ -198,7 +198,7 @@ namespace UnityEngine.UI.Extensions
// move the target scroll rect // move the target scroll rect
TargetScrollRect.horizontalNormalizedPosition += TargetScrollRect.horizontalNormalizedPosition +=
(offlimitsValue / LayoutListGroup.rect.width) * Time.deltaTime * scrollSpeed; (offlimitsValue / LayoutListGroup.rect.width) * Time.unscaledDeltaTime * scrollSpeed;
} }
private float GetScrollOffset(float position, float listAnchorPosition, float targetLength, float maskLength) private float GetScrollOffset(float position, float listAnchorPosition, float targetLength, float maskLength)