void printdData(PlayerInformation data) { /* * GameObject textObject = new GameObject("Text"); * textObject.transform.parent = panel.transform; * Text text = textObject.AddComponent<Text>(); * * text.text = data.name + "\n" + "Score: " + data.score; * text.color = Color.black; * * Font ArialFont = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf"); * text.font = ArialFont; * text.material = ArialFont.material; * text.alignment = TextAnchor.MiddleCenter; */ GameObject buttonObject = new GameObject("Button"); CanvasRenderer canvasRenderer = buttonObject.AddComponent <CanvasRenderer>(); Image image = buttonObject.AddComponent <Image>(); Button button = buttonObject.AddComponent <Button>(); buttonObject.transform.parent = panel.transform; VerticalLayoutGroup layout = buttonObject.AddComponent <VerticalLayoutGroup>(); layout.childControlWidth = true; layout.childControlHeight = true; layout.childForceExpandHeight = true; layout.childForceExpandWidth = true; ColorBlock cb = button.colors; cb.selectedColor = Color.yellow; button.colors = cb; PlayerSaveData saveFile = buttonObject.AddComponent <PlayerSaveData>(); saveFile.AddData(data); button.onClick.AddListener(saveFile.OnClickLeaderBoard); GameObject textObject = new GameObject("Text"); textObject.transform.parent = buttonObject.transform; Text text = textObject.AddComponent <Text>(); text.text = data.name + "\n" + "Score: " + data.score; text.color = Color.black; Font ArialFont = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf"); text.font = ArialFont; text.material = ArialFont.material; text.alignment = TextAnchor.MiddleCenter; }
void printdData(string name) { PlayerInformation data = readData(name); GameObject buttonObject = new GameObject("Button"); CanvasRenderer canvasRenderer = buttonObject.AddComponent <CanvasRenderer>(); Image image = buttonObject.AddComponent <Image>(); Button button = buttonObject.AddComponent <Button>(); buttonObject.transform.parent = panel.transform; VerticalLayoutGroup layout = buttonObject.AddComponent <VerticalLayoutGroup>(); layout.childControlWidth = true; layout.childControlHeight = true; layout.childForceExpandHeight = true; layout.childForceExpandWidth = true; ColorBlock cb = button.colors; cb.selectedColor = Color.yellow; button.colors = cb; PlayerSaveData saveFile = buttonObject.AddComponent <PlayerSaveData>(); saveFile.AddData(data); button.onClick.AddListener(saveFile.OnClick); GameObject textObject = new GameObject("Text"); textObject.transform.parent = buttonObject.transform; Text text = textObject.AddComponent <Text>(); text.text = data.ToString(); text.color = Color.black; Font ArialFont = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf"); text.font = ArialFont; text.material = ArialFont.material; if (counter == 0) { eventSystem.firstSelectedGameObject = buttonObject; } }