Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ScrollRect ScrollerRect;
- public RectTransform SelectedEntry;
- void Start()
- {
- //test the selected entry - remove and add your own selection method.
- if (SelectedEntry != null)
- ScrollToEntryView(SelectedEntry);//--pass in selected entry and scroll to view
- }
- void ScrollToEntryView(RectTransform target)
- {
- float scrollToPos = 0;
- float yStartPos = ScrollerRect.content.rect.yMax ;
- float entryHeight = 150;
- for (int i = 0; i < ScrollerRect.content.childCount; i++)
- {
- if (SelectedEntry.gameObject.name == ScrollerRect.content.GetChild(i).gameObject.name)
- SetScrollContentPoint(scrollToPos);
- else
- scrollToPos = yStartPos += entryHeight;
- }
- void SetScrollContentPoint(float yPos)
- {
- ScrollerRect.content.offsetMax = new Vector2(0,yPos);
- //select the element to highlight the entry
- EventSystem.current.SetSelectedGameObject(SelectedEntry.gameObject, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement