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.
1698 lines
147 KiB
1698 lines
147 KiB
using UnityEngine; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.Xml; |
|
using System.IO; |
|
using System.Text; |
|
|
|
public class xmlManager : MonoBehaviour |
|
{ |
|
public static xmlManager Instance; |
|
|
|
public GameObject SGCmodel;//消防车模型 |
|
|
|
private int CengID = 0; |
|
private Vector3 placementRot;//方向 |
|
private Vector3 placementSca;//大小 |
|
private Vector3 placementPos;//坐标 |
|
private Vector3 placementRotBi;//Bi方向 |
|
private Vector3 placementScaBi;//Bi大小 |
|
private Vector3 placementPosBi;//Bi坐标 |
|
private Vector3 placementRotBi1;//Bi1方向 |
|
private Vector3 placementScaBi1;//Bi1大小 |
|
private Vector3 placementPosBi1;//Bi1坐标 |
|
private Vector3 placementRotBi2;//Bi2方向 |
|
private Vector3 placementScaBi2;//Bi2大小 |
|
private Vector3 placementPosBi2;//Bi2坐标 |
|
private Vector3 placementRotBi3;//Bi3方向 |
|
private Vector3 placementScaBi3;//Bi3大小 |
|
private Vector3 placementPosBi3;//Bi3坐标 |
|
private Vector3 placementRotBi4;//Bi4方向 |
|
private Vector3 placementScaBi4;//Bi4大小 |
|
private Vector3 placementPosBi4;//Bi4坐标 |
|
private Vector3 placementRotBi5;//Bi5方向 |
|
private Vector3 placementScaBi5;//Bi5大小 |
|
private Vector3 placementPosBi5;//Bi5坐标 |
|
private Vector3 placementRotBi6;//Bi6方向 |
|
private Vector3 placementScaBi6;//Bi6大小 |
|
private Vector3 placementPosBi6;//Bi6坐标 |
|
private Vector3 placementRotpt;//pt方向 |
|
private Vector3 placementScapt;//pt大小 |
|
private Vector3 placementPospt;//pt坐标 |
|
private Vector3 placementRotptou;//ptou方向 |
|
private Vector3 placementScaptou;//ptou大小 |
|
private Vector3 placementPosptou;//ptou坐标 |
|
private Vector3 placementRotHose;//Hose方向 |
|
private Vector3 placementScaHose;//Hose大小 |
|
private Vector3 placementPosHose;//Hose坐标 |
|
private bool Hoseactive = false; |
|
private int Risenum; |
|
private int MaxRise; |
|
private ArrayList BoolList; |
|
private float scale = 1.0f; |
|
private string name_; |
|
private string topname; |
|
private string taskname; |
|
private string infoPlane_scaleX = ""; |
|
private GameObject prlineObj = null; |
|
|
|
[HideInInspector] |
|
public string xmlname = "";//选择任务的xml名称 |
|
Vector3 p = Vector3.zero, r = Vector3.zero, s = new Vector3(1, 1, 1); |
|
|
|
void Awake() |
|
{ |
|
if (Instance == null) |
|
{ |
|
Instance = this; |
|
} |
|
} |
|
|
|
public string[] GetServerIP() |
|
{ |
|
string[] info = new string[3]; |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + "ServerIP.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "ip") |
|
{ |
|
info[0] = elem.InnerText; |
|
} |
|
if (elem.Name == "username") |
|
{ |
|
info[1] = elem.InnerText; |
|
} |
|
if (elem.Name == "password") |
|
{ |
|
info[2] = elem.InnerText; |
|
} |
|
} |
|
return info; |
|
} |
|
return null; |
|
} |
|
public void SetJieDianCount(string path, string cjid, int zqid, int count) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in zq) |
|
{ |
|
if (x1.Name == "jiedianCount") |
|
{ |
|
x1.InnerText = count.ToString(); |
|
break; |
|
} |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
public bool FindTheName(string path, string name, string cjid, int zqid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement jd in zq.ChildNodes) |
|
{ |
|
if (jd.GetAttribute("name") == name) |
|
{ |
|
return true; |
|
} |
|
} |
|
} |
|
|
|
} |
|
} |
|
} |
|
|
|
} |
|
return false; |
|
} |
|
public void SetJieDianContent(string cjid, int zqid, int id, string jdcontent) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + "jiedian.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in zq.ChildNodes) |
|
{ |
|
if (x1.Name == "jiedian" && x1.GetAttribute("id") == id.ToString()) |
|
{ |
|
foreach (XmlElement x2 in x1) |
|
{ |
|
if (x2.Name == "JDContent") |
|
{ |
|
x2.InnerText = jdcontent; |
|
xmlDoc.Save(filepath); |
|
|
|
} |
|
} |
|
|
|
} |
|
} |
|
|
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
public void SetZaiQingCount(string cjid, int count) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + "NodeRecord.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem) |
|
{ |
|
|
|
if (zq.Name == "zaiqingCount") |
|
{ |
|
zq.InnerText = count.ToString(); |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
/** |
|
* 覆盖 |
|
*/ |
|
public void FuGaiJieDian(string cjid, int zaiqingid, int JieDianid, string Name, string Intro, string xml) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + "NodeRecord.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem) |
|
{ |
|
|
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zaiqingid.ToString()) |
|
{ |
|
foreach (XmlElement jd in zq) |
|
{ |
|
if (jd.Name == "jiedian" && jd.GetAttribute("id") == JieDianid.ToString()) |
|
{ |
|
jd.SetAttribute("name", Name); |
|
jd.SetAttribute("filename", xml); |
|
foreach (XmlElement x1 in jd) |
|
{ |
|
if (x1.Name == "JDIntro") |
|
{ |
|
x1.InnerText = Intro; |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
public void SetJieDianID(string cjid, int zqid, int jdid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + "NodeRecord.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
|
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement jd in zq.ChildNodes) |
|
{ |
|
if (jd.Name == "jiedian") |
|
{ |
|
|
|
string jiedianID = jd.GetAttribute("id"); |
|
int intid = int.Parse(jiedianID); |
|
if (intid > jdid) |
|
{ |
|
jd.SetAttribute("id", (intid + 1).ToString()); |
|
jd.SetAttribute("filename", (intid + 1).ToString() + ".xml"); |
|
} |
|
|
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
} |
|
|
|
} |
|
public int GetJieDianCount(string path, string cjid, int zqid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in zq.ChildNodes) |
|
{ |
|
if (x1.Name == "jiedianCount") |
|
{ |
|
int jdc = int.Parse(x1.InnerText); |
|
return jdc; |
|
} |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
|
|
} |
|
} |
|
return -1; |
|
} |
|
|
|
|
|
public int GetZaiQingCount(string cjid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + "NodeRecord.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqingCount") |
|
{ |
|
int zqc = int.Parse(zq.InnerText); |
|
return zqc; |
|
} |
|
} |
|
|
|
} |
|
} |
|
} |
|
return 0; |
|
} |
|
|
|
|
|
public string GetJieDianIntro(string path, string cjid, int zqid, int id) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in zq.ChildNodes) |
|
{ |
|
if (x1.Name == "jiedian" && x1.GetAttribute("id") == id.ToString()) |
|
{ |
|
foreach (XmlElement x2 in x1.ChildNodes) |
|
{ |
|
if (x2.Name == "JDIntro") |
|
{ |
|
return x2.InnerText; |
|
} |
|
} |
|
//break; |
|
} |
|
} |
|
} |
|
// break; |
|
} |
|
} |
|
|
|
} |
|
} |
|
return "False!"; |
|
} |
|
public string GetZaiQingIntro(string cjid, int zqid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + "NodeRecord.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in zq) |
|
{ |
|
if (x1.Name == "ZQIntro") |
|
{ |
|
return x1.InnerText; |
|
} |
|
} |
|
//break; |
|
} |
|
} |
|
} |
|
} |
|
|
|
} |
|
return "False!"; |
|
} |
|
public string GetJieDianFilename(string path, string cjid, int zqid, int id) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in zq) |
|
{ |
|
if (x1.Name == "jiedian" && x1.GetAttribute("id") == id.ToString()) |
|
{ |
|
return x1.GetAttribute("filename"); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return "Not Found!"; |
|
} |
|
return "False!"; |
|
} |
|
public string GetJieDianName(string path, string cjid, int zqid, int id) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in zq) |
|
{ |
|
if (x1.Name == "jiedian" && x1.GetAttribute("id") == id.ToString()) |
|
{ |
|
return x1.GetAttribute("name"); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return "Not Found!"; |
|
} |
|
return "False!"; |
|
} |
|
public string GetJieDianContent(string cjid, int zqid, int id) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + "jiedian.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in zq) |
|
{ |
|
if (x1.Name == "jiedian" && x1.GetAttribute("id") == id.ToString()) |
|
{ |
|
foreach (XmlElement x2 in x1) |
|
{ |
|
if (x2.Name == "JDContent") |
|
{ |
|
return x2.InnerText; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
} |
|
|
|
return "False!"; |
|
|
|
|
|
} |
|
public string GetZaiQingName(string cjid, int zqid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + "NodeRecord.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
return zq.GetAttribute("name"); |
|
} |
|
} |
|
} |
|
|
|
} |
|
return "Not Found!"; |
|
} |
|
else |
|
{ |
|
return "False!"; |
|
} |
|
} |
|
|
|
public void creatPos_Rot(XmlDocument xmlDoc, Transform trans, XmlElement elem) |
|
{ |
|
//存储坐标 |
|
XmlElement elmPos = xmlDoc.CreateElement("position"); |
|
elem.AppendChild(elmPos); |
|
XmlElement position_X = xmlDoc.CreateElement("x"); |
|
position_X.InnerText = trans.position.x + ""; |
|
elmPos.AppendChild(position_X); |
|
XmlElement position_Y = xmlDoc.CreateElement("y"); |
|
position_Y.InnerText = trans.position.y + ""; |
|
elmPos.AppendChild(position_Y); |
|
XmlElement position_Z = xmlDoc.CreateElement("z"); |
|
position_Z.InnerText = trans.position.z + ""; |
|
elmPos.AppendChild(position_Z); |
|
|
|
//存储方向 |
|
XmlElement elmRot = xmlDoc.CreateElement("rotation"); |
|
elem.AppendChild(elmRot); |
|
XmlElement rotation_X = xmlDoc.CreateElement("x"); |
|
rotation_X.InnerText = trans.localEulerAngles.x + ""; |
|
elmRot.AppendChild(rotation_X); |
|
XmlElement rotation_Y = xmlDoc.CreateElement("y"); |
|
rotation_Y.InnerText = trans.localEulerAngles.y + ""; |
|
elmRot.AppendChild(rotation_Y); |
|
XmlElement rotation_Z = xmlDoc.CreateElement("z"); |
|
rotation_Z.InnerText = trans.localEulerAngles.z + ""; |
|
elmRot.AppendChild(rotation_Z); |
|
|
|
//存储大小 |
|
XmlElement elmSca = xmlDoc.CreateElement("scale"); |
|
elem.AppendChild(elmSca); |
|
XmlElement scale_X = xmlDoc.CreateElement("x"); |
|
scale_X.InnerText = trans.localScale.x + ""; |
|
elmSca.AppendChild(scale_X); |
|
XmlElement scale_Y = xmlDoc.CreateElement("y"); |
|
scale_Y.InnerText = trans.localScale.y + ""; |
|
elmSca.AppendChild(scale_Y); |
|
XmlElement scale_Z = xmlDoc.CreateElement("z"); |
|
scale_Z.InnerText = trans.localScale.z + ""; |
|
elmSca.AppendChild(scale_Z); |
|
} |
|
public void SetCameraFromNodeData(string path, string cjid, int zqid, int jdid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + path; |
|
string id = jdid.ToString(); |
|
if (File.Exists(filepath)) |
|
{ |
|
|
|
XmlDocument xmlDoc = new XmlDocument(); |
|
//根据路径将XML读取出来 |
|
xmlDoc.Load(filepath); |
|
XmlNodeList nodeList = xmlDoc.SelectSingleNode("assets").ChildNodes; |
|
//遍历所有关卡 |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement jiedian in zq) |
|
{ |
|
if (jiedian.Name == "jiedian" && jiedian.GetAttribute("id") == id) |
|
{ |
|
foreach (XmlElement xe in jiedian.ChildNodes) |
|
{ |
|
if (xe.Name == "Camera") |
|
{ |
|
Transform camera = GameObject.Find("Main Camera").transform; |
|
Transform target = GameObject.Find("xinShengjiangti").transform; |
|
//继续遍历 |
|
foreach (XmlElement x2 in xe.ChildNodes) |
|
{ |
|
if (x2.Name == "target") |
|
{ |
|
foreach (XmlElement x3 in x2.ChildNodes) |
|
{ |
|
if (x3.Name == "x") |
|
{ |
|
placementPos.x = float.Parse(x3.InnerText); |
|
} |
|
if (x3.Name == "y") |
|
{ |
|
placementPos.y = float.Parse(x3.InnerText); |
|
} |
|
if (x3.Name == "z") |
|
{ |
|
placementPos.z = float.Parse(x3.InnerText); |
|
} |
|
} |
|
target.position = placementPos; |
|
} |
|
//if (x2.Name == "x") |
|
//{ |
|
// camera.gameObject.GetComponent<MouseFollowRotation>().x = float.Parse(x2.InnerText); |
|
//} |
|
//if (x2.Name == "y") |
|
//{ |
|
// camera.gameObject.GetComponent<MouseFollowRotation>().y = float.Parse(x2.InnerText); |
|
//} |
|
if (x2.Name == "distance") |
|
{ |
|
camera.gameObject.GetComponent<MouseFollowRotation>().distance = float.Parse(x2.InnerText); |
|
} |
|
if (x2.Name == "position") |
|
{ |
|
foreach (XmlElement x3 in x2.ChildNodes) |
|
{ |
|
if (x3.Name == "x") |
|
{ |
|
placementPos.x = float.Parse(x3.InnerText); |
|
} |
|
if (x3.Name == "y") |
|
{ |
|
placementPos.y = float.Parse(x3.InnerText); |
|
} |
|
if (x3.Name == "z") |
|
{ |
|
placementPos.z = float.Parse(x3.InnerText); |
|
} |
|
} |
|
} |
|
if (x2.Name == "rotation") |
|
{ |
|
foreach (XmlElement x3 in x2.ChildNodes) |
|
{ |
|
if (x3.Name == "x") |
|
{ |
|
placementRot.x = float.Parse(x3.InnerText); |
|
} |
|
if (x3.Name == "y") |
|
{ |
|
placementRot.y = float.Parse(x3.InnerText); |
|
} |
|
if (x3.Name == "z") |
|
{ |
|
placementRot.z = float.Parse(x3.InnerText); |
|
} |
|
} |
|
} |
|
} |
|
|
|
camera.position = placementPos; |
|
camera.localEulerAngles = placementRot; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
public void CreatNodeElement(string path, string cjid, int zqid, int jdid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
|
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x in zq) |
|
{ |
|
if (x.Name == "jiedianCount") |
|
{ |
|
x.InnerText = jdid.ToString(); |
|
break; |
|
} |
|
} |
|
|
|
XmlElement jiedian = xmlDoc.CreateElement("jiedian"); |
|
jiedian.SetAttribute("id", jdid.ToString()); |
|
zq.AppendChild(jiedian); |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
bool ExistNodeWithID(string path, string cjid, int zqid, int jdid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
|
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
|
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement jd in zq.ChildNodes) |
|
{ |
|
if (jd.Name == "jiedian" && jd.GetAttribute("id") == jdid.ToString()) |
|
{ |
|
return true; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
public void RecordCamera(string path, string cjid, int zqid, int jdid, int id) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
if (!ExistNodeWithID(path, cjid, zqid, jdid)) |
|
{ |
|
CreatNodeElement(path, cjid, zqid, jdid); |
|
} |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
|
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement jd in zq.ChildNodes) |
|
{ |
|
if (jd.Name == "jiedian" && jd.GetAttribute("id") == jdid.ToString()) |
|
{ |
|
XmlElement camera = xmlDoc.CreateElement("Camera"); |
|
camera.SetAttribute("id", id.ToString()); |
|
jd.AppendChild(camera); |
|
Transform mainCamera = GameObject.Find("Main Camera").transform; |
|
//存储x,y |
|
XmlElement x = xmlDoc.CreateElement("x"); |
|
x.InnerText = mainCamera.gameObject.GetComponent<MouseFollowRotation>().x.ToString(); |
|
camera.AppendChild(x); |
|
XmlElement y = xmlDoc.CreateElement("y"); |
|
y.InnerText = mainCamera.gameObject.GetComponent<MouseFollowRotation>().y.ToString(); |
|
camera.AppendChild(y); |
|
//存储坐标 |
|
XmlElement elmPos1 = xmlDoc.CreateElement("position"); |
|
XmlElement position_X1 = xmlDoc.CreateElement("x"); |
|
position_X1.InnerText = mainCamera.position.x + ""; |
|
XmlElement position_Y1 = xmlDoc.CreateElement("y"); |
|
position_Y1.InnerText = mainCamera.position.y + ""; |
|
XmlElement position_Z1 = xmlDoc.CreateElement("z"); |
|
position_Z1.InnerText = mainCamera.position.z + ""; |
|
elmPos1.AppendChild(position_X1); |
|
elmPos1.AppendChild(position_Y1); |
|
elmPos1.AppendChild(position_Z1); |
|
camera.AppendChild(elmPos1); |
|
|
|
//存储方向 |
|
XmlElement elmRot1 = xmlDoc.CreateElement("rotation"); |
|
XmlElement rotation_X1 = xmlDoc.CreateElement("x"); |
|
rotation_X1.InnerText = mainCamera.localEulerAngles.x + ""; |
|
XmlElement rotation_Y1 = xmlDoc.CreateElement("y"); |
|
rotation_Y1.InnerText = mainCamera.localEulerAngles.y + ""; |
|
XmlElement rotation_Z1 = xmlDoc.CreateElement("z"); |
|
rotation_Z1.InnerText = mainCamera.localEulerAngles.z + ""; |
|
elmRot1.AppendChild(rotation_X1); |
|
elmRot1.AppendChild(rotation_Y1); |
|
elmRot1.AppendChild(rotation_Z1); |
|
camera.AppendChild(elmRot1); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
public void RecordCameraWithMemoryDate(string path, string cjid, int zqid, int jdid, int id, ArrayList lounumList, ArrayList PosList, ArrayList RotList) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
if (!ExistNodeWithID(path, cjid, zqid, jdid)) |
|
{ |
|
CreatNodeElement(path, cjid, zqid, jdid); |
|
} |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
|
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement jd in zq.ChildNodes) |
|
{ |
|
if (jd.Name == "jiedian" && jd.GetAttribute("id") == jdid.ToString()) |
|
{ |
|
XmlElement louceng = xmlDoc.CreateElement("LouCeng"); |
|
for (int i = 0; i < lounumList.Count; i++) |
|
{ |
|
if (i <= lounumList.Count - 2) |
|
{ |
|
louceng.InnerText += ((int)lounumList[i]).ToString() + ","; |
|
} |
|
else |
|
{ |
|
louceng.InnerText += ((int)lounumList[i]).ToString(); |
|
} |
|
} |
|
jd.AppendChild(louceng); |
|
XmlElement camera = xmlDoc.CreateElement("Camera"); |
|
jd.AppendChild(camera); |
|
////存储x,y |
|
//XmlElement x = xmlDoc.CreateElement("x"); |
|
//for (int i = 0; i < xList.Count; i++) |
|
//{ |
|
// if (i <= xList.Count - 2) |
|
// { |
|
// x.InnerText += ((float)xList[i]).ToString() + ","; |
|
// } |
|
// else |
|
// { |
|
// x.InnerText += ((float)xList[i]).ToString(); |
|
// } |
|
//} |
|
//camera.AppendChild(x); |
|
//XmlElement y = xmlDoc.CreateElement("y"); |
|
//for (int i = 0; i < yList.Count; i++) |
|
//{ |
|
// if (i <= yList.Count - 2) |
|
// { |
|
// y.InnerText += ((float)yList[i]).ToString() + ","; |
|
// } |
|
// else |
|
// { |
|
// y.InnerText += ((float)yList[i]).ToString(); |
|
// } |
|
//} |
|
//camera.AppendChild(y); |
|
//存储坐标 |
|
XmlElement elmPos1 = xmlDoc.CreateElement("position"); |
|
camera.AppendChild(elmPos1); |
|
XmlElement position_X1 = xmlDoc.CreateElement("x"); |
|
for (int i = 0; i < PosList.Count; i++) |
|
{ |
|
if (i <= PosList.Count - 2) |
|
{ |
|
position_X1.InnerText += ((Vector3)PosList[i]).x.ToString() + ","; |
|
} |
|
else |
|
{ |
|
position_X1.InnerText += ((Vector3)PosList[i]).x.ToString(); |
|
} |
|
} |
|
elmPos1.AppendChild(position_X1); |
|
|
|
XmlElement position_Y1 = xmlDoc.CreateElement("y"); |
|
for (int i = 0; i < PosList.Count; i++) |
|
{ |
|
if (i <= PosList.Count - 2) |
|
{ |
|
position_Y1.InnerText += ((Vector3)PosList[i]).y.ToString() + ","; |
|
} |
|
else |
|
{ |
|
position_Y1.InnerText += ((Vector3)PosList[i]).y.ToString(); |
|
} |
|
} |
|
elmPos1.AppendChild(position_Y1); |
|
XmlElement position_Z1 = xmlDoc.CreateElement("z"); |
|
for (int i = 0; i < PosList.Count; i++) |
|
{ |
|
if (i <= PosList.Count - 2) |
|
{ |
|
position_Z1.InnerText += ((Vector3)PosList[i]).z.ToString() + ","; |
|
} |
|
else |
|
{ |
|
position_Z1.InnerText += ((Vector3)PosList[i]).z.ToString(); |
|
} |
|
} |
|
elmPos1.AppendChild(position_Z1); |
|
|
|
|
|
//存储方向 |
|
XmlElement elmRot1 = xmlDoc.CreateElement("rotation"); |
|
camera.AppendChild(elmRot1); |
|
XmlElement rotation_X1 = xmlDoc.CreateElement("x"); |
|
for (int i = 0; i < RotList.Count; i++) |
|
{ |
|
if (i <= RotList.Count - 2) |
|
{ |
|
rotation_X1.InnerText += ((Vector3)RotList[i]).x.ToString() + ","; |
|
} |
|
else |
|
{ |
|
rotation_X1.InnerText += ((Vector3)RotList[i]).x.ToString(); |
|
} |
|
} |
|
elmRot1.AppendChild(rotation_X1); |
|
|
|
XmlElement rotation_Y1 = xmlDoc.CreateElement("y"); |
|
for (int i = 0; i < RotList.Count; i++) |
|
{ |
|
if (i <= RotList.Count - 2) |
|
{ |
|
rotation_Y1.InnerText += ((Vector3)RotList[i]).y.ToString() + ","; |
|
} |
|
else |
|
{ |
|
rotation_Y1.InnerText += ((Vector3)RotList[i]).y.ToString(); |
|
} |
|
} |
|
elmRot1.AppendChild(rotation_Y1); |
|
|
|
XmlElement rotation_Z1 = xmlDoc.CreateElement("z"); |
|
for (int i = 0; i < RotList.Count; i++) |
|
{ |
|
if (i <= RotList.Count - 2) |
|
{ |
|
rotation_Z1.InnerText += ((Vector3)RotList[i]).z.ToString() + ","; |
|
} |
|
else |
|
{ |
|
rotation_Z1.InnerText += ((Vector3)RotList[i]).z.ToString(); |
|
} |
|
} |
|
elmRot1.AppendChild(rotation_Z1); |
|
|
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
public void LoadCamera(string path, string cjid, int zqid, int jdid, int id) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
//根据路径将XML读取出来 |
|
xmlDoc.Load(filepath); |
|
XmlNodeList nodeList = xmlDoc.SelectSingleNode("assets").ChildNodes; |
|
//遍历所有关卡 |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement jd in zq.ChildNodes) |
|
{ |
|
if (jd.Name == "jiedian" && jd.GetAttribute("id") == jdid.ToString()) |
|
{ |
|
{ |
|
foreach (XmlElement cam in jd.ChildNodes) |
|
{ |
|
|
|
//拿到相机的节点 |
|
if (cam.Name == "Camera" && cam.GetAttribute("id") == id.ToString()) |
|
{ |
|
Transform camera = GameObject.Find("Main Camera").transform; |
|
//继续遍历 |
|
foreach (XmlElement x2 in cam.ChildNodes) |
|
{ |
|
if (x2.Name == "x") |
|
{ |
|
camera.gameObject.GetComponent<MouseFollowRotation>().x = float.Parse(x2.InnerText); |
|
} |
|
if (x2.Name == "y") |
|
{ |
|
camera.gameObject.GetComponent<MouseFollowRotation>().y = float.Parse(x2.InnerText); |
|
} |
|
if (x2.Name == "position") |
|
{ |
|
foreach (XmlElement x3 in x2.ChildNodes) |
|
{ |
|
if (x3.Name == "x") |
|
{ |
|
placementPos.x = float.Parse(x3.InnerText); |
|
} |
|
if (x3.Name == "y") |
|
{ |
|
placementPos.y = float.Parse(x3.InnerText); |
|
} |
|
if (x3.Name == "z") |
|
{ |
|
placementPos.z = float.Parse(x3.InnerText); |
|
} |
|
} |
|
} |
|
if (x2.Name == "rotation") |
|
{ |
|
foreach (XmlElement x3 in x2.ChildNodes) |
|
{ |
|
if (x3.Name == "x") |
|
{ |
|
placementRot.x = float.Parse(x3.InnerText); |
|
} |
|
if (x3.Name == "y") |
|
{ |
|
placementRot.y = float.Parse(x3.InnerText); |
|
} |
|
if (x3.Name == "z") |
|
{ |
|
placementRot.z = float.Parse(x3.InnerText); |
|
} |
|
} |
|
} |
|
} |
|
|
|
camera.position = placementPos; |
|
camera.localEulerAngles = placementRot; |
|
} |
|
|
|
} |
|
} |
|
|
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
public void CreatJieDian(string path, string cjid, int zqID, int id, string JDName, string JDIntro, string filename,int count) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
|
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqID.ToString()) |
|
{ |
|
foreach (XmlElement x in zq) |
|
{ |
|
if (x.Name == "jiedianCount") |
|
{ |
|
x.InnerText = count.ToString(); |
|
break; |
|
} |
|
} |
|
|
|
XmlElement jiedian = xmlDoc.CreateElement("jiedian"); |
|
jiedian.SetAttribute("id", id.ToString()); |
|
jiedian.SetAttribute("name", JDName); |
|
jiedian.SetAttribute("filename", filename); |
|
|
|
XmlElement JDI = xmlDoc.CreateElement("JDIntro"); |
|
JDI.InnerText = JDIntro; |
|
jiedian.AppendChild(JDI); |
|
|
|
XmlElement JDC = xmlDoc.CreateElement("JDContent"); |
|
JDC.InnerText = ""; |
|
jiedian.AppendChild(JDC); |
|
|
|
// CreatItems(xmlDoc, jiedian); |
|
|
|
zq.AppendChild(jiedian); |
|
root.AppendChild(elem); |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.AppendChild(root); |
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
public void CreatZaiQing(string cjid, int zqid, string ZQName, string ZQIntro) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + "NodeRecord.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
bool HasZQC = false; |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqingCount") |
|
{ |
|
zq.InnerText = zqid.ToString(); |
|
HasZQC = true; |
|
} |
|
} |
|
if (!HasZQC) |
|
{ |
|
XmlElement zqc = xmlDoc.CreateElement("zaiqingCount"); |
|
zqc.InnerText = zqid.ToString(); |
|
elem.AppendChild(zqc); |
|
} |
|
XmlElement zaiqing = xmlDoc.CreateElement("zaiqing"); |
|
zaiqing.SetAttribute("id", zqid.ToString()); |
|
zaiqing.SetAttribute("name", ZQName); |
|
XmlElement ZQI = xmlDoc.CreateElement("ZQIntro"); |
|
ZQI.InnerText = ZQIntro; |
|
zaiqing.AppendChild(ZQI); |
|
XmlElement jdc = xmlDoc.CreateElement("jiedianCount"); |
|
jdc.InnerText = "0"; |
|
zaiqing.AppendChild(jdc); |
|
elem.AppendChild(zaiqing); |
|
xmlDoc.AppendChild(root); |
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
|
|
} |
|
} |
|
public void EditJieDian(string path, string cjid, int zqid, int id, string JDName, string JDIntro) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + path; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
|
|
foreach (XmlElement jiedian in zq) |
|
{ |
|
if (jiedian.Name == "jiedian" && jiedian.GetAttribute("id") == id.ToString()) |
|
{ |
|
jiedian.SetAttribute("name", JDName); |
|
foreach (XmlElement x1 in jiedian) |
|
{ |
|
if (x1.Name == "JDIntro") |
|
{ |
|
x1.InnerText = JDIntro; |
|
break; |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
break; |
|
} |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
public void EditZaiQing(string cjid, int zqid, string ZQName, string ZQIntro) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + "NodeRecord.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "changjing" && elem.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in elem.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in zq) |
|
{ |
|
if (x1.Name == "ZQIntro") |
|
{ |
|
x1.InnerText = ZQIntro; |
|
break; |
|
} |
|
} |
|
zq.SetAttribute("name", ZQName); |
|
xmlDoc.Save(filepath); |
|
break; |
|
} |
|
} |
|
} |
|
|
|
} |
|
} |
|
} |
|
public void DeleteJieDian(string path, string cjid, int ZQid, int JDid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + path; |
|
//string zaiqingid = ZQid.ToString(); |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
//根据路径将XML读取出来 |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
for (int i = 0; i < nodeList.Count; i++) |
|
{ |
|
|
|
XmlElement changjing = (XmlElement)nodeList[i]; |
|
if (changjing.Name == "changjing" && changjing.GetAttribute("id") == cjid) |
|
{ |
|
|
|
foreach (XmlElement zq in changjing.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == ZQid.ToString()) |
|
{ |
|
foreach (XmlElement jiedian in zq) |
|
{ |
|
if (jiedian.Name == "jiedian" && jiedian.GetAttribute("id") == JDid.ToString()) |
|
{ |
|
jiedian.RemoveAll(); |
|
zq.RemoveChild(jiedian); |
|
break; |
|
} |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
int x = GetJieDianCount(path, cjid, ZQid); |
|
SetJieDianCount(path, cjid, ZQid, x - 1); |
|
JieDianIDPaiXu(path, cjid, ZQid, JDid); |
|
} |
|
if (path.Contains("NodeRecord.xml")) |
|
{ |
|
//同时删除轨迹记录的文件 |
|
string filename = Application.dataPath + @"/ExtendFolder/xml/recordList/"+ZQid+"/" + JDid + ".xml"; |
|
if (File.Exists(filename)) |
|
{ |
|
File.Delete(filename); |
|
} |
|
XMLFile_Rename(JDid,ZQid); |
|
|
|
} |
|
} |
|
|
|
public void XMLFile_Rename(int jdid,int zqid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/recordList/" + zqid + "/"; |
|
string[] files = Directory.GetFiles(filepath); |
|
foreach (string filename_path in files) |
|
{ |
|
string filename = Path.GetFileName(filename_path); |
|
string[] strs = filename.Split('.'); |
|
int id = int.Parse(strs[0]); |
|
if (id > jdid) |
|
{ |
|
string sourceFile = filename_path; |
|
string destFile = ""; |
|
if (strs.Length == 2) |
|
{ |
|
destFile = filepath + (id - 1) + ".xml"; |
|
} |
|
else if (strs.Length == 3) |
|
{ |
|
destFile = filepath + (id - 1) + ".xml.meta"; |
|
} |
|
|
|
File.Copy(sourceFile, destFile, true); |
|
File.Delete(sourceFile); |
|
} |
|
} |
|
} |
|
|
|
public void DeleteZaiQing(string cjid, int ZQid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + "NodeRecord.xml"; |
|
//string id = ZQid.ToString(); |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
//根据路径将XML读取出来 |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
for (int i = 0; i < nodeList.Count; i++) |
|
{ |
|
XmlElement changjing = (XmlElement)nodeList[i]; |
|
if (changjing.Name == "changjing" && changjing.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in changjing.ChildNodes) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == ZQid.ToString()) |
|
{ |
|
zq.RemoveAll(); |
|
changjing.RemoveChild(zq); |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
int x = GetZaiQingCount(((int)ExamInfoHelpClass.selectSceneID).ToString()); |
|
SetZaiQingCount(cjid, x - 1); |
|
ZaiQingIDPaiXu(((int)ExamInfoHelpClass.selectSceneID).ToString(), ZQid); |
|
|
|
string path = Application.dataPath + @"/ExtendFolder/xml/recordList/" +ZQid+"/"; |
|
string fileDir = Path.GetDirectoryName(path); |
|
if (Directory.Exists(fileDir)) |
|
{ |
|
string[] files = Directory.GetFiles(fileDir); |
|
foreach (string file in files) |
|
{ |
|
File.Delete(file); |
|
} |
|
//Directory.Delete(fileDir); |
|
|
|
DirectionRename_zq(ZQid); |
|
} |
|
} |
|
} |
|
|
|
void DirectionRename_zq(int zqid) |
|
{ |
|
string path = Application.dataPath + @"/ExtendFolder/xml/recordList/"; |
|
string fileDir = Path.GetDirectoryName(path); |
|
Debug.Log(fileDir); |
|
if (Directory.Exists(fileDir)) |
|
{ |
|
string[] Subdirs = Directory.GetDirectories(fileDir); |
|
//Directory.Delete(Subdirs[zqid - 1]); |
|
for (int i = 0; i < Subdirs.Length;i++ ) |
|
{ |
|
Debug.Log(Subdirs[i]); |
|
if (Directory.Exists(Subdirs[i])) |
|
{ |
|
if (!Subdirs[i].Contains("meta")) |
|
{ |
|
if (i >= zqid) |
|
{ |
|
//if (Directory.Exists(Subdirs[i - 1])) |
|
//{ |
|
// Directory.Move(Subdirs[i], Subdirs[i - 1]);//把文件夹3的文件复制到文件夹2中 |
|
//} |
|
string[] files = Directory.GetFiles(Subdirs[i]); |
|
foreach (string file in files) |
|
{ |
|
string filename = Path.GetFileName(file); |
|
//string s = Subdirs[i - 1] + filename; |
|
string destFileName = Subdirs[i - 1] +"/"+ filename; |
|
File.Copy(file, destFileName); |
|
Debug.Log(""); |
|
} |
|
foreach (string file in files) |
|
{ |
|
File.Delete(file); |
|
} |
|
//Directory.Delete(Subdirs[i]); |
|
} |
|
} |
|
|
|
} |
|
} |
|
Directory.Delete(Subdirs[Subdirs.Length - 1]); |
|
} |
|
} |
|
|
|
public void JieDianIDPaiXu(string path, string cjid, int ZQid, int JDid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + path; |
|
//string id = JDid.ToString(); |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
//根据路径将XML读取出来 |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
for (int i = 0; i < nodeList.Count; i++) |
|
{ |
|
XmlElement changjing = (XmlElement)nodeList[i]; |
|
if (changjing.Name == "changjing" && changjing.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in changjing) |
|
{ |
|
if (zq.Name == "zaiqing" && zq.GetAttribute("id") == ZQid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in zq) |
|
{ |
|
if (x1.Name == "jiedian") |
|
{ |
|
string jiedianID = x1.GetAttribute("id"); |
|
int intid = int.Parse(jiedianID); |
|
if (intid > JDid) |
|
{ |
|
x1.SetAttribute("id", (intid - 1).ToString()); |
|
x1.SetAttribute("filename", (intid - 1).ToString() + ".xml"); |
|
} |
|
} |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
public void ZaiQingIDPaiXu(string cjid, int ZQid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/Node/" + "NodeRecord.xml"; |
|
//string id = ZQid.ToString(); |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
//根据路径将XML读取出来 |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
for (int i = 0; i < nodeList.Count; i++) |
|
{ |
|
XmlElement changjing = (XmlElement)nodeList[i]; |
|
if (changjing.Name == "changjing" && changjing.GetAttribute("id") == cjid) |
|
{ |
|
foreach (XmlElement zq in changjing) |
|
{ |
|
if (zq.Name == "zaiqing") |
|
{ |
|
string zaiqingID = zq.GetAttribute("id"); |
|
int intid = int.Parse(zaiqingID); |
|
if (intid > ZQid) |
|
{ |
|
zq.SetAttribute("id", (intid - 1).ToString()); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
public static ArrayList ListName; |
|
public void GetjiedianListName(int zqid) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + "jiedian.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
ListName = new ArrayList(); |
|
xmlDoc.Load(filepath); |
|
XmlNode root = xmlDoc.SelectSingleNode("assets"); |
|
XmlNodeList nodeList = root.ChildNodes; |
|
foreach (XmlElement elem in nodeList) |
|
{ |
|
if (elem.Name == "zaiqing" && elem.GetAttribute("id") == zqid.ToString()) |
|
{ |
|
foreach (XmlElement x1 in elem.ChildNodes) |
|
{ |
|
if (x1.Name == "jiedian") |
|
{ |
|
string name = x1.GetAttribute("name"); |
|
ListName.Add(name); |
|
} |
|
} |
|
//break; |
|
} |
|
} |
|
//break; |
|
} |
|
else |
|
{ |
|
//break; |
|
} |
|
} |
|
public void SaveFFIntro(string fireForceIntroduction, int num) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + xmlname; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNodeList nodeList = xmlDoc.SelectSingleNode("assets").ChildNodes; |
|
bool HasFFI = false; |
|
foreach (XmlElement cus in nodeList) |
|
{ |
|
if (cus.GetAttribute("id") == num.ToString()) |
|
{ |
|
foreach (XmlElement xe in cus) |
|
{ |
|
if (xe.Name == "fireForceIntroduction") |
|
{ |
|
xe.InnerText = fireForceIntroduction; |
|
HasFFI = true; |
|
} |
|
} |
|
} |
|
} |
|
if (!HasFFI) |
|
{ |
|
foreach (XmlElement cus in nodeList) |
|
{ |
|
if (cus.GetAttribute("id") == num.ToString()) |
|
{ |
|
XmlElement ffi = xmlDoc.CreateElement("fireForceIntroduction"); |
|
ffi.InnerText = fireForceIntroduction; |
|
cus.AppendChild(ffi); |
|
} |
|
} |
|
|
|
} |
|
|
|
|
|
xmlDoc.Save(filepath); |
|
} |
|
} |
|
|
|
public void SaveFireForceName(string fireForceName) |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + "jiedian.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
xmlDoc.Load(filepath); |
|
XmlNodeList nodeList = xmlDoc.SelectSingleNode("assets").ChildNodes; |
|
foreach (XmlElement cus in nodeList) |
|
{ |
|
|
|
if (cus.Name == "fireForceName") |
|
{ |
|
cus.InnerText = fireForceName; |
|
xmlDoc.Save(filepath); |
|
return; |
|
} |
|
|
|
} |
|
} |
|
} |
|
|
|
public string GetFireForceName() |
|
{ |
|
string filepath = Application.dataPath + @"/ExtendFolder/xml/" + "jiedian.xml"; |
|
if (File.Exists(filepath)) |
|
{ |
|
XmlDocument xmlDoc = new XmlDocument(); |
|
//根据路径将XML读取出来 |
|
xmlDoc.Load(filepath); |
|
|
|
XmlNodeList nodeList = xmlDoc.SelectSingleNode("assets").ChildNodes; |
|
//遍历所有关卡 |
|
foreach (XmlElement cus in nodeList) |
|
{ |
|
|
|
if (cus.Name == "fireForceName") |
|
{ |
|
return cus.InnerText; |
|
} |
|
} |
|
} |
|
return "No File!"; |
|
} |
|
|
|
|
|
|
|
}
|
|
|