13 [RequireComponent(typeof(ScrollRect))]
14 [AddComponentMenu(
"UI/Extensions/Scrollrect Conflict Manager")]
17 [Tooltip(
"The parent ScrollRect control hosting this ScrollSnap")]
20 [Tooltip(
"The parent ScrollSnap control hosting this Scroll Snap.\nIf left empty, it will use the ScrollSnap of the ParentScrollRect")]
23 private ScrollRect _myScrollRect;
24 private IBeginDragHandler[] _beginDragHandlers;
25 private IEndDragHandler[] _endDragHandlers;
26 private IDragHandler[] _dragHandlers;
28 private bool scrollOther;
30 private bool scrollOtherHorizontally;
35 _myScrollRect = this.GetComponent<ScrollRect>();
37 scrollOtherHorizontally = _myScrollRect.vertical;
39 if (scrollOtherHorizontally)
41 if (_myScrollRect.horizontal)
42 Debug.LogError(
"You have added the SecondScrollRect to a scroll view that already has both directions selected");
44 Debug.LogError(
"The other scroll rect does not support scrolling horizontally");
48 Debug.LogError(
"The other scroll rect does not support scrolling vertically");
69 float horizontal = Mathf.Abs(eventData.position.x - eventData.pressPosition.x);
70 float vertical = Mathf.Abs(eventData.position.y - eventData.pressPosition.y);
71 if (scrollOtherHorizontally)
73 if (horizontal > vertical)
77 _myScrollRect.enabled =
false;
78 for (
int i = 0, length = _beginDragHandlers.Length; i < length; i++)
80 _beginDragHandlers[i].OnBeginDrag(eventData);
85 else if (vertical > horizontal)
89 _myScrollRect.enabled =
false;
90 for (
int i = 0, length = _beginDragHandlers.Length; i < length; i++)
92 _beginDragHandlers[i].OnBeginDrag(eventData);
102 _myScrollRect.enabled =
true;
104 for (
int i = 0, length = _endDragHandlers.Length; i < length; i++)
106 _endDragHandlers[i].OnEndDrag(eventData);
112 public void OnDrag(PointerEventData eventData)
116 for (
int i = 0, length = _endDragHandlers.Length; i < length; i++)
118 _dragHandlers[i].OnDrag(eventData);
124 #endregion DragHandler
Credit Erdener Gonenc - @PixelEnvision.