From 5cfc3da6c0ec60bf9b007ac21b2909adbbcdbf94 Mon Sep 17 00:00:00 2001 From: "Simon (darkside) Jackson" Date: Thu, 22 Oct 2020 01:38:49 +0100 Subject: [PATCH] Added the programmatic capability to change the parent scroll rect on the ScrollConflictManager at runtime. --- .../Utilities/ScrollConflictManager.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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)