diff --git a/Runtime/Scripts/Utilities/ScrollConflictManager.cs b/Runtime/Scripts/Utilities/ScrollConflictManager.cs index c66788d..e202a72 100644 --- a/Runtime/Scripts/Utilities/ScrollConflictManager.cs +++ b/Runtime/Scripts/Utilities/ScrollConflictManager.cs @@ -18,7 +18,7 @@ namespace UnityEngine.UI.Extensions public ScrollRect ParentScrollRect; [Tooltip("The parent ScrollSnap control hosting this Scroll Snap.\nIf left empty, it will use the ScrollSnap of the ParentScrollRect")] - public ScrollSnapBase ParentScrollSnap; + private ScrollSnapBase ParentScrollSnap; private ScrollRect _myScrollRect; private IBeginDragHandler[] _beginDragHandlers; @@ -30,6 +30,14 @@ namespace UnityEngine.UI.Extensions private bool scrollOtherHorizontally; void Awake() + { + if (ParentScrollRect) + { + InitialiseConflictManager(); + } + } + + private void InitialiseConflictManager() { //Get the current scroll rect so we can disable it if the other one is scrolling _myScrollRect = this.GetComponent(); @@ -55,12 +63,27 @@ namespace UnityEngine.UI.Extensions } void Start() + { + if (ParentScrollRect) + { + AssignScrollRectHandlers(); + } + } + + private void AssignScrollRectHandlers() { _beginDragHandlers = ParentScrollRect.GetComponents(); _dragHandlers = ParentScrollRect.GetComponents(); _endDragHandlers = ParentScrollRect.GetComponents(); } + public void SetParentScrollRect(ScrollRect parentScrollRect) + { + ParentScrollRect = parentScrollRect; + InitialiseConflictManager(); + AssignScrollRectHandlers(); + } + #region DragHandler public void OnBeginDrag(PointerEventData eventData)