Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void PopulateTeamList()
- {
- //Button array
- teamJoinButtons = new Button[teamList.Count];
- //Text array
- teamNameTexts = new Text[teamList.Count];
- //Hard referenced prefab trough public gameobject
- teamElementTransform = teamElementPrefab.GetComponent<RectTransform>();
- //teamListContent is the content child of the scrollview
- teamScrollTransform = teamListContent.GetComponent<RectTransform>();
- int j = 0;
- for (int i = 0; i < teamList.Count; i++)
- {
- j++;
- //teamElementPrefab is a public GameObject with a reference to a prefab
- GameObject newTeamElement = Instantiate(teamElementPrefab, teamScrollTransform) as GameObject;
- newTeamElement.transform.SetParent(teamScrollTransform, false);
- teamJoinButtons[i] = newTeamElement.GetComponentInChildren<Button>();
- teamJoinButtons[i].enabled = true;
- teamNameTexts[i] = teamJoinButtons[i].GetComponentInChildren<Text>();
- teamNameTexts[i].text = teamList[i].name;
- teamNameTexts[i].fontSize = 12;
- RectTransform rectTransform = newTeamElement.GetComponent<RectTransform>();
- //float x = -teamScrollTransform.rect.width / 2 * (i % 1);
- //float y = teamScrollTransform.rect.height / 2 - 50 * j;
- float x = 0;
- float y = teamScrollTransform.rect.height / 2 - 50 * j;
- rectTransform.offsetMin = new Vector2(x, y);
- x = rectTransform.offsetMin.x;
- y = rectTransform.offsetMin.y;
- rectTransform.offsetMax = new Vector2(x, y);
- -----> teamListContent.GetComponent<RectTransform>().sizeDelta += new Vector2(0, teamScrollTransform.rect.height / 2 - 50); <----
- AddTeamButtonListeners(teamJoinButtons[i], teamNameTexts[i].text);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement