| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class CategoryPanel : MonoBehaviour {
- [Serializable]
- public class Category {
- public string name;
- public int id;
- public Color32 color;
- public int questionCount;
- }
- [SerializeField] GameObject gameManager;
- string gameMode;
- List<Category> categories;
- // Start is called before the first frame update
- void Start() {
- PopulatePanel();
- }
- private void PopulatePanel() {
- if (categories == null) {
- categories = new List<Category>();
- Database.Instance.GetCategories(categories, GetGameMode(), gameManager.GetComponent<GameManagerScript>().GameId);
- }
- foreach (Category cat in categories) {
- AddText(cat.name, cat.color);
- }
- }
- private void AddText(string text, Color32 color) {
- color.a = 255;
- GameObject go = new GameObject(text);
- go.transform.SetParent(this.transform, false);
- Text newText = go.AddComponent<Text>();
- newText.text = text;
- newText.color = color;
- newText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
- newText.resizeTextForBestFit = true;
- newText.resizeTextMaxSize = 40;
- newText.resizeTextMinSize = 8;
- newText.alignment = TextAnchor.MiddleCenter;
- }
- private string GetGameMode() {
- if (gameMode == null) {
- gameMode = PlayerPrefs.GetString(Constants.GAME_MODE);
- }
- return gameMode;
- }
- }
|