SHARE
TWEET

Untitled

a guest Jul 18th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top