You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.8 KiB
110 lines
3.8 KiB
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<CoursewareInfo> CourseWareList;// = new List<ExaminationPrepareObject>(); |
|
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<CoursewareInfo> pair = (PagingReplyInfo<CoursewareInfo>)(message.Data); |
|
CourseWareList = pair.Items; |
|
//questionList = (List<ExaminationPrepareObject>)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<ExaminationPrepareMessage>().setQuestion(question); |
|
if (ControlFist) |
|
{ |
|
item.GetComponent<Toggle>().isOn = true; |
|
ControlFist = false; |
|
} |
|
item.GetComponent<Toggle>().group = this.gameObject.GetComponent<ToggleGroup>(); |
|
} |
|
} |
|
public void CreateView() |
|
{ |
|
string namexml = Application.dataPath + @"/ExtendFolder/xml/CourseXML.xml"; |
|
|
|
if (File.Exists(namexml)) |
|
{ |
|
CreateNodes(); |
|
} |
|
} |
|
/// <summary> |
|
/// 根据xml生成课件名称 |
|
/// </summary> |
|
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<ExaminationPrepareMessage>().setQuestion(courseware); |
|
if (ControlFist) |
|
{ |
|
item.GetComponent<Toggle>().isOn = true; |
|
ControlFist = false; |
|
} |
|
item.GetComponent<Toggle>().group = this.gameObject.GetComponent<ToggleGroup>(); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |