| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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;
- }
- GameManagerScript gms;
- List<Category> categories;
- // Start is called before the first frame update
- void Start()
- {
- PopulatePanel();
- }
- private void PopulatePanel() {
- if (categories == null) {
- if (PlayerPrefs.GetString("GameMode").Equals("Local")) {
- Database.Instance.GetCategories(categories);
- } else if (PlayerPrefs.GetString("GameMode").Equals("Online")) {
- OnlineDatabase.Instance.GetCategories(categories);
- }
- }
- 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 = 18;
- newText.resizeTextMinSize = 8;
- newText.alignment = TextAnchor.MiddleCenter;
- }
- public Category GetCategoryById(int id) {
- if (categories == null) {
- if (PlayerPrefs.GetString("GameMode").Equals("Local")) {
- Database.Instance.GetCategories(categories);
- } else if (PlayerPrefs.GetString("GameMode").Equals("Online")) {
- OnlineDatabase.Instance.GetCategories(categories);
- }
- }
- foreach (Category cat in categories) {
- if (cat.id == id) {
- return cat;
- }
- }
- return null;
- }
- }
|