QuestionItem.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6. using System;
  7. public enum EAnswerType
  8. {
  9. A, B, C, D, E
  10. }
  11. public class QuestionItem : MonoBehaviour, IPointerHandler
  12. {
  13. public Action<QuestionItem> OnClickBtn;
  14. private Text m_Menu;
  15. private Text m_Answer;
  16. private Image m_RightImage;
  17. private Image m_ErrorImage;
  18. private int m_ID;
  19. private bool m_IsClick;
  20. private string m_Answertext;
  21. /// <summary>
  22. /// 答案选项ID
  23. /// </summary>
  24. public int ID
  25. {
  26. get { return m_ID; }
  27. set { m_ID = value; }
  28. }
  29. /// <summary>
  30. /// 答案文字
  31. /// </summary>
  32. public string Answertext
  33. {
  34. get { return m_Answertext; }
  35. set { m_Answertext = value; }
  36. }
  37. public bool IsClick
  38. {
  39. get { return m_IsClick; }
  40. set
  41. {
  42. m_IsClick = value;
  43. if (!m_IsClick)
  44. {
  45. m_ErrorImage.gameObject.SetActive(false);
  46. m_RightImage.gameObject.SetActive(false);
  47. }
  48. }
  49. }
  50. private void Awake()
  51. {
  52. m_IsClick = false;
  53. m_Menu = transform.Find("MenuText").GetComponent<Text>();
  54. m_Answer = transform.Find("QuestionText").GetComponent<Text>();
  55. m_RightImage = transform.Find("RightImage").GetComponent<Image>();
  56. m_ErrorImage = transform.Find("ErrorImage").GetComponent<Image>();
  57. m_ErrorImage.gameObject.SetActive(false);
  58. m_RightImage.gameObject.SetActive(false);
  59. }
  60. public void Init()
  61. {
  62. m_Answer.text = m_Answertext;
  63. switch (ID)
  64. {
  65. case (int)EAnswerType.A:
  66. m_Menu.text = "A";
  67. break;
  68. case (int)EAnswerType.B:
  69. m_Menu.text = "B";
  70. break;
  71. case (int)EAnswerType.C:
  72. m_Menu.text = "C";
  73. break;
  74. case (int)EAnswerType.D:
  75. m_Menu.text = "D";
  76. break;
  77. case (int)EAnswerType.E:
  78. m_Menu.text = "E";
  79. break;
  80. default:
  81. break;
  82. }
  83. }
  84. void Start()
  85. {
  86. }
  87. // Update is called once per frame
  88. void Update()
  89. {
  90. }
  91. /// <summary>
  92. /// 判断答案是否正确
  93. /// </summary>
  94. /// <param name="istrue"></param>
  95. public void JudgeAnswer(bool istrue)
  96. {
  97. m_ErrorImage.gameObject.SetActive(!istrue);
  98. m_RightImage.gameObject.SetActive(istrue);
  99. }
  100. public void OnPointerClick(PointerEventData eventData)
  101. {
  102. if (m_IsClick)
  103. {
  104. return;
  105. }
  106. if (OnClickBtn != null)
  107. {
  108. OnClickBtn(this);
  109. }
  110. }
  111. public void OnDrag(PointerEventData eventData)
  112. {
  113. }
  114. public void OnPointerDown(PointerEventData eventData)
  115. {
  116. }
  117. public void OnPointerEnter(PointerEventData eventData)
  118. {
  119. }
  120. public void OnPointerExit(PointerEventData eventData)
  121. {
  122. }
  123. public void OnPointerUp(PointerEventData eventData)
  124. {
  125. }
  126. }