using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class StatsScript : MonoBehaviour { public GameObject statsNames; public GameObject statsValues; private Text[] statsTextNames; private Text[] statsTextValues; GameManagerScript gms; private void Start() { gms = GameObject.Find("GameManager").GetComponent(); AddTextComponent(statsNames, "Player",false,-1); AddTextComponent(statsValues, "",true,-1); //AddPlayersFromRefs(); statsTextNames = statsNames.GetComponentsInChildren(); statsTextValues = statsValues.GetComponentsInChildren(); } public void AddPlayersToStats(List> players) { int count = players.Count; for (int i = 0; i < count; i++) { AddTextComponent(statsNames, players[i].Key, false, i); AddTextComponent(statsValues, players[i].Value.ToString(), true, i); } } private void AddTextComponent(GameObject parent, string text, bool alignCenter, int index) { GameObject playerHeaderGameObject = new GameObject(); playerHeaderGameObject.transform.parent = parent.transform; Text newTextObject = playerHeaderGameObject.AddComponent(); newTextObject.text = text; newTextObject.font = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf"); newTextObject.color = new Color32(50,50,50,255); newTextObject.resizeTextForBestFit = true; newTextObject.resizeTextMinSize = 10; newTextObject.resizeTextMaxSize = 14; if (index >= 0) { newTextObject.name = "Player" + index; } if (alignCenter) { newTextObject.alignment = TextAnchor.MiddleCenter; } RectTransform rectTransform = newTextObject.GetComponent(); rectTransform.sizeDelta = new Vector2(0, 15); rectTransform.localPosition = new Vector3(0, 0, 0); rectTransform.localScale = new Vector3(1, 1, 1); } public void MakeBold(string playerName) { statsTextNames = statsNames.GetComponentsInChildren(); statsTextValues = statsValues.GetComponentsInChildren(); for (int i = 0; i < statsTextNames.Length; i++) { if (statsTextNames[i].text.Equals(playerName)) { statsTextNames[i].fontStyle = FontStyle.Bold; statsTextValues[i].fontStyle = FontStyle.Bold; } else { statsTextNames[i].fontStyle = FontStyle.Normal; statsTextValues[i].fontStyle = FontStyle.Normal; } } } public void IncreaseRoundValue() { foreach (Text text in statsTextValues) { if (text.name.Equals("Stats Value Round")) { Int32.TryParse(text.text, out int round); round++; text.text = round.ToString(); gms.GetDatabase().SetRoundValue(gms.GameId, round); break; } } } public void SetQuestionsInAnswerLine(string playerName, int count) { for (int i = 0; i < statsTextNames.Length; i++) { if (statsTextNames[i].text.Equals(playerName)) { statsTextValues[i].text = count.ToString(); } } } }