QuestionCard.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Networking;
  6. using UnityEngine.UI;
  7. public class QuestionCard : MonoBehaviour {
  8. public Text questionText;
  9. public Text answerText;
  10. public Text backCategoryText;
  11. public GameObject questionTextPanel;
  12. public string questionString = "";
  13. public string answerString = "";
  14. public string idString = "";
  15. public string categoryString = "";
  16. public Color32 unsafeColor;
  17. public Color32 safeColor;
  18. [SerializeField] CanvasGroup frosting;
  19. public void SetQuestionSafe() {
  20. this.GetComponent<Image>().color = safeColor;
  21. }
  22. internal void SetQuestionUnSafe() {
  23. this.GetComponent<Image>().color = unsafeColor;
  24. }
  25. public bool IsQuestionSafe() {
  26. if (this.GetComponent<Image>().color == safeColor) {
  27. return true;
  28. }
  29. return false;
  30. }
  31. public void SetQuestionCategoryColor(Color32 questionCategoryColor) {
  32. if (backCategoryText != null) {
  33. backCategoryText.transform.parent.GetComponent<Image>().color = questionCategoryColor;
  34. }
  35. }
  36. public void SetQuestionText(string text) {
  37. if (questionText == null) {
  38. GameObject test = new GameObject("Text");
  39. questionText = test.AddComponent<Text>();
  40. }
  41. this.questionText.text = text;
  42. }
  43. public void SetAnswerText(string text) {
  44. if (answerText == null) {
  45. GameObject test = new GameObject("Text");
  46. answerText = test.AddComponent<Text>();
  47. }
  48. this.answerText.text = text;
  49. }
  50. public Text GetQuestionText() {
  51. return this.questionText;
  52. }
  53. public Text GetAnswerText() {
  54. return this.answerText;
  55. }
  56. public int GetCategoryId() {
  57. Int32.TryParse(categoryString, out int result);
  58. return result;
  59. }
  60. internal int GetId() {
  61. Int32.TryParse(idString, out int result);
  62. return result;
  63. }
  64. public void SetId(int value) {
  65. idString = value.ToString();
  66. }
  67. public void SetBackCategoryText(string value) {
  68. if (backCategoryText == null) {
  69. GameObject test = new GameObject("Text");
  70. backCategoryText = test.AddComponent<Text>();
  71. }
  72. backCategoryText.text = value;
  73. }
  74. public string GetBackCategoryText() {
  75. if (backCategoryText == null) {
  76. return "Category";
  77. }
  78. return backCategoryText.text;
  79. }
  80. public void SetFrostingActive(Boolean value) {
  81. if (value) {
  82. frosting.alpha = 1f;
  83. } else {
  84. frosting.alpha = 0f;
  85. }
  86. }
  87. }