Merged in fix/NextPreviousScrollsnapFix (pull request #133)

Scroll Snap buttons fix
pull/413/head
Simon Jackson 2022-04-23 20:02:37 +00:00
commit 5bd7df19e1
3 changed files with 28 additions and 8 deletions

View File

@ -5,6 +5,7 @@
using System; using System;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI.Extensions;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
@ -314,6 +315,8 @@ namespace UnityEngine.UI.Extensions
//Function for switching screens with buttons //Function for switching screens with buttons
public void NextScreen() public void NextScreen()
{ {
_scroll_rect.velocity = Vector2.zero;
if (_currentPage < _screens - 1 || _isInfinite) if (_currentPage < _screens - 1 || _isInfinite)
{ {
if (!_lerp) StartScreenChange(); if (!_lerp) StartScreenChange();
@ -336,6 +339,8 @@ namespace UnityEngine.UI.Extensions
//Function for switching screens with buttons //Function for switching screens with buttons
public void PreviousScreen() public void PreviousScreen()
{ {
_scroll_rect.velocity = Vector2.zero;
if (_currentPage > 0 || _isInfinite) if (_currentPage > 0 || _isInfinite)
{ {
if (!_lerp) StartScreenChange(); if (!_lerp) StartScreenChange();
@ -515,15 +520,8 @@ namespace UnityEngine.UI.Extensions
MaskBuffer = 1; MaskBuffer = 1;
} }
if (PageStep < 0) PageStep.Clamp(0, 9);
{
PageStep = 0;
}
if (PageStep > 8)
{
PageStep = 9;
}
var infiniteScroll = GetComponent<UI_InfiniteScroll>(); var infiniteScroll = GetComponent<UI_InfiniteScroll>();
if (ChildObjects != null && ChildObjects.Length > 0 && infiniteScroll != null && !infiniteScroll.InitByUser) if (ChildObjects != null && ChildObjects.Length > 0 && infiniteScroll != null && !infiniteScroll.InitByUser)
{ {

View File

@ -29,5 +29,27 @@ namespace UnityEngine.UI.Extensions
!gameObject.hideFlags.HasFlag(HideFlags.HideInHierarchy); !gameObject.hideFlags.HasFlag(HideFlags.HideInHierarchy);
// I don't care about GameObjects *inside* prefabs, just the overall prefab. // I don't care about GameObjects *inside* prefabs, just the overall prefab.
} }
/// <summary>
/// Generic clamp method to limt a value between a range of values
/// </summary>
/// <typeparam name="T"><see cref="IComparable"/> data type</typeparam>
/// <param name="value">Value to clamp</param>
/// <param name="min">Minimum value</param>
/// <param name="max">Maximum value</param>
/// <returns></returns>
public static T Clamp<T>(this T value, T min, T max) where T : IComparable<T>
{
if (value.CompareTo(min) < 0)
{
value = min;
}
if (value.CompareTo(max) > 0)
{
value = max;
}
return value;
}
} }
} }