diff --git a/Runtime/Scripts/Layout/ScrollSnapBase.cs b/Runtime/Scripts/Layout/ScrollSnapBase.cs index d200bef..3ffcb3b 100644 --- a/Runtime/Scripts/Layout/ScrollSnapBase.cs +++ b/Runtime/Scripts/Layout/ScrollSnapBase.cs @@ -35,6 +35,10 @@ namespace UnityEngine.UI.Extensions internal bool _endEventCalled = false; internal bool _suspendEvents = false; + // Events + [SerializeField] + private UnityEvent onTransitionEffects = new UnityEvent(); + [Serializable] public class SelectionChangeStartEvent : UnityEvent { } [Serializable] @@ -300,11 +304,11 @@ namespace UnityEngine.UI.Extensions Debug.Log("Failed to setactive child [" + i + "]"); } } - //Deactivate items out of visibility at the bottom of the ScrollRect Mask (only on scroll) if (_currentPage > _halfNoVisibleItems) ChildObjects[CurrentPage - _bottomItem].SetActive(false); //Deactivate items out of visibility at the top of the ScrollRect Mask (only on scroll) if (_screensContainer.childCount - _currentPage > _topItem) ChildObjects[CurrentPage + _topItem].SetActive(false); + } //Function for switching screens with buttons @@ -642,5 +646,30 @@ namespace UnityEngine.UI.Extensions } #endregion + + #region Transition Effects + + private Vector2 GetDisplacementFromCenter(int index) + { + return _screensContainer.GetChild(index).GetComponent().position - _scroll_rect.viewport.transform.position; + } + + private void HandleTransitionEffects() + { + if (onTransitionEffects.GetPersistentEventCount() == 0) return; + + for (int i = 0; i < _screensContainer.childCount; i++) + { + Vector2 displacement = GetDisplacementFromCenter(i); + float d = (_scroll_rect.horizontal ? displacement.x : displacement.y); + onTransitionEffects.Invoke(_screensContainer.GetChild(i).gameObject, d); + } + } + + protected virtual void Update() + { + HandleTransitionEffects(); + } + #endregion } } \ No newline at end of file