using UnityEngine; using System.Collections; using System.IO; using AX.MessageSystem; using AX.TrackRecord; using System; using UnityEngine.UI; using System.Xml; using System.Xml.Serialization; using HelpXHSxml; public enum ModelADD : int { None = 0, Video = 1, Pict = 2, All=3 } public class UIController : MonoBehaviour { /// /// 场景开始根据模式启动 /// private GameObject Courseware; private GameObject MakeScoreSet; private GameObject Examine; private GameObject PapeSet; private GameObject SelfStudy; private GameObject Prepare; private GameObject Teach; private GameObject Exit; private GameObject AddTag; public bool NameControl = true; public static UIController instance; private GameObject TheLieBiao; private GameObject RenYuan; private GameObject GongJu; private GameObject Car; private GameObject ZaiQing; private GameObject DomeView;//工具栏 private GameObject NodeSelectWin; public Record_One_root Record = new Record_One_root(); private GameObject CarAndPeopleBtn; private GameObject ToolBtn; private GameObject DisasterBtn; private GameObject StaffBtn; private GameObject CarPeoPlePicture; private GameObject DisasterPeoPlePicture; private GameObject ToolsPeoPlePicture; private GameObject StaffPeoPlePicture; //private GameObject LeftSet; private GameObject CarShuXingBtn; //private GameObject WeatherBtn; //private GameObject TeamBtn; public GameObject Treeview; public static string filename; [HideInInspector] public GameObject PolygonPlane; void Awake() { if (instance == null) { instance = this; } ExamInfoHelpClass.applicationMode = ExamInfoHelpClass.ApplicationMode.PATHFINDING; //寻路 //ExamInfoHelpClass.loadSceneMode = ExamInfoHelpClass.LoadSceneMode.PrepareMode; CheckUserFolder(); if (MySceneManager.GetActiveScene().name.Equals("11")) { GameObject.Find("SceneAll").transform.Find("shinei").gameObject.SetActive(true); } if (GameObject.Find("PolygonPlane")) { PolygonPlane = GameObject.Find("PolygonPlane").gameObject; PolygonPlane.SetActive(false); } } private void CheckUserFolder() { string path = Application.dataPath + @"/ExtendFolder/xml/Coursewares/"; string fileDir = Path.GetDirectoryName(path); string pathxml= Application.dataPath + @"/ExtendFolder/xml/"; string PathPlan = Application.dataPath + @"/Three-dimensionalPlan/"; string namexml = Application.dataPath + @"/ExtendFolder/xml/NodeNameList.xml"; if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.PrepareMode) { if (File.Exists(namexml)) { File.Delete(namexml); CreateXml(pathxml);//用于根据创建的xml排序节点 } else { CreateXml(pathxml);//用于根据创建的xml排序节点 } } if (!Directory.Exists(PathPlan)) { Directory.CreateDirectory(PathPlan); } if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); CrestXml(path); } ExamInfoHelpClass.CurrentWorkPath = path;//确定当前用户的工作路径 CheckPath(); AwakeOnDestroy(); } public void AwakeOnDestroy() { string path = Application.dataPath + @"/ExtendFolder/xml/Coursewares/Temporaryfile/" ; string fileDir = Path.GetDirectoryName(path); if (Directory.Exists(fileDir)) { string[] files = Directory.GetFiles(path); foreach (string file in files) { File.Delete(file); } } } void OnDestroy() { } public void CheckPath() { if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.PrepareMode) { ExamInfoHelpClass.CurrentWorkPath = Application.dataPath + @"/ExtendFolder/xml/Coursewares/" + "Temporaryfile/"; ExamInfoHelpClass.NameListWorkPath = Application.dataPath + @"/ExtendFolder/xml/" + "NodeNameList.xml"; ExamInfoHelpClass.savexmlWorkPath = Application.dataPath + @"/ExtendFolder/xml/Coursewares/" + "Temporaryfile/"; } else if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.EditCourceware) { ExamInfoHelpClass.CurrentWorkPath = NodeSet.Cousrsewse.FilePath + "savexml/"; ExamInfoHelpClass.NameListWorkPath = NodeSet.Cousrsewse.FilePath + "NodeNameList.xml"; ExamInfoHelpClass.savexmlWorkPath = NodeSet.Cousrsewse.FilePath + "savexml/"; } else if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.PrepareModeLook) { ExamInfoHelpClass.CurrentWorkPath = NodeSet.Cousrsewse.FilePath + "savexml/"; ExamInfoHelpClass.NameListWorkPath = NodeSet.Cousrsewse.FilePath + "NodeNameList.xml"; ExamInfoHelpClass.savexmlWorkPath = NodeSet.Cousrsewse.FilePath + "savexml/"; } } /// /// 读取消火栓XML /// public void LoadXHSxml() { RootRecordItem XHSRoot = ReturnXHSxml(); if (XHSRoot != null) { if (XHSRoot.BaseList.Count > 0) { Transform Father = GameObject.Find("AllParent/pXhs").transform; for (int i = 0; i < XHSRoot.BaseList.Count; i++) { BaseDataAttri Attri = XHSRoot.BaseList[i] as BaseDataAttri; GameObject xhs = Instantiate(Resources.Load("Prefabs/ToolPrefab/XHSScene")); xhs.transform.parent = GameObject.Find("AllParent/pXhs").transform; xhs.transform.localPosition = Attri.position; xhs.transform.localScale = Attri.scale; xhs.transform.localEulerAngles = Attri.rotation; xhs.GetComponent().cengID = Attri.CengID; xhs.GetComponent().CengIDBuildType = Attri.buidType; xhs.name = Attri.Name; CreateXHS.instance.XHSList.Add(xhs); } } } } /// /// 反序列化消火栓XML /// /// RootRecordItem public RootRecordItem ReturnXHSxml() { string XHSpath = NodeSet.Cousrsewse.FilePath + "XHS.xml"; if (File.Exists(XHSpath)) { Debug.Log("Have"); StreamReader reader = new StreamReader(XHSpath); RootRecordItem root = new RootRecordItem(); XmlSerializer xml = new XmlSerializer(typeof(RootRecordItem)); root = xml.Deserialize(reader) as RootRecordItem; reader.Close(); Debug.Log("bACK"); return root; } return null; } private void CreateXml(string path) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(dec); //根 XmlElement root = doc.CreateElement("NodeNameList"); doc.AppendChild(root); //创建节点(二级) XmlElement Name = doc.CreateElement("NextID"); Name.InnerText="1"; root.AppendChild(Name); //创建节点(二级) XmlElement nodes = doc.CreateElement("Nodes"); root.AppendChild(nodes); //创建节点(三级) XmlElement node = doc.CreateElement("Node"); node.SetAttribute("ID", "0"); node.SetAttribute("Name", "模拟演练"); node.SetAttribute("ParentID", "-1"); node.SetAttribute("Hierarchy", "0"); node.InnerText = "21"; nodes.AppendChild(node); doc.Save(path + "/" + "NodeNameList.xml"); Console.Write(doc.OuterXml); } public void CrestXml(string path) { XmlDocument doc = new XmlDocument(); XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(dec); //创建一个根节点(一级) XmlElement root = doc.CreateElement("ScoreAssets"); doc.AppendChild(root); //创建节点(二级) XmlNode node = doc.CreateElement("Child"); root.AppendChild(node); //创建节点(三级) XmlElement ScoreID = doc.CreateElement("score"); ScoreID.SetAttribute("ScoreID", "0"); ScoreID.SetAttribute("AnwserID", "00"); ScoreID.SetAttribute("CreatID", "11"); node.AppendChild(ScoreID); root.AppendChild(node); doc.Save(path + "/" + "SocreData.xml"); Console.Write(doc.OuterXml); } void Start() { Courseware = this.gameObject.transform.Find("自学课件").gameObject; Examine = this.gameObject.transform.Find("考核模式").gameObject; PapeSet = this.gameObject.transform.Find("考卷设置").gameObject; SelfStudy = this.gameObject.transform.Find("自学模式").gameObject; Prepare = this.gameObject.transform.Find("备课模式").gameObject; Teach = this.gameObject.transform.Find("授课模式").gameObject; Exit = this.gameObject.transform.Find("退出").gameObject; MakeScoreSet = this.gameObject.transform.Find("评分模式").gameObject; TheLieBiao = this.gameObject.transform.parent.Find("DomeView").Find("BroweMenu").Find("BtnGrid").gameObject; NodeSelectWin = GameObject.Find("Canvas").transform.Find("ToolbarObject").Find("NodeSelectWin").gameObject; AddTag = this.gameObject.transform.parent.Find("AddTag").gameObject; DomeView = this.gameObject.transform.parent.Find("DomeView").gameObject; CarAndPeopleBtn = DomeView.transform.Find("BroweMenu").Find("BtnGrid").Find("CarButton").gameObject; ToolBtn = DomeView.transform.Find("BroweMenu").Find("BtnGrid").Find("ToolButton").gameObject; DisasterBtn = DomeView.transform.Find("BroweMenu").Find("BtnGrid").Find("DisasterButton").gameObject; StaffBtn = DomeView.transform.Find("BroweMenu").Find("BtnGrid").Find("StaffButton").gameObject; CarShuXingBtn = DomeView.transform.Find("BroweMenu").Find("CarShuXing").gameObject; //LeftSet = GameObject.Find("IntercalateButton").gameObject; //WeatherBtn = LeftSet.transform.Find("WeatherButton").gameObject; //TeamBtn = LeftSet.transform.Find("TeamNameButton").gameObject; CarPeoPlePicture = DomeView.transform.Find("BroweMenu").Find("CarButtonPicture").gameObject; DisasterPeoPlePicture = DomeView.transform.Find("BroweMenu").Find("DisasterButtonPicture").gameObject; StaffPeoPlePicture = DomeView.transform.Find("BroweMenu").Find("StaffButtonPicture").gameObject; ToolsPeoPlePicture = DomeView.transform.Find("BroweMenu").Find("ToolButtonPicture").gameObject; Treeview = NodeSelectWin.transform.Find("TreeView").gameObject; CheckMode(); if (ExamInfoHelpClass.applicationMode == ExamInfoHelpClass.ApplicationMode.PATHFINDING) { StaffBtn.SetActive(false); } Treeview.SetActive(false); Invoke("showtreeview", 0.2f); if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.EditCourceware || ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.PrepareModeLook) { LoadXHSxml(); } UIActive(); } /// /// 移动指挥终端模块需要控制 UI: RightSet 的显隐,但也需要此脚本中Start中CheckMode()逻辑,所以移至到这里,不然又执行顺序的问题 /// private void UIActive() { MessageDispatcher.SendMessage("UI_ACTIVE"); } public void showtreeview() { Treeview.SetActive(true); } void CheckMode() { AllFalse(); switch (ExamInfoHelpClass.loadSceneMode) { case ExamInfoHelpClass.LoadSceneMode.CoursewareMode://自学课件模式 CoursewareMode(); break; case ExamInfoHelpClass.LoadSceneMode.ExamineMode://考核模式 ExamineMode(); break; case ExamInfoHelpClass.LoadSceneMode.CreatQuestion://考题设置模式 CreatQuestion(); break; case ExamInfoHelpClass.LoadSceneMode.SelfStudyMode://自学模式 SelfStudyMode(); break; case ExamInfoHelpClass.LoadSceneMode.PrepareMode://备课模式 PrepareMode(); break; case ExamInfoHelpClass.LoadSceneMode.EditCourceware://编辑课件模式 PrepareMode(); break; case ExamInfoHelpClass.LoadSceneMode.PrepareModeLook://备课查看模式 PrepareModeLook(); break; case ExamInfoHelpClass.LoadSceneMode.TeachMode://授课模式 TeachMode(); break; case ExamInfoHelpClass.LoadSceneMode.CourseBaseMode://课件库模式 CourseBaseMode(); break; case ExamInfoHelpClass.LoadSceneMode.CheckAnswer: Debug.Log("查看答案"); //加载场景,回放记录 CheckAnswer(); break; case ExamInfoHelpClass.LoadSceneMode.CheckScore: Debug.Log("查看分数"); //加载场景,罗列分数 CheckScore(); break; case ExamInfoHelpClass.LoadSceneMode.MakeScore: Debug.Log("评分"); //加载考试记录,开始评分 MakeScore(); break; case ExamInfoHelpClass.LoadSceneMode.CheckQuestion: Debug.Log("查看考题"); //只加载灾情,不开始记录 CheckQuestion(); //此情景下只是加载考题,不提供任何其他界面 break; case ExamInfoHelpClass.LoadSceneMode.EditQuestion: case ExamInfoHelpClass.LoadSceneMode.CopyQuestion: Debug.Log("编辑或复制考题"); //只加载灾情,不开始记录 EditOrCopyQuestion(); //此情景下只是加载考题,不提供任何其他界面 break; default: break; } } private void Update() { } private void EditOrCopyQuestion() { //反序列化并加载灾情 Record = null; //string filename = ExaminationQuestionDetail.question.ID + "/" + ExaminationQuestionDetail.question.FilePath; Record = TrackRecordHelpClass.LoadRecord_DeserializeXMLToRecord("Questions/" + filename); //TrackRecordHelpClass.LoadObjSetToOriginalTrans(Record); LoadManager.Instance.LoadObjSetToOriginalTrans(Record); //提供灾情工具栏 CreatQuestion(); ShowQuestionIntro(ExaminationQuestionDetail.question.Intro); } private void SetSceneFromXmlPath(string path) { Record = null; string filename = BaseItemManager.CurQues.ID + "/" + BaseItemManager.CurQues.FilePath; Record = TrackRecordHelpClass.LoadRecord_DeserializeXMLToRecord(path + "/" + filename); //该函数的默认路径待修改 } void AllFalse() { Courseware.SetActive(false); Examine.SetActive(false); PapeSet.SetActive(false); SelfStudy.SetActive(false); Prepare.SetActive(false); Teach.SetActive(false); MakeScoreSet.SetActive(false); Exit.SetActive(false); } void UIFalse() { CarAndPeopleBtn.SetActive(false); ToolBtn.SetActive(false); DisasterBtn.SetActive(false); StaffBtn.SetActive(false); CarPeoPlePicture.SetActive(false); DisasterPeoPlePicture.SetActive(false); ToolsPeoPlePicture.SetActive(false); StaffPeoPlePicture.SetActive(false); CarShuXingBtn.SetActive(false); } private IEnumerator ITheCheck(int i) { yield return new WaitForSeconds(Time.deltaTime * 2); TheCheck_(i); } private void TheCheck_(int i) { UIFalse(); if (i == 1) { CarAndPeopleBtn.SetActive(true); ToolBtn.SetActive(true); StaffBtn.SetActive(true); CarPeoPlePicture.SetActive(true); AddTag.SetActive(true); CarShuXingBtn.SetActive(true); } else if (i == 3) { DisasterBtn.SetActive(true); DisasterPeoPlePicture.SetActive(true); } else if (i == 7) { CarAndPeopleBtn.SetActive(true); ToolBtn.SetActive(true); DisasterBtn.SetActive(true); StaffBtn.SetActive(true); CarPeoPlePicture.SetActive(true); CarShuXingBtn.SetActive(true); } else if (i == 9) { CarAndPeopleBtn.SetActive(true); ToolBtn.SetActive(true); DisasterBtn.SetActive(true); StaffBtn.SetActive(true); CarPeoPlePicture.SetActive(true); CarShuXingBtn.SetActive(true); } } public void TheCheck(int i) { //StartCoroutine(ITheCheck(i)); TheCheck_(i); } /// /// 展示考题简介 /// void ShowQuestionIntro(string intro) { Debug.Log(intro); var qiWin = transform.parent.Find("QuestionIntroPanel"); qiWin.gameObject.SetActive(true); qiWin.Find("Viewport/Content").GetComponent().text = intro; } void ExamineMode()//考核模式 { Examine.SetActive(true); ExamineModeSet.instance.stopped = false; NodeSelectWin.SetActive(false); TheCheck(1); SetSceneFromXmlPath("Questions"); //加载考题灾情 //TrackRecordHelpClass.LoadObjSetToOriginalTrans(Record);//该处还是采用这种加载初始物体的方式,避免答案中未记录初始物体 LoadManager.Instance.LoadObjSetToOriginalTrans(Record); //开始记录 //RecordManager.Instance.StartRecord(); RecordManager.Instance.StartRecordWait1Frame(); ShowQuestionIntro(BaseItemManager.CurQues.Intro); } private void CheckQuestion()//查看考题 { DomeView.SetActive(false); Exit.SetActive(true); SetSceneFromXmlPath("Questions"); //加载考题灾情 //TrackRecordHelpClass.LoadObjSetToOriginalTrans(Record); LoadManager.Instance.LoadObjSetToOriginalTrans(Record); ShowQuestionIntro(BaseItemManager.CurQues.Intro); } void CreatQuestion()//考题设置模式 只有灾情 { PapeSet.SetActive(true); NodeSelectWin.SetActive(false); TheCheck(3); } private void MakeScore()//评分 { //打分模式,显示并刷新考生列表面板 DomeView.SetActive(false); MakeScoreSet.SetActive(true); GameObject.Find("Canvas").transform.Find("MakeScoreStudentList").gameObject.SetActive(true); } private void CheckScore()//查看评分 { DomeView.SetActive(false); Exit.SetActive(true); //显示答案面板 GameObject.Find("Canvas").transform.Find("ScoreResultCheckList").gameObject.SetActive(true); //该答案的Xml路径是BaseItemManager.XmlPath //如果要加载答案可以使用此处获取record } private void CheckAnswer()///查看作答 { DomeView.SetActive(false); Exit.SetActive(true); //查看,播放作答的答案记录 NodeSet.Instance.LoadRecordFromFile("Answers/" + BaseItemManager.CurExam.ID + "_" + BaseItemManager.CurQues.ID + ".xml"); GameObject.Find("Canvas").transform.Find("考核模式倒计时").gameObject.SetActive(true); LoadManager.Instance.IsMakeScore = true; } void PrepareMode()//备课模式 { Prepare.SetActive(true); NodeSelectWin.SetActive(true); TheCheck(7); } void PrepareModeLook()//备课查看(用了课件学习的模式) { Exit.SetActive(true); DomeView.SetActive(false); NodeSelectWin.SetActive(true); } void TeachMode()//授课模式 { Teach.SetActive(true); DomeView.SetActive(false); NodeSelectWin.SetActive(true); } void CourseBaseMode()//课件库模式 { Exit.SetActive(true); DomeView.SetActive(false); NodeSelectWin.SetActive(true); } void SelfStudyMode()//自学模式 { SelfStudy.SetActive(true); NodeSelectWin.SetActive(false); TheCheck(9); } void CoursewareMode()//自学课件 { Courseware.SetActive(true); DomeView.SetActive(false); NodeSelectWin.SetActive(true); } void LoadExamToScene() { //TrackRecordHelpClass.LoadObjSetToOriginalTrans(Record); LoadManager.Instance.LoadObjSetToOriginalTrans(Record); } public void GetUITrue() { switch (ExamInfoHelpClass.loadSceneMode) { case ExamInfoHelpClass.LoadSceneMode.CoursewareMode://自学课件模式 DomeView.SetActive(false); break; case ExamInfoHelpClass.LoadSceneMode.PrepareModeLook://备课模式 DomeView.SetActive(false); break; case ExamInfoHelpClass.LoadSceneMode.PrepareMode://备课模式 DomeView.SetActive(true); break; case ExamInfoHelpClass.LoadSceneMode.EditCourceware://编辑课件模式 DomeView.SetActive(true); break; case ExamInfoHelpClass.LoadSceneMode.TeachMode://授课模式 DomeView.SetActive(false); break; case ExamInfoHelpClass.LoadSceneMode.CourseBaseMode://课件库模式 DomeView.SetActive(false); break; case ExamInfoHelpClass.LoadSceneMode.CheckAnswer: DomeView.SetActive(false); break; case ExamInfoHelpClass.LoadSceneMode.CheckScore: DomeView.SetActive(false); break; case ExamInfoHelpClass.LoadSceneMode.MakeScore: DomeView.SetActive(false); break; default: break; } } }