123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- using System;
- public enum EAnswerType
- {
- A, B, C, D, E
- }
- public class QuestionItem : MonoBehaviour, IPointerHandler
- {
- public Action<QuestionItem> OnClickBtn;
- private Text m_Menu;
- private Text m_Answer;
- private Image m_RightImage;
- private Image m_ErrorImage;
- private int m_ID;
- private bool m_IsClick;
- private string m_Answertext;
- /// <summary>
- /// 答案选项ID
- /// </summary>
- public int ID
- {
- get { return m_ID; }
- set { m_ID = value; }
- }
- /// <summary>
- /// 答案文字
- /// </summary>
- public string Answertext
- {
- get { return m_Answertext; }
- set { m_Answertext = value; }
- }
- public bool IsClick
- {
- get { return m_IsClick; }
- set
- {
- m_IsClick = value;
- if (!m_IsClick)
- {
- m_ErrorImage.gameObject.SetActive(false);
- m_RightImage.gameObject.SetActive(false);
- }
- }
- }
- private void Awake()
- {
- m_IsClick = false;
- m_Menu = transform.Find("MenuText").GetComponent<Text>();
- m_Answer = transform.Find("QuestionText").GetComponent<Text>();
- m_RightImage = transform.Find("RightImage").GetComponent<Image>();
- m_ErrorImage = transform.Find("ErrorImage").GetComponent<Image>();
- m_ErrorImage.gameObject.SetActive(false);
- m_RightImage.gameObject.SetActive(false);
- }
- public void Init()
- {
- m_Answer.text = m_Answertext;
- switch (ID)
- {
- case (int)EAnswerType.A:
- m_Menu.text = "A";
- break;
- case (int)EAnswerType.B:
- m_Menu.text = "B";
- break;
- case (int)EAnswerType.C:
- m_Menu.text = "C";
- break;
- case (int)EAnswerType.D:
- m_Menu.text = "D";
- break;
- case (int)EAnswerType.E:
- m_Menu.text = "E";
- break;
- default:
- break;
- }
- }
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- }
- /// <summary>
- /// 判断答案是否正确
- /// </summary>
- /// <param name="istrue"></param>
- public void JudgeAnswer(bool istrue)
- {
- m_ErrorImage.gameObject.SetActive(!istrue);
- m_RightImage.gameObject.SetActive(istrue);
- }
- public void OnPointerClick(PointerEventData eventData)
- {
- if (m_IsClick)
- {
- return;
- }
- if (OnClickBtn != null)
- {
- OnClickBtn(this);
- }
- }
- public void OnDrag(PointerEventData eventData)
- {
- }
- public void OnPointerDown(PointerEventData eventData)
- {
- }
- public void OnPointerEnter(PointerEventData eventData)
- {
- }
- public void OnPointerExit(PointerEventData eventData)
- {
- }
- public void OnPointerUp(PointerEventData eventData)
- {
- }
- }
|