Tanoda
ScrollRectLinker.cs
Go to the documentation of this file.
1
3
5{
6 [RequireComponent(typeof(ScrollRect))]
7 [AddComponentMenu("UI/Extensions/ScrollRectLinker")]
8 public class ScrollRectLinker : MonoBehaviour
9 {
10
11 public bool clamp = true;
12
13 [SerializeField]
14 ScrollRect controllingScrollRect = null;
15 ScrollRect scrollRect = null;
16
17 void Awake()
18 {
19 scrollRect = GetComponent<ScrollRect>();
20 if (controllingScrollRect != null)
21 controllingScrollRect.onValueChanged.AddListener(MirrorPos);
22 }
23
24 void MirrorPos(Vector2 scrollPos)
25 {
26
27 if (clamp)
28 scrollRect.normalizedPosition = new Vector2(Mathf.Clamp01(scrollPos.x), Mathf.Clamp01(scrollPos.y));
29 else
30 scrollRect.normalizedPosition = scrollPos;
31 }
32
33 }
34}
Credit Erdener Gonenc - @PixelEnvision.