Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 5cfc3da

Browse files
Added the programmatic capability to change the parent scroll rect on the ScrollConflictManager at runtime.
1 parent 184954e commit 5cfc3da

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Runtime/Scripts/Utilities/ScrollConflictManager.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ScrollConflictManager : MonoBehaviour, IBeginDragHandler, IEndDragH
1818
public ScrollRect ParentScrollRect;
1919

2020
[Tooltip("The parent ScrollSnap control hosting this Scroll Snap.\nIf left empty, it will use the ScrollSnap of the ParentScrollRect")]
21-
public ScrollSnapBase ParentScrollSnap;
21+
private ScrollSnapBase ParentScrollSnap;
2222

2323
private ScrollRect _myScrollRect;
2424
private IBeginDragHandler[] _beginDragHandlers;
@@ -30,6 +30,14 @@ public class ScrollConflictManager : MonoBehaviour, IBeginDragHandler, IEndDragH
3030
private bool scrollOtherHorizontally;
3131

3232
void Awake()
33+
{
34+
if (ParentScrollRect)
35+
{
36+
InitialiseConflictManager();
37+
}
38+
}
39+
40+
private void InitialiseConflictManager()
3341
{
3442
//Get the current scroll rect so we can disable it if the other one is scrolling
3543
_myScrollRect = this.GetComponent<ScrollRect>();
@@ -55,12 +63,27 @@ void Awake()
5563
}
5664

5765
void Start()
66+
{
67+
if (ParentScrollRect)
68+
{
69+
AssignScrollRectHandlers();
70+
}
71+
}
72+
73+
private void AssignScrollRectHandlers()
5874
{
5975
_beginDragHandlers = ParentScrollRect.GetComponents<IBeginDragHandler>();
6076
_dragHandlers = ParentScrollRect.GetComponents<IDragHandler>();
6177
_endDragHandlers = ParentScrollRect.GetComponents<IEndDragHandler>();
6278
}
6379

80+
public void SetParentScrollRect(ScrollRect parentScrollRect)
81+
{
82+
ParentScrollRect = parentScrollRect;
83+
InitialiseConflictManager();
84+
AssignScrollRectHandlers();
85+
}
86+
6487
#region DragHandler
6588

6689
public void OnBeginDrag(PointerEventData eventData)

0 commit comments

Comments
 (0)