public void CreateComponentList() { if (currentComponentButtons.Count > 0) { foreach (Button button in currentComponentButtons) { Destroy(button.gameObject); } currentComponentButtons.Clear(); } Dispensary dispensary = GameObject.Find("DispensaryManager").GetComponent <DispensaryManager>().dispensary; string[] allComponents = dispensary.GetIndoorComponents(); float selectionPanelHeight = selectComponentPanel.rectTransform.rect.height; float titlePanelHeight = selectComponentTitlePanel.GetComponent <Image>().rectTransform.rect.height; float buttonHeight = selectComponentButtonPrefab.image.rectTransform.rect.height; int counter = 0; /*int allComponentsSize = allComponents.Length; * string[] tempArray = new string[allComponentsSize + 7]; * int counter2 = 0; * foreach (string str in allComponents) * { * tempArray[counter2] = str; * counter2++; * } * tempArray[2] = "dummy button 1"; * tempArray[3] = "dummy button 2"; * tempArray[4] = "dummy button 3"; * tempArray[5] = "dummy button 4"; * tempArray[6] = "dummy button 5"; * tempArray[7] = "dummy button 6"; * tempArray[8] = "dummy button 7";*/ foreach (string component in /*tempArray*/ allComponents) { Button newButton = Instantiate(selectComponentButtonPrefab) as Button; newButton.gameObject.SetActive(true); newButton.transform.SetParent(selectComponentButtonPrefab.transform.parent, false); newButton.image.rectTransform.anchoredPosition = new Vector2(0, buttonHeight * -counter); newButton.onClick.AddListener(() => selector.SelectComponent(dm.GetComponentGrid(component), true)); Text[] buttonText = newButton.GetComponentsInChildren <Text>(); buttonText[0].text = component; currentComponentButtons.Add(newButton); counter++; } /*print("Bar height before: " + bar.rectTransform.rect.height); * float newBarHeight = titlePanelHeight + ((counter + 1) * buttonHeight); * bar.rectTransform.sizeDelta = new Vector2(0, -newBarHeight); * bar.rectTransform.anchoredPosition = new Vector2(0, newBarHeight/2); * print("Bar height after: " + bar.rectTransform.rect.height);*/ /* if (counter == 1) * { * bar.transform.localScale = new Vector3(1, 1, 1); * } * else if (counter == 2) * { * bar.transform.localScale = new Vector3(1, 1.5f, 1); * } * else if (counter > 2) * { * bar.transform.localScale = new Vector3(1, 1.5f + (.5f * counter), 1); * }*/ RectTransform barRectTransform = selectComponentPanelBar.GetComponent <RectTransform>(); barRectTransform.offsetMin = new Vector2(barRectTransform.offsetMax.x, selectionPanelHeight - (buttonHeight * (counter + 1.25f))); barRectTransform.offsetMax = new Vector2(barRectTransform.offsetMax.x, 0); }