| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 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<GameManagerScript>();
- AddTextComponent(statsNames, "Player",false,-1);
- AddTextComponent(statsValues, "",true,-1);
- //AddPlayersFromRefs();
- statsTextNames = statsNames.GetComponentsInChildren<Text>();
- statsTextValues = statsValues.GetComponentsInChildren<Text>();
- }
- public void AddPlayersToStats(List<KeyValuePair<string,int>> 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<Text>();
- 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>();
- 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<Text>();
- statsTextValues = statsValues.GetComponentsInChildren<Text>();
- 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();
- }
- }
- }
- }
|