public MenuButton InstantiateMenuButton(GameObject _parentButtonContainerGO, ButtonContainer _parentButtonContainerScript, Transform _buttonContainerTransform) { GameObject newMenuButtonGO = Instantiate(prefabMenuButton); MenuButton newMenuButtonScript = newMenuButtonGO.GetComponent <MenuButton>(); Button newMenuButtonUnityButtonScript = newMenuButtonGO.GetComponent <Button>(); newMenuButtonScript.unityButtonScript = newMenuButtonUnityButtonScript; newMenuButtonUnityButtonScript.onClick.AddListener(HandleMenuButtonClick); RectTransform newMenuButtonRectTransform = newMenuButtonGO.GetComponent <Image>().rectTransform; newMenuButtonScript.rectTransformScript = newMenuButtonRectTransform; newMenuButtonRectTransform.sizeDelta = _parentButtonContainerScript.buttonDimensions; newMenuButtonGO.GetComponent <Transform>().SetParent(_buttonContainerTransform); return(newMenuButtonScript); }
public ButtonContainer InitButtonContainer(GameObject _buttonContainerGO, Transform _buttonContainerTransform) { ButtonContainer curButtonContainerScript = _buttonContainerGO.GetComponent <ButtonContainer>(); int buttonsToCreateCount = 0; List <MenuButton> newMenuButtonScripts = new List <MenuButton>(); // set amount of buttons to create based on a condition of what these buttons will represent if (curButtonContainerScript.buttonContainerType == ButtonContainerType.playerToolsInShop) { foreach (Tool curTool in GameManager.singleton.playerAllTools) { MenuButton newMenuButtonScript = InstantiateMenuButton(_buttonContainerGO, curButtonContainerScript, _buttonContainerTransform); newMenuButtonScript.menuButtonType = MenuButtonType.item; newMenuButtonScript.representedToolScript = curTool; newMenuButtonScripts.Add(newMenuButtonScript); } } curButtonContainerScript.childMenuButtonScripts = newMenuButtonScripts; return(curButtonContainerScript); }