Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public ScrollRect ScrollerRect;
  2. public RectTransform SelectedEntry;
  3.  
  4. void Start()
  5. {
  6. //test the selected entry - remove and add your own selection method.
  7. if (SelectedEntry != null)
  8. ScrollToEntryView(SelectedEntry);//--pass in selected entry and scroll to view
  9. }
  10. void ScrollToEntryView(RectTransform target)
  11. {
  12. float scrollToPos = 0;
  13. float yStartPos = ScrollerRect.content.rect.yMax ;
  14. float entryHeight = 150;
  15. for (int i = 0; i < ScrollerRect.content.childCount; i++)
  16. {
  17. if (SelectedEntry.gameObject.name == ScrollerRect.content.GetChild(i).gameObject.name)
  18. SetScrollContentPoint(scrollToPos);
  19. else
  20. scrollToPos = yStartPos += entryHeight;
  21. }
  22. void SetScrollContentPoint(float yPos)
  23. {
  24. ScrollerRect.content.offsetMax = new Vector2(0,yPos);
  25. //select the element to highlight the entry
  26. EventSystem.current.SetSelectedGameObject(SelectedEntry.gameObject, null);
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement