using UnityEngine; using System.Collections.Generic; using AX.MessageSystem; using AX.NetworkSystem; using UnityEngine.UI; using System.IO; using System.Linq; using System.Xml; public class ExaminationPrepareList : MonoBehaviour { int numberEachPage = 10; public GameObject itemPrefab; public List CourseWareList;// = new List(); void Start() { CreateView(); MessageDispatcher.AddListener("PREPARE_PAGE_REFRESH", showQuestionList); } void OnDestroy() { MessageDispatcher.RemoveListener("PREPARE_PAGE_REFRESH", showQuestionList); } // Update is called once per frame void Update() { } bool ControlFist=true;//第一个属性预设的复选框为选中状态 //刷新列表信息 private void showQuestionList(IMessage message) { PagingReplyInfo pair = (PagingReplyInfo)(message.Data); CourseWareList = pair.Items; //questionList = (List)message.Data; foreach (Transform child in transform) { Destroy(child.gameObject); } foreach (CoursewareInfo question in CourseWareList) { GameObject item = Instantiate(itemPrefab) as GameObject; item.transform.parent = this.transform; item.transform.localScale = new Vector3(1, 1, 1); item.name = "Item"; item.GetComponent().setQuestion(question); if (ControlFist) { item.GetComponent().isOn = true; ControlFist = false; } item.GetComponent().group = this.gameObject.GetComponent(); } } public void CreateView() { string namexml = Application.dataPath + @"/ExtendFolder/xml/CourseXML.xml"; if (File.Exists(namexml)) { CreateNodes(); } } /// /// 根据xml生成课件名称 /// public void CreateNodes() { foreach (Transform child in transform) { Destroy(child.gameObject); } string filepath = Application.dataPath + @"/ExtendFolder/xml/CourseXML.xml"; if (File.Exists(filepath)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(filepath); XmlNode root = xmlDoc.SelectSingleNode("CourseNameList"); XmlNodeList nodeList = root.ChildNodes; foreach (XmlElement elem in nodeList) { if (elem.Name == "CourseName") { foreach (XmlElement node in elem) { GameObject item = Instantiate(itemPrefab) as GameObject; item.transform.parent = this.transform; item.transform.localScale = new Vector3(1, 1, 1); item.name = node.InnerText; CoursewareInfo courseware = new CoursewareInfo(); courseware.CreatorName = node.InnerText; string str = node.GetAttribute("ID").ToString(); courseware.SceneType =int.Parse(str); courseware.FilePath = Application.dataPath + @"/ExtendFolder/xml/SaveCoursewares/" + courseware.CreatorName+"/"; item.GetComponent().setQuestion(courseware); if (ControlFist) { item.GetComponent().isOn = true; ControlFist = false; } item.GetComponent().group = this.gameObject.GetComponent(); } } } } } }