现在来记录一下:Unity 中动态生成 xml文件:
//xml保存的路径,这里放在Assets路径 注意路径。
string filepath = Application.dataPath + @"/my.xml";
//继续判断当前路径下是否有该文件
if(!File.Exists (filepath))
{
//创建XML文档实例
XmlDocument xmlDoc = new XmlDocument();
//创建root节点,也就是最上一层节点
XmlElement root = xmlDoc.CreateElement("transforms");
//继续创建下一层节点
XmlElement elmNew = xmlDoc.CreateElement("rotation");
//设置节点的两个属性 ID 和 NAME
elmNew.SetAttribute("id","0");
elmNew.SetAttribute("name","momo");
//继续创建下一层节点
XmlElement rotation_X = xmlDoc.CreateElement("x");
//设置节点中的数值
rotation_X.InnerText = "0";