130 lines
3.3 KiB
C#
130 lines
3.3 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
using GCGame.Table;
|
|
|
|
public class ImperialOrderPanelCtr : MonoBehaviour {
|
|
public static ImperialOrderPanelCtr Instance;
|
|
void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
Instance = null;
|
|
}
|
|
|
|
public List<GameObject> answerList;
|
|
public List<Image> markList;
|
|
public List<Image> rightOrWrongIconList;
|
|
|
|
public Text questionDesc;
|
|
public List<Text> anserDescList;
|
|
|
|
public GameObject markPanel;
|
|
|
|
public Sprite rightIcon;
|
|
public Sprite wrongIcon;
|
|
|
|
private Tab_QuestionBank bank = null;
|
|
private int rightAnswerIndex = -1;
|
|
|
|
public void InitQuestionInfo(int questionId)
|
|
{
|
|
bank = TableManager.GetQuestionBankByID(questionId, 0);
|
|
if(bank != null)
|
|
{
|
|
questionDesc.text = bank.QuestionDesc;
|
|
for(int index = 0; index < answerList.Count; index++)
|
|
{
|
|
anserDescList[index].text = bank.GetAnswerbyIndex(index);
|
|
}
|
|
}
|
|
|
|
if (markPanel.activeInHierarchy)
|
|
{
|
|
markPanel.gameObject.SetActive(false);
|
|
}
|
|
|
|
HideAllAnswerIcon();
|
|
GetRightAnswer();
|
|
}
|
|
|
|
public void HideAllAnswerIcon()
|
|
{
|
|
for (int index = 0; index < rightOrWrongIconList.Count; index++)
|
|
{
|
|
rightOrWrongIconList[index].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void GetRightAnswer()
|
|
{
|
|
string answer = bank.RightAnswer;
|
|
switch(answer)
|
|
{
|
|
case "A":
|
|
rightAnswerIndex = 0;
|
|
break;
|
|
case "B":
|
|
rightAnswerIndex = 1;
|
|
break;
|
|
case "C":
|
|
rightAnswerIndex = 2;
|
|
break;
|
|
default:
|
|
rightAnswerIndex = 3;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
public void OnAnswerClick(int answer) //0A 1B 3C 4D
|
|
{
|
|
//设置CheckMark
|
|
for (int index = 0; index < answerList.Count; index++)
|
|
{
|
|
markList[index].gameObject.SetActive(index == answer);
|
|
}
|
|
|
|
//显示正确错误的答案
|
|
for (int index = 0; index < rightOrWrongIconList.Count; index++)
|
|
{
|
|
rightOrWrongIconList[index].gameObject.SetActive(true);
|
|
rightOrWrongIconList[index].overrideSprite = (index == rightAnswerIndex ? rightIcon : wrongIcon);
|
|
rightOrWrongIconList[index].SetNativeSize();
|
|
answerList[index].gameObject.GetComponent<Button>().interactable = false;
|
|
}
|
|
|
|
//发送协议
|
|
CG_REQ_QUESTION req = (CG_REQ_QUESTION)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_QUESTION);
|
|
req.SetReqType((int)ImpreialExamPanelCtr.Question_Type.QUESTION_BAOLINGDAN);
|
|
req.SetAnswer(answer + 1);
|
|
req.SendPacket();
|
|
}
|
|
|
|
|
|
public void OnCloseBtnClick()
|
|
{
|
|
UIManager.CloseUI(UIInfo.ImperialOrderPanel);
|
|
}
|
|
|
|
public void OnDisable()
|
|
{
|
|
SetNativeSeting();
|
|
}
|
|
|
|
//按钮的点击跟选中状态全部由初始化
|
|
public void SetNativeSeting()
|
|
{
|
|
for (int index = 0; index < answerList.Count; index++)
|
|
{
|
|
answerList[index].gameObject.GetComponent<Button>().interactable = true;
|
|
markList[index].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
}
|