Advertisement
Guest User

Untitled

a guest
Nov 21st, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. private void PopulateTeamList()
  2. {
  3.  
  4.  
  5. //Button array
  6. teamJoinButtons = new Button[teamList.Count];
  7.  
  8. //Text array
  9. teamNameTexts = new Text[teamList.Count];
  10.  
  11. //Hard referenced prefab trough public gameobject
  12. teamElementTransform = teamElementPrefab.GetComponent<RectTransform>();
  13. //teamListContent is the content child of the scrollview
  14. teamScrollTransform = teamListContent.GetComponent<RectTransform>();
  15.  
  16. int j = 0;
  17. for (int i = 0; i < teamList.Count; i++)
  18. {
  19. j++;
  20.  
  21. //teamElementPrefab is a public GameObject with a reference to a prefab
  22. GameObject newTeamElement = Instantiate(teamElementPrefab, teamScrollTransform) as GameObject;
  23. newTeamElement.transform.SetParent(teamScrollTransform, false);
  24. teamJoinButtons[i] = newTeamElement.GetComponentInChildren<Button>();
  25. teamJoinButtons[i].enabled = true;
  26. teamNameTexts[i] = teamJoinButtons[i].GetComponentInChildren<Text>();
  27. teamNameTexts[i].text = teamList[i].name;
  28. teamNameTexts[i].fontSize = 12;
  29.  
  30. RectTransform rectTransform = newTeamElement.GetComponent<RectTransform>();
  31.  
  32. //float x = -teamScrollTransform.rect.width / 2 * (i % 1);
  33. //float y = teamScrollTransform.rect.height / 2 - 50 * j;
  34. float x = 0;
  35. float y = teamScrollTransform.rect.height / 2 - 50 * j;
  36. rectTransform.offsetMin = new Vector2(x, y);
  37.  
  38. x = rectTransform.offsetMin.x;
  39. y = rectTransform.offsetMin.y;
  40. rectTransform.offsetMax = new Vector2(x, y);
  41.  
  42. -----> teamListContent.GetComponent<RectTransform>().sizeDelta += new Vector2(0, teamScrollTransform.rect.height / 2 - 50); <----
  43. AddTeamButtonListeners(teamJoinButtons[i], teamNameTexts[i].text);
  44.  
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement