1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 using UnityEngine.UI; 5 6 //选项列表 7 [System.Serializable] 8 class OptionxTxt 9 { 10 //选项 11 public List<string> optionxTxt; 12 } 13 /// <summary> 14 /// 答题面板管理 15 /// </summary> 16 public class AnswerManager : MonoBehaviour 17 { 18 [SerializeField] List<OptionxTxt> optionxTxt;//选项列表 19 [SerializeField] List<string> topics;//题目 20 [SerializeField] Toggle option_A;//选项 21 [SerializeField] Toggle option_B; 22 [SerializeField] Toggle option_C; 23 [SerializeField] Toggle option_O; 24 [SerializeField]Text TextTopics;//题目显示 25 [SerializeField] Text OKTopicCount;//答对多少道题目 26 [SerializeField]string answer;//答案 27 string resul;//成绩 28 [SerializeField]List<Text> Answer_txt; 29 private void Start() 30 { 31 TextTopics.text = topics[0]; 32 } 33 //返回选择结果 34 private string SelectResult() 35 { 36 string str = ""; 37 if (option_A.isOn) str = "A"; 38 if (option_B.isOn) str = "B"; 39 if (option_C.isOn) str = "C"; 40 return str; 41 } 42 //设置选项 43 private void SetOption(int index) 44 { 45 for (int i = 0; i < Answer_txt.Count; i++) 46 { 47 Answer_txt[i].text = optionxTxt[index].optionxTxt[i]; 48 } 49 } 50 //·µ»Ø´ð¶ÔÌâÄ¿µÄÊýÁ¿ 51 private int GetOkTopicsLength() 52 { 53 int count = 0; 54 if (answer[0] == resul[0]) count++; 55 if (answer[1] == resul[1]) count++; 56 if (answer[2] == resul[2]) count++; 57 return count; 58 } 59 //设置为空选项 60 private void EmptyOption() 61 { 62 option_O.isOn = true; 63 } 64 //-------UIEvent------------ 65 int index = 0; 66 public void NextTopic() 67 { 68 index++; 69 if (option_O.isOn) 70 return; 71 if (index >= topics.Count-1) 72 { 73 resul += SelectResult(); 74 OKTopicCount.text = string.Format("¹恭喜你答对{0}题", GetOkTopicsLength()); 75 return; 76 } 77 if (topics.Count <= 0) 78 return; 79 resul += SelectResult(); 80 EmptyOption(); 81 TextTopics.text = topics[index];//更改题目 82 SetOption(index); 83 } 84 }
标签:count,index,string,SerializeField,答题卡,isOn,option From: https://www.cnblogs.com/wl-2619/p/17839685.html