QuestionCard.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. private Color categoryColor;
  13. private int categoryId;
  14. private int questionId;
  15. private bool questionSafe;
  16. private String categoryText;
  17. public Color32 unsafeColor;
  18. public Color32 safeColor;
  19. [SerializeField] CanvasGroup frosting;
  20. [SerializeField] GameObject frontCategoryPanel;
  21. [SerializeField] Text frontCategoryText;
  22. public Color CategoryColor { get => categoryColor; set => categoryColor = value; }
  23. public int CategoryId { get => categoryId; set => categoryId = value; }
  24. public int QuestionId { get => questionId; set => questionId = value; }
  25. public bool QuestionSafe { get => questionSafe; set => questionSafe = value; }
  26. public string CategoryText { get => categoryText; set => categoryText = value; }
  27. public void SetQuestionSafe(bool safe) {
  28. if (safe) {
  29. SetQuestionSafe();
  30. } else {
  31. SetQuestionUnSafe();
  32. }
  33. }
  34. public void SetQuestionSafe() {
  35. this.GetComponent<Image>().color = safeColor;
  36. QuestionSafe = true;
  37. }
  38. internal void SetQuestionUnSafe() {
  39. this.GetComponent<Image>().color = unsafeColor;
  40. QuestionSafe = false;
  41. }
  42. public bool IsQuestionSafe() {
  43. return QuestionSafe;
  44. }
  45. public void SetQuestionCategoryColor(Color32 questionCategoryColor) {
  46. CategoryColor = questionCategoryColor;
  47. if (backCategoryText != null) {
  48. backCategoryText.transform.parent.GetComponent<Image>().color = questionCategoryColor;
  49. frontCategoryPanel.GetComponent<Image>().color = questionCategoryColor;
  50. }
  51. }
  52. public void SetQuestionText(string text) {
  53. if (questionText == null) {
  54. GameObject test = new GameObject("Text");
  55. questionText = test.AddComponent<Text>();
  56. }
  57. this.questionText.text = text;
  58. }
  59. public void SetAnswerText(string text) {
  60. if (answerText == null) {
  61. GameObject test = new GameObject("Text");
  62. answerText = test.AddComponent<Text>();
  63. }
  64. this.answerText.text = text;
  65. }
  66. public String GetQuestionText() {
  67. return this.questionText.text;
  68. }
  69. public String GetAnswerText() {
  70. return this.answerText.text;
  71. }
  72. public void SetId(int value) {
  73. questionId = value;
  74. }
  75. public void SetBackCategoryText(string value) {
  76. if (backCategoryText == null) {
  77. GameObject temp = new GameObject("Text");
  78. backCategoryText = temp.AddComponent<Text>();
  79. }
  80. backCategoryText.text = value;
  81. frontCategoryText.text = value;
  82. CategoryText = value;
  83. }
  84. public string GetBackCategoryText() {
  85. if (backCategoryText == null) {
  86. return "Category";
  87. }
  88. return backCategoryText.text;
  89. }
  90. public void SetFrostingActive(Boolean value) {
  91. if (value) {
  92. frosting.alpha = 1f;
  93. } else {
  94. frosting.alpha = 0f;
  95. }
  96. }
  97. }