XML

作者: _Arturia | 来源:发表于2017-11-22 14:30 被阅读0次

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++;
    }
}

}

相关文章

网友评论

    本文标题:XML

    本文链接:https://www.haomeiwen.com/subject/usnnvxtx.html