XML
2017-11-22 本文已影响0人
_Arturia
Save XML
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;
using System.IO;
using System.Xml.Linq;
public class SaveXML : MonoBehaviour {
void Start () {
XElement root = new XElement ("Root");
for (int i = 0; i < this.transform.childCount; i++) {
root.Add (new XElement (this.transform.GetChild (i).name, this.transform.GetChild (i).position));
//在当前节点后面添加子节点
}
//root.AddAfterSelf() 在当前节点后面添加一个相同级别的节点
root.Save (Application.dataPath + "/MyXML.xml");
}
}
Load XML
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml;
using System.Linq;
using System.Xml.Linq;
public class LoadXML : MonoBehaviour {
void Start () {
XElement root = XElement.Load (Application.dataPath + "/MyXML.xml");
int i = 0;
foreach (var a in root.Elements()) {
string abc = a.Value;
abc = abc.Replace ("(", "");
abc = abc.Replace (")", "");
abc.Trim ();
string[] str = abc.Split (',');
this.transform.GetChild (i).position = new Vector3 (float.Parse (str [0]), float.Parse (str [1]), float.Parse (str [2]));
i++;
}
}
}