天津23维预案
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.
 
 
 
 
 
 

1333 lines
48 KiB

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using AX.MessageSystem;
using AX.TrackRecord;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using System;
using System.IO;
using UnityEngine.SceneManagement;
using AX.NetworkSystem;
using System.Text.RegularExpressions;
using System.Linq;
using System.Xml;
using DevelopEngine;
public class NodeSet : SingletonMono<NodeSet> {
/**
* 节点显示面板
*/
private Button XinJianBtn;//新建按钮
public Button JiaZaiBtn;//加载按钮
public GameObject NodePrefab;//节点预设
private GameObject NodeFather;//节点预设的父物体
private Text XinJianText;//新建按钮下的文本框
private Text BtText;//标题文本框
[HideInInspector]
public GameObject PlaneWithRercod;//添加记录的面板
private InputField XinJianNodeName;//记录面板的详细输入框
private InputField XinJianIntroName;//记录面板的名字输入框
private InputField NodeNameWithRecord;//编辑节点名称输入框
private InputField NodeIntroWithRecord;//编辑节点详细输入框
private GameObject PingBiKuang;//屏蔽框
//public static NodeSet Instance;
public GameObject AddBtn;
private Text CousrseName;
public static CoursewareInfo Cousrsewse;
void Awake()
{
//if (Instance == null)
//{
// Instance = this;
//}
//CheckPath();
AwakeOnDestroy();
}
void Start ()
{
XinJianBtn = this.transform.Find("XianJian").GetComponent<Button>();
JiaZaiBtn = this.transform.Find("JiaZai").GetComponent<Button>();
CousrseName = this.transform.Find("BT").GetComponent<Text>();
NodeFather = this.transform.Find("Scroll View (1)").Find("Viewport").Find("Content").gameObject;
BtText = this.transform.Find("BT").GetComponent<Text>();
XinJianText = XinJianBtn.transform.Find("Text").GetComponent<Text>();
PlaneWithRercod = this.transform.parent.Find("XianJianJieDianPlane").gameObject;
XinJianNodeName = PlaneWithRercod.transform.Find("Name").GetComponent<InputField>();
XinJianIntroName = PlaneWithRercod.transform.Find("Scroll View/Viewport/Intro").GetComponent<InputField>();
NodeNameWithRecord = this.transform.parent.Find("NodeIntroShowWin").Find("Name").GetComponent<InputField>();
NodeIntroWithRecord = this.transform.parent.Find("NodeIntroShowWin").Find("Scroll View/Viewport/Intro").GetComponent<InputField>();
XinJianNodeName.onValidateInput += ValidCharDetect._OnValidateInput;
NewFuGaiIntro = this.transform.parent.Find("NewFuGaiShowWin").Find("Intro").GetComponent<InputField>();
XinJianBtn.onClick.AddListener(StrartRecord);
JiaZaiBtn.onClick.AddListener(LoadNode);
MessageDispatcher.AddListener("SpaceControl", SpacnControl);
if (ExamInfoHelpClass.loadSceneMode != ExamInfoHelpClass.LoadSceneMode.PrepareMode)
{
this.XinJianBtn.gameObject.SetActive(false);
if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.EditCourceware)
{
this.XinJianBtn.gameObject.SetActive(true);
}
}
MySceneManager.BackToLastSceneEvent += BackToLastSceneEvent;
JiaZaiBtn.gameObject.SetActive(false);
//第二套
//this.gameObject.SetActive(false);
}
public void SpacnControl(IMessage mes)
{
if ((string)mes.Data == "NodeSet")
{
if (LoadManager.Instance.IsPlayBacking && !TheBackView.instance.VidoSHOW.activeInHierarchy && !TheBackView.instance.PictSHOW.activeInHierarchy)
{
TheBackView.instance.ControlBtn();
}
}
}
private void BackToLastSceneEvent(MyEventArgs args)
{
if (args.destinateScene == "PrepareLessons")
{
NodeListName.Clear();
Debug.Log("NodeListName"+NodeListName.Count);
}
}
void GenerateNodexml()
{
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + "NodeNameList.xml";
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Name")
{
foreach (XmlElement node in elem)
{
GameObject checkBox = Instantiate(NodePrefab) as GameObject;
checkBox.transform.SetParent(NodeFather.transform);
checkBox.transform.localScale = new Vector3(1, 1, 1);
checkBox.GetComponentInChildren<Text>().text = node.InnerText;
checkBox.name = node.InnerText;
}
}
}
}
}
void GenerateNode() //开始创建节点预设
{
//List<string> Node = new List<string>();
//string path = ExamInfoHelpClass.CurrentWorkPath;
//string fileDir = Path.GetDirectoryName(path);
//if (Directory.Exists(fileDir))
//{
// string[] files = Directory.GetFiles(fileDir);
// List<string> ssss = files.OrderBy(ss => new FileInfo(ss).CreationTime).ToList();
// foreach (string file in ssss)
// {
// string str = Path.GetFileName(file);
// if (!str.Contains(".meta"))
// {
// GameObject checkBox = Instantiate(NodePrefab) as GameObject;
// checkBox.transform.SetParent(NodeFather.transform);
// checkBox.transform.localScale = new Vector3(1, 1, 1);
// checkBox.GetComponentInChildren<Text>().text = str.Substring(0,str.Length-4);
// checkBox.name = str.Substring(0, str.Length - 4);
// Debug.Log(checkBox.name);
// checkBox.transform.SetAsLastSibling();
// }
// }
//}
//string Data = Cousrsewse.FilePath;
//CousrseName.text = Cousrsewse.Name;
//string[] char_Data = Data.Split(new char[] { ';' },System.StringSplitOptions.RemoveEmptyEntries);
//int t = 0;
//for (int i = 0; i <char_Data.Length; i++)
//{
// GameObject checkBox = Instantiate(NodePrefab) as GameObject;
// checkBox.transform.SetParent(NodeFather.transform);
// checkBox.transform.localScale = new Vector3(1, 1, 1);
// string name = char_Data[i].Substring(0,char_Data[i].Length-4);
// checkBox.GetComponentInChildren<Text>().text = name;
// checkBox.name = name;
// //针对编辑课件模式,要将当前课件文件复制到与新建课件统一的路径下,并添加到节点名数组中
// if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.EditCourceware)
// {
// File.Copy(ExamInfoHelpClass.CurrentWorkPath + "Coursewares/" + Cousrsewse.ID + "/" + char_Data[i], ExamInfoHelpClass.CurrentWorkPath + "Coursewares/" + char_Data[i]);
// NodeListName.Add(char_Data[i]);
// }
//}
}
public void StrartRecord()//开始记录方法
{
if (XinJianText.text == "新建记录")
{
if (CheckHasFireSpreading())
{
MessageDispatcher.SendMessage("Operatinghints", (object)"蔓延中,不能新建节点!");
return;
}
if (TreeViewControl__.Instance.HasItemSelected() < 0)
{
MessageDispatcher.SendMessage("Operatinghints", (object)"请勾选确定新建位置!");
return;
}
XinJianText.text = "停止记录";
AddBtn.SetActive(true);
RecordManager.Instance.StartRecord();
JiaZaiBtn.gameObject.SetActive(false);
AddRecordTag.Instance.ThisButton.enabled = true;//zzj
}
else
{
XinJianText.text = "新建记录";
AddBtn.SetActive(false);
RecordManager.Instance.IsPause = true;
MessageDispatcher.SendMessage("OPEN", (object)PlaneWithRercod.name, "CUBE");
//JiaZaiBtn.gameObject.SetActive(true);
}
}
public void StrartRecord_new(bool newFlag = true)//开始记录方法
{
if (newFlag)//新建节点
{
if (CheckHasFireSpreading())
{
MessageDispatcher.SendMessage("Operatinghints", (object)"蔓延中,不能新建节点!");
return;
}
if (LoadManager.Instance.IsPlayBacking)
{
MessageDispatcher.SendMessage("Operatinghints", (object)"回放中,不能新建节点!");
return;
}
AddBtn.SetActive(true);
RecordManager.Instance.StartRecord();
AddRecordTag.Instance.ThisButton.enabled = true;//zzj
}
else//停止记录,保存节点
{
}
}
private bool CheckHasFireSpreading()
{
Transform pfire = GameObject.Find("pfire").transform;
foreach(Transform fire in pfire)
{
if (fire.GetComponent<FireSpreadCtrl>())
{
if (fire.GetComponent<FireSpreadCtrl>().isSpreading)
return true;
}
}
return false;
}
public List<string> NodeListName = new List<string>();
public void SaveNode()//保存记录 //新建一个节点
{
if (XinJianNodeName.text.Equals("已经有此名字") || XinJianNodeName.text == "名字不能为空")
{
XinJianNodeName.text = "";
return;
}
if (XinJianNodeName.text == "" || XinJianNodeName.text==null)
{
XinJianNodeName.text = "";
MessageDispatcher.SendMessage("Operatinghints", (object)"名字不能为空");
return;
}
if(XinJianNodeName.text.Contains("/")|| XinJianNodeName.text.Contains("\\"))
{
XinJianNodeName.text = "";
MessageDispatcher.SendMessage("Operatinghints", (object)"名字不能包含/或\\");
return;
}
bool b = XinJianNodeName.text.IndexOf("\r\n") > 0;
if (b)
{
XinJianNodeName.text = "";
MessageDispatcher.SendMessage("Operatinghints", (object)"名字不能包含回车符号");
return;
}
if (TreeViewControl__.Instance.CheckFileTreeItems())
{
JiaZaiBtn.gameObject.SetActive(true);
}
else
{
JiaZaiBtn.gameObject.SetActive(false);
}
string NodeName = XinJianNodeName.text;
string NodeIntro = XinJianIntroName.text;
string path = ExamInfoHelpClass.CurrentWorkPath;
string fileDir = Path.GetDirectoryName(path);
string ThePath = NodeName;
ShowNameText = "";
var treeItems = TreeViewControl__.Instance.TreeItems;
TreeViewname.Clear();
foreach (Transform item in treeItems)
{
if (item.GetComponentInChildren<Toggle>() && item.GetComponentInChildren<Toggle>().isOn)
{
var treeViewItem = item.GetComponent<TreeViewItem__>();
var count = treeViewItem.GetChildrenNumber();
var filepath = ExamInfoHelpClass.CurrentWorkPath + treeViewItem.Name + ".xml";
if (!File.Exists(filepath) && treeViewItem.GetHierarchy() < treeViewItem.maxHierarchy - 1)//新建节点添加到该层级下,Add即可
{
var pid = treeViewItem.ID;
ShowTheText(item);
for (int i = TreeViewname.Count - 1; i >= 0; i--)
{
ShowNameText += TreeViewname[i].ToString() + "-";
}
ShowNameText += ThePath;
if (TreeViewControl__.Instance.GetHierarchy_Name(treeViewItem.GetHierarchy(), ShowNameText))
{
MessageDispatcher.SendMessage("Operatinghints", (object)"已经有此名字");
return;
}
}
else//新建节点添加到该节点后边,需要Insert
{
var pid = treeViewItem.parentID;
ShowTheText(item);
for (int i = TreeViewname.Count - 1; i >= 0; i--)
{
ShowNameText += TreeViewname[i].ToString() + "-";
}
ShowNameText += ThePath;
if (TreeViewControl__.Instance.GetHierarchy_Name(treeViewItem.GetHierarchy(), ShowNameText))
{
MessageDispatcher.SendMessage("Operatinghints", (object)"已经有此名字");
return;
}
}
}
}
if (Directory.Exists(fileDir))
{
string[] files = Directory.GetFiles(fileDir);
foreach (string file in files)
{
string str = Path.GetFileName(file);
if (str.Equals(ShowNameText+".xml"))
{
XinJianNodeName.text = "";
MessageDispatcher.SendMessage("Operatinghints", (object)"已经有此名字");
return;
}
}
}
string filename = ExamInfoHelpClass.CurrentWorkPath + ShowNameText+ ".xml";
RecordManager.Instance.record.Intro = NodeIntro;
RecordManager.Instance.StopRecord_SerializeRecordToXML(filename, RecordManager.Instance.record);
XinJianNodeName.text = "";
XinJianIntroName.text = "";
MessageDispatcher.SendMessage("CLOSE", (object)PlaneWithRercod.name, "CUBE");
TreeViewControl__.Instance.AddNode(ShowNameText);
NodeListName.Add(NodeName + ".xml");
}
public void SaveNode_new()//保存记录 //新建一个节点
{
if (XinJianNodeName.text.Equals("已经有此名字") || XinJianNodeName.text == "名字不能为空")
{
XinJianNodeName.text = "";
return;
}
if (XinJianNodeName.text == "" || XinJianNodeName.text == null)
{
XinJianNodeName.text = "";
MessageDispatcher.SendMessage("Operatinghints", (object)"名字不能为空");
return;
}
if (XinJianNodeName.text.Contains("/") || XinJianNodeName.text.Contains("\\"))
{
XinJianNodeName.text = "";
MessageDispatcher.SendMessage("Operatinghints", (object)"名字不能包含/或\\");
return;
}
bool b = XinJianNodeName.text.IndexOf("\r\n") > 0;
if (b)
{
XinJianNodeName.text = "";
MessageDispatcher.SendMessage("Operatinghints", (object)"名字不能包含回车符号");
return;
}
string NodeName = XinJianNodeName.text;
string NodeIntro = XinJianIntroName.text;
string path = ExamInfoHelpClass.CurrentWorkPath;
string fileDir = Path.GetDirectoryName(path);
List<TreeViewData> nodeList = new List<TreeViewData>();
GetAllDates(ref nodeList);
var curNode = NodeSecondLevelControl.Instance.curNodeItem_SL;
var curParentID = TempDataManager.Instance.CurNodeID;//当前选中的一级节点的ID
if (curNode != null)
{
curParentID = curNode.GetData().ParentID;
}
var node = nodeList.Find(n =>
{
return n.ParentID == curParentID && n.Name == NodeName;
});
if (node != null)
{
XinJianNodeName.text = "";
MessageDispatcher.SendMessage("Operatinghints", (object)"已经有此名字");
return;
}
string filename = ExamInfoHelpClass.CurrentWorkPath + NodeName + ".xml";
RecordManager.Instance.record.Intro = NodeIntro;
RecordManager.Instance.StopRecord_SerializeRecordToXML(filename, RecordManager.Instance.record);
XinJianNodeName.text = "";
XinJianIntroName.text = "";
MessageDispatcher.SendMessage("CLOSE", (object)PlaneWithRercod.name, "CUBE");
NodeSecondLevelControl.Instance.AddNode(NodeName, curParentID, GetNextID());
NodeListName.Add(NodeName + ".xml");
}
/// <summary>
/// 通过键盘Arrow加载node 第一套
/// </summary>
public void KeyDownLoadNode2(int num)
{
if (TheBackView.instance.VidoSHOW.activeInHierarchy || TheBackView.instance.PictSHOW.activeInHierarchy)
{
return;
}
var list = TreeViewControl__.Instance.Data;
int Count = TempDataManager.Instance.CurNodeID;
var data = list.Find(d => { return d.ID == Count; });
int Hierarchy = data.Hierarchy;
var index = list.FindIndex(d => { return d.ID == Count; });
if (num == 1)
{
for (int i = index + 1; i < list.Count; i++)
{
var filepath = ExamInfoHelpClass.CurrentWorkPath + list[i].Name + ".xml";
if (File.Exists(filepath))
{
TheBackView.instance.ChongZhi();
string filename_ = list[i].Name + ".xml";
LoadManager.Instance.GetRecord_Load(filename_);
RecordFileName = filename_;
TreeViewControl__.Instance.SetToggleTrue(list[i].ID);
TempDataManager.Instance.CurNodeID = list[i].ID;
ShowNameText = "";
TreeViewname.Clear();
ShowNameText = TreeViewControl__.Instance.GetToggleGame().transform.GetComponent<TreeViewItem__>().Name;
MessageDispatcher.SendMessage("NodeLoadHints", (object)ShowNameText);
return;
}
}
}
else
{
for (int i = index - 1; i >= 0; i--)
{
var filepath = ExamInfoHelpClass.CurrentWorkPath + list[i].Name + ".xml";
if (File.Exists(filepath))
{
TheBackView.instance.ChongZhi();
string filename_ = list[i].Name + ".xml";
LoadManager.Instance.GetRecord_Load(filename_);
RecordFileName = filename_;
TreeViewControl__.Instance.SetToggleTrue(list[i].ID);
TempDataManager.Instance.CurNodeID = list[i].ID;
ShowNameText = "";
TreeViewname.Clear();
ShowNameText = TreeViewControl__.Instance.GetToggleGame().transform.GetComponent<TreeViewItem__>().Name;
MessageDispatcher.SendMessage("NodeLoadHints", (object)ShowNameText);
return;
}
}
}
}
// <summary>
/// 通过键盘Arrow加载node 第二套
/// </summary>
//public void KeyDownLoadNode2(int num)
//{
// if (TheBackView.instance.VidoSHOW.activeInHierarchy || TheBackView.instance.PictSHOW.activeInHierarchy)
// {
// return;
// }
// int CurID = TempDataManager.Instance.CurNodeID;
// GameObject chose = NodeSecondLevelControl.Instance.GetToggleGame();
// int index = chose.transform.GetSiblingIndex();
// GameObject Next = NodeSecondLevelControl.Instance.CheckGetSiblingIndex(index + num);
// if (Next != null)//如果当前选中的下一个不是空物体设置为选中状态
// {
// Next.GetComponent<Toggle>().isOn = true;
// }
// else//如果当前选中的下一个是空物体,展示下一个一级节点
// {
// GameObject OneLevel = HorizontalTreeSet.instance_.GetChoseToggle(num);
// if (OneLevel != null)
// {
// NodeSecondLevelControl.Instance.GetFather().GetComponent<Toggle>().isOn = true;
// }
// }
//}
/// <summary>
/// 关闭所有选中状态
/// </summary>
public void CLOSEALLToggle()
{
foreach (Transform child in NodeFather.transform) //遍历谁被勾选
{
if (child.Find("Toggle").GetComponent<Toggle>().isOn)
{
child.Find("Toggle").GetComponent<Toggle>().isOn = false;
}
}
}
/// <summary>
/// 检查有没有选中的节点
/// </summary>
public GameObject checkToggle()
{
foreach (Transform child in NodeFather.transform) //遍历谁被勾选
{
if (child.Find("Toggle").GetComponent<Toggle>().isOn)
{
return child.gameObject;
}
}
return null;
}
public void Back()
{
MySceneManager.BackToLastScene();
}
public void ClosePlaneWithRercod()//取消记录的保存
{
MessageDispatcher.SendMessage("CLOSE", (object)PlaneWithRercod.name, "CUBE");
GameObject TipWindow = Instantiate(Resources.Load<GameObject>("UIPrefab/TipWindow"));
TipWindow.GetComponent<TipWindowManager>().SetWindow(
"是否放弃此条记录?", new UnityEngine.Events.UnityAction(OKSubmit), new UnityEngine.Events.UnityAction(NOSubmit));
}
public void OKSubmit()
{
XinJianText.text = "新建记录";
RecordManager.Instance.IsRecording = false;
AddBtn.SetActive(false);
XinJianNodeName.text = "";
XinJianIntroName.text = "";
if (TreeViewControl__.Instance.CheckFileTreeItems())
{
JiaZaiBtn.gameObject.SetActive(true);
}
else
{
JiaZaiBtn.gameObject.SetActive(false);
}
}
public void NOSubmit()
{
XinJianText.text = "停止记录";
JiaZaiBtn.gameObject.SetActive(false);
RecordManager.Instance.IsPause = false;
XinJianNodeName.text = "";
XinJianIntroName.text = "";
AddBtn.SetActive(true);
}
string TheFilePath;
public string RecordFileName;//用于修改标签简介时候的路径
public void LoadNode()//加载记录方法
{
//********************原来的加在节点的方法***********************
//bool hasIson = false;
//foreach (Transform child in NodeFather.transform)
//{
// if (child.Find("Toggle").GetComponent<Toggle>().isOn)
// {
// hasIson = true;
// }
//}
//if (!hasIson)
//{
// MessageDispatcher.SendMessage("Operatinghints", (object)"请勾选节点加载");
// return;
//}
//CheckPath();
//TheBackView.instance.ChongZhi();
//GameObject.Find("Canvas").transform.Find("时间轴").gameObject.SetActive(true);
//foreach (Transform child in NodeFather.transform)
//{
// if (child.Find("Toggle").GetComponent<Toggle>().isOn)
// {
// string filename_ =child.name + ".xml";
// LoadRecordFromFile(filename_);
// RecordFileName = filename_;
// if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.MakeScore)
// {
// GameObject.Find("Canvas").transform.Find("AddTag").gameObject.SetActive(true);
// }
// }
//}
//***************结束*****************************************
//record_Load = TrackRecordHelpClass.LoadRecord_DeserializeXMLToRecord(filename);
//GameObject
//**********************新的方法**********************
var treeItems = TreeViewControl__.Instance.TreeItems;
if (TreeViewControl__.Instance.HasItemSelected() < 0)
{
MessageDispatcher.SendMessage("Operatinghints", (object)"请勾选节点加载");
return;
}
Transform Trager = GameObject.Find("target").transform; Trager.transform.parent = null;
TheBackView.instance.ChongZhi();
//GameObject.Find("Canvas").transform.Find("时间轴").gameObject.SetActive(true);
foreach (Transform item in treeItems)
{
if(item.GetComponentInChildren<Toggle>() && item.GetComponentInChildren<Toggle>().isOn)
{
var treeviewItem = item.GetComponent<TreeViewItem__>();
string filename_ = treeviewItem.Name + ".xml";
//LoadRecordFromFile(filename_);
LoadManager.Instance.GetRecord_Load(filename_);
RecordFileName = filename_;
ShowNameText = "";
TreeViewname.Clear();
ShowTheText(item);
for (int i = TreeViewname.Count-1; i >= 0; i--)
{
ShowNameText += TreeViewname[i].ToString()+"-";
}
string STR;
if (treeviewItem.Name.Contains("-"))
{
string[] str = treeviewItem.Name.Split('-');
STR= str[str.Length - 1];
}
else
{
STR = treeviewItem.Name;
}
ShowNameText += STR;
MessageDispatcher.SendMessage("NodeLoadHints", (object)ShowNameText);
TempDataManager.Instance.CurNodeID = treeviewItem.ID;
}
}
}
/// <summary>
/// 点击显示节点信息后开始加载节点
/// </summary>
public void BecauseClickLoadNode()
{
if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.EditCourceware)
{
GameObject.Find("Canvas").transform.Find("AddTag").gameObject.SetActive(true);
}
GameObject.Find("Canvas").transform.Find("时间轴").gameObject.SetActive(true);
LoadManager.Instance.StartPlayBack(RecordFileName);
}
string ShowNameText = "";
List<string> TreeViewname = new List<string>();
public void ShowTheText(Transform item)
{
var parent=item.GetComponent<TreeViewItem__>().GetParent();
if (parent != null)
{
if (parent.GetHierarchy() > 0)
{
TreeViewname.Add(parent.Name);
ShowTheText(parent.transform);
}
}
}
//public void SendNodeMessage()
//{
// GameObject Node = GameObject.Find("Canvas").transform.Find("NodeMessage").gameObject;
// Node.SetActive(true);
// Node.GetComponent<Animator>().Play("QIShow");
// Node.transform.Find("Viewport/Content").GetComponent<Text>().text = LoadManager.Instance.record_Load.Intro;
//}
public void CheckPath()
{
if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.PrepareMode)
{
ExamInfoHelpClass.CurrentWorkPath = ExamInfoHelpClass.CurrentWorkPath + "Temporaryfile/";
}
else if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.EditCourceware)
{
}
else if (ExamInfoHelpClass.loadSceneMode == ExamInfoHelpClass.LoadSceneMode.PrepareModeLook)
{
}
}
public void LoadRecordFromFile(string filename)
{
//GameObject.Find("Canvas").transform.Find("时间轴").gameObject.SetActive(true);
//LoadManager.Instance.StartPlayBack(filename);
}
private GameObject GameNode;
public void GetMessageNode(GameObject game) //点击删除和编辑预设传来的当前预设
{
//************原来的方法****************
//GameNode = game;
//if (this.transform.Find("NodeIntroShowWin").gameObject.activeInHierarchy)
//{
// NodeNameWithRecord.text = GameNode.GetComponent<NodePrefabController>().name;
// string filename_ = GameNode.name + ".xml";
// Record_One_root recordLoad = TrackRecordHelpClass.LoadRecord_DeserializeXMLToRecord(filename_);
// NodeIntroWithRecord.text = recordLoad.Intro;
//}
//****************结束*****************
//*************新方法******************
GameNode = game;
if (this.transform.parent.Find("NodeIntroShowWin").gameObject.activeInHierarchy)
{
NodeNameWithRecord.text = GameNode.GetComponent<TreeViewItem__>().Name;
string filename_ = NodeNameWithRecord.text + ".xml";
var filepath = ExamInfoHelpClass.CurrentWorkPath + filename_;
if (File.Exists(filepath))
{
LoadManager.Instance.record_Load = null;
LoadManager.Instance.record_Load = TrackRecordHelpClass.LoadRecord_DeserializeXMLToRecord(filename_);
NodeIntroWithRecord.text = LoadManager.Instance.record_Load.Intro;
}
else
{
NodeIntroWithRecord.text = "";
}
}
//*************结束*******************
}
public void DelectNode()//删除节点方法
{
string path = ExamInfoHelpClass.CurrentWorkPath;
string fileDir = Path.GetDirectoryName(path);
string ThePath = GameNode.name+".xml";
if (Directory.Exists(fileDir))
{
string[] files = Directory.GetFiles(fileDir);
foreach (string file in files)
{
string str = Path.GetFileName(file);
if (str.Equals(ThePath))
{
File.Delete(file);
}
}
}
DelXml(GameNode.name);
Destroy(GameNode);
string str_ = "AskDeslectNode";
NodeListName.Remove(ThePath);
MessageDispatcher.SendMessage("CLOSE", (object)str_, "CUBE");
}
public void EditNode()//编辑节点方法
{
if (NodeNameWithRecord.text.Equals("已经有此名字") || NodeNameWithRecord.text == "名字不能为空")
{
return;
}
if (NodeNameWithRecord.text == "" || NodeNameWithRecord.text == null)
{
NodeNameWithRecord.text = "名字不能为空";
return;
}
string Name = NodeNameWithRecord.text;
string Intro = NodeIntroWithRecord.text;
string fileDir = Path.GetDirectoryName(ExamInfoHelpClass.CurrentWorkPath);
string ThePath = Name + ".xml";
//判断新编辑的有没有重复的名字
if (Directory.Exists(fileDir))
{
string[] files = Directory.GetFiles(fileDir);
foreach (string file in files)
{
string str = Path.GetFileName(file);
if (str.Equals(ThePath))
{
Debug.Log(file);
NodeNameWithRecord.text = "已经有此名字";
return;
}
}
}
//***********************原来的方法*************************
////修改课件名称
//string name = GameNode.name + ".xml";
//if (Directory.Exists(fileDir))
//{
// string[] files = Directory.GetFiles(fileDir);
// foreach (string file in files)
// {
// string str = Path.GetFileName(file);
// Debug.Log(Path.GetPathRoot(file));
// if (str.Equals(name))
// {
// File.Move(ExamInfoHelpClass.CurrentWorkPath + str, ExamInfoHelpClass.CurrentWorkPath+ Name + ".xml");
// }
// }
//}
//ChangeXml(GameNode.name, Name);
//int ZID = GameNode.GetComponent<NodePrefabController>().FatherID;
//int JID = GameNode.GetComponent<NodePrefabController>().id;
////string str_= "NodeIntroShowWin";
//GameNode.transform.Find("Name").GetComponent<Text>().text = Name;
//GameNode.name=Name;
//GameNode.GetComponent<NodePrefabController>().Intro = Intro;
//*********************结束************************
//***************新方法***************************
var treeViewItem = GameNode.GetComponent<TreeViewItem__>();
var oriFile = ExamInfoHelpClass.CurrentWorkPath + treeViewItem.Name + ".xml";
if (File.Exists(oriFile))
{
// LoadManager.Instance.record_Load.Intro = Intro;
//File.Move(oriFile, ExamInfoHelpClass.CurrentWorkPath + Name + ".xml");
// RecordManager.Instance.StopRecord_SerializeRecordToXML(ExamInfoHelpClass.CurrentWorkPath+Name + ".xml", LoadManager.Instance.record_Load);
var destFile = ExamInfoHelpClass.CurrentWorkPath + Name + ".xml";
EditXML_Name_Intro(oriFile, destFile, Intro);
if (File.Exists(destFile))
{
File.Delete(oriFile);
}
}
ChangeXml_(treeViewItem.ID.ToString(), Name);
GameNode.transform.Find("TreeViewText").GetComponent<Text>().text = Name;
treeViewItem.Name = Name;
//Data中的数据也的变
var data = TreeViewControl__.Instance.Data.Find(d => { return d.ID == treeViewItem.ID; });
data.Name = Name;
// GameNode.GetComponent<NodePrefabController>().Intro = Intro;
//***************结束***************************
if (NodeListName.Contains(name))
{
NodeListName.Remove(name);
}
NodeListName.Add(Name + ".xml");
MessageDispatcher.SendMessage("CLOSE", (object)"NodeIntroShowWin", "CUBE");
}
private InputField NewFuGaiName;
private InputField NewFuGaiIntro;
//只有评分模块允许在回放记录时添加标签,添加评分
public void NewFuGaiNodeShowWin()//回放中添加标签需要保存新的文件
{
string NodeName = XinJianNodeName.text;
string NodeIntro = XinJianIntroName.text;
string filename = "score/"+TrackRecordHelpClass.GetFileNameAccordingTime(DateTime.Now);//待确定
RecordManager.Instance.StopRecord_SerializeRecordToXML(filename, RecordManager.Instance.record);//另存为一份新的轨迹记录文件,作为考卷评价
}
public void AwakeOnDestroy()
{
//string path = ExamInfoHelpClass.CurrentWorkPath;
//string fileDir = Path.GetDirectoryName(path);
//if (Directory.Exists(fileDir))
//{
// string[] files = Directory.GetFiles(path);
// foreach (string file in files)
// {
// File.Delete(file);
// }
//}
}
void OnDestroy()
{
MessageDispatcher.RemoveListener("SpaceControl", SpacnControl);
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);
}
}
}
#region XML控制相关
/// <summary>
/// 添加一条新的xml数据
/// </summary>
/// <param name="nodename"></param>
public void ADDXml(string nodename)
{
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Name")
{
XmlElement jiedian = xmlDoc.CreateElement("Node");
jiedian.InnerText = nodename;
elem.AppendChild(jiedian);
root.AppendChild(elem);
}
}
xmlDoc.AppendChild(root);
xmlDoc.Save(filepath);
}
}
public int GetNextID()
{
int result = 0;
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "NextID")
{
result = int.Parse(elem.InnerText);
elem.InnerText = (result + 1).ToString();
}
}
xmlDoc.Save(filepath);
}
return result;
}
public void ADDXml(string nodename, TreeViewData data)
{
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Nodes")
{
XmlElement jiedian = xmlDoc.CreateElement("Node");
jiedian.InnerText = nodename;
jiedian.SetAttribute("ID", data.ID.ToString());
jiedian.SetAttribute("ParentID", data.ParentID.ToString());
jiedian.SetAttribute("Name", data.Name.ToString());
jiedian.SetAttribute("Hierarchy", data.Hierarchy.ToString());
elem.AppendChild(jiedian);
root.AppendChild(elem);
}
}
xmlDoc.AppendChild(root);
xmlDoc.Save(filepath);
}
}
public void InsertXml(string id, TreeViewData data)
{
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Nodes")
{
foreach (XmlElement node in elem.ChildNodes)
{
if (node.GetAttribute("ID") == id)
{
XmlElement jiedian = xmlDoc.CreateElement("Node");
jiedian.InnerText = data.Name;
jiedian.SetAttribute("ID", data.ID.ToString());
jiedian.SetAttribute("ParentID", data.ParentID.ToString());
jiedian.SetAttribute("Name", data.Name.ToString());
jiedian.SetAttribute("Hierarchy", data.Hierarchy.ToString());
//elem.AppendChild(jiedian);
elem.InsertAfter(jiedian, node);
}
}
}
}
xmlDoc.Save(filepath);
}
}
public void DeleteXml(List<int> needDeleteList)
{
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Nodes")
{
for (int i = elem.ChildNodes.Count - 1; i >= 0; i--)
{
var node = elem.ChildNodes[i] as XmlElement;
if (needDeleteList.Contains(int.Parse(node.GetAttribute("ID"))))
{
var fp = ExamInfoHelpClass.CurrentWorkPath + node.GetAttribute("Name") + ".xml";
if (File.Exists(fp))
{
File.Delete(fp);
}
node.RemoveAll();
elem.RemoveChild(node);
}
}
break;
}
}
xmlDoc.Save(filepath);
}
}
public void GetAllDates(ref List<TreeViewData> datas)
{
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Nodes")
{
foreach (XmlElement node in elem.ChildNodes)
{
TreeViewData data = new TreeViewData();
data.ID = int.Parse(node.GetAttribute("ID"));
data.Name = node.GetAttribute("Name");
data.ParentID = int.Parse(node.GetAttribute("ParentID"));
data.Hierarchy = int.Parse(node.GetAttribute("Hierarchy"));
datas.Add(data);
}
}
}
}
}
/// <summary>
/// 插入一条新的xml数据
/// </summary>
/// <param name="nodename"></param>
public void InserXml(string nodename, string chosename)
{
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Name")
{
foreach (XmlElement node in elem)
{
if (node.Name == "Node" && node.InnerText == chosename)
{
XmlElement jiedian = xmlDoc.CreateElement("Node");
jiedian.InnerText = nodename;
elem.AppendChild(jiedian);
elem.InsertAfter(jiedian, node);
}
}
}
}
xmlDoc.Save(filepath);
}
}
/// <summary>
/// 修改一条xml数据
/// </summary>
/// <param name="nodename"></param>
public void ChangeXml(string nodename, string newname)
{
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Name")
{
foreach (XmlElement node in elem)
{
if (node.Name == "Node" && node.InnerText == nodename)
{
node.InnerText = newname;
}
}
}
}
xmlDoc.Save(filepath);
}
}
public void EditXML_Name_Intro(string oriFile,string destFile,string intro)
{
if (File.Exists(oriFile))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(oriFile);
XmlNode root = xmlDoc.SelectSingleNode("Record_One_root");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Intro")
{
elem.InnerText = intro;
}
}
xmlDoc.Save(destFile);
}
}
public void ChangeXml_(string id, string newname)
{
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Nodes")
{
foreach (XmlElement node in elem.ChildNodes)
{
if (node.GetAttribute("ID") == id)
{
node.InnerText = newname;
node.SetAttribute("Name", newname);
break;
}
}
}
}
xmlDoc.Save(filepath);
}
}
/// <summary>
/// 拖动修改xml数据位置
/// </summary>
/// after=true choseid为选中拖动的id,ID为拖动到对应位置的ID
XmlElement ChoseXml;
XmlElement IDXml;
public void TranslocationXML(string Choseid, string ID, bool after)
{
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Nodes")
{
foreach (XmlElement node in elem.ChildNodes)
{
if (node.GetAttribute("ID") == Choseid)
{
ChoseXml = node;
break;
}
}
foreach (XmlElement node in elem.ChildNodes)
{
if (node.GetAttribute("ID") == ID)
{
IDXml = node;
break;
}
}
if (after)
{
elem.InsertAfter(ChoseXml, IDXml);
}
else
{
elem.InsertBefore(ChoseXml, IDXml);
}
}
}
xmlDoc.Save(filepath);
}
}
/// <summary>
/// 删除一条xml数据
/// </summary>
public void DelXml(string nodename)
{
string filepath = ExamInfoHelpClass.NameListWorkPath;
if (File.Exists(filepath))
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlNode root = xmlDoc.SelectSingleNode("NodeNameList");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlElement elem in nodeList)
{
if (elem.Name == "Name")
{
foreach (XmlElement node in elem)
{
if (node.Name == "Node" && node.InnerText == nodename)
{
node.RemoveAll();
elem.RemoveChild(node);
break;
}
}
break;
}
}
xmlDoc.Save(filepath);
}
}
#endregion
}