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