Merged in fix/ScrollSnapEvents (pull request #96)
Resolve event issues with the H&S ScrollSnap controlspull/413/head
commit
69fd735e65
|
@ -27,7 +27,7 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
updated = false;
|
||||
|
||||
if (!_lerp && _scroll_rect.velocity == Vector2.zero)
|
||||
if (!_lerp && (_scroll_rect.velocity == Vector2.zero && _scroll_rect.inertia))
|
||||
{
|
||||
if (!_settled && !_pointerDown)
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ namespace UnityEngine.UI.Extensions
|
|||
else if (_lerp)
|
||||
{
|
||||
_screensContainer.anchoredPosition = Vector3.Lerp(_screensContainer.anchoredPosition, _lerp_target, transitionSpeed * (UseTimeScale ? Time.deltaTime : Time.unscaledDeltaTime));
|
||||
if (Vector3.Distance(_screensContainer.anchoredPosition, _lerp_target) < 0.1f)
|
||||
if (Vector3.Distance(_screensContainer.anchoredPosition, _lerp_target) < 0.2f)
|
||||
{
|
||||
_screensContainer.anchoredPosition = _lerp_target;
|
||||
_lerp = false;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
using System;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
|
@ -30,11 +31,13 @@ namespace UnityEngine.UI.Extensions
|
|||
internal int _currentPage;
|
||||
internal int _previousPage;
|
||||
internal int _halfNoVisibleItems;
|
||||
internal bool _moveStarted;
|
||||
internal bool _isInfinite; // Is a UI Infinite scroller attached to the control
|
||||
internal int _infiniteWindow; // The infinite window the control is in
|
||||
internal float _infiniteOffset; // How much to offset a repositioning
|
||||
private int _bottomItem, _topItem;
|
||||
private int _bottomItem, _topItem;
|
||||
internal bool _startEventCalled = false;
|
||||
internal bool _endEventCalled = false;
|
||||
internal bool _suspendEvents = false;
|
||||
|
||||
[Serializable]
|
||||
public class SelectionChangeStartEvent : UnityEvent { }
|
||||
|
@ -443,14 +446,16 @@ namespace UnityEngine.UI.Extensions
|
|||
private void ChangeBulletsInfo(int targetScreen)
|
||||
{
|
||||
if (Pagination)
|
||||
{
|
||||
for (int i = 0; i < Pagination.transform.childCount; i++)
|
||||
{
|
||||
Pagination.transform.GetChild(i).GetComponent<Toggle>().isOn = (targetScreen == i)
|
||||
? true
|
||||
: false;
|
||||
Pagination.transform.GetChild(i).GetComponent<Toggle>().isOn = (targetScreen == i) ? true : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make a lock function for pagination, to prevent event leaking
|
||||
|
||||
/// <summary>
|
||||
/// disables the page navigation buttons when at the first or last screen
|
||||
/// </summary>
|
||||
|
@ -531,9 +536,12 @@ namespace UnityEngine.UI.Extensions
|
|||
/// </summary>
|
||||
public void StartScreenChange()
|
||||
{
|
||||
if (!_moveStarted)
|
||||
if (!_startEventCalled)
|
||||
{
|
||||
_moveStarted = true;
|
||||
_suspendEvents = true;
|
||||
|
||||
_startEventCalled = true;
|
||||
_endEventCalled = false;
|
||||
OnSelectionChangeStartEvent.Invoke();
|
||||
}
|
||||
}
|
||||
|
@ -551,9 +559,15 @@ namespace UnityEngine.UI.Extensions
|
|||
/// </summary>
|
||||
internal void EndScreenChange()
|
||||
{
|
||||
OnSelectionChangeEndEvent.Invoke(_currentPage);
|
||||
_settled = true;
|
||||
_moveStarted = false;
|
||||
if (!_endEventCalled)
|
||||
{
|
||||
_suspendEvents = false;
|
||||
|
||||
_endEventCalled = true;
|
||||
_startEventCalled = false;
|
||||
_settled = true;
|
||||
OnSelectionChangeEndEvent.Invoke(_currentPage);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -228,10 +228,13 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
InitialiseChildObjectsFromScene();
|
||||
DistributePages();
|
||||
if (MaskArea) UpdateVisible();
|
||||
if (MaskArea)
|
||||
UpdateVisible();
|
||||
|
||||
if (JumpOnEnable || !RestartOnEnable) SetScrollContainerPosition();
|
||||
if(RestartOnEnable) GoToScreen(StartingScreen);
|
||||
if (JumpOnEnable || !RestartOnEnable)
|
||||
SetScrollContainerPosition();
|
||||
if (RestartOnEnable)
|
||||
GoToScreen(StartingScreen);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
for (int i = 0; i < m_PaginationChildren.Count; i++)
|
||||
{
|
||||
if (m_PaginationChildren[i].isOn)
|
||||
if (m_PaginationChildren[i].isOn && !scrollSnap._suspendEvents)
|
||||
{
|
||||
GoToScreen(i);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue