码迷,mamicode.com
首页 > 其他好文 > 详细

数据生成XML导入Excel

时间:2015-07-21 20:21:50      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:

void GenerateXML(Dictionary<string, PrefabDict> dict)
{
string xmlPath = Application.dataPath + "/Editor/CharactersEffectPoint/EffectPointsInfo.xml";
if (File.Exists(xmlPath))
{
Debug.Log(xmlPath);
File.Delete(xmlPath);
}

XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration xmldecl;
xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
XmlElement root = xmlDoc.DocumentElement;
xmlDoc.InsertBefore(xmldecl, root);

XmlElement infoBase = xmlDoc.CreateElement("InfoBase"); //创建根节点,最上层节点 角色名
xmlDoc.AppendChild(infoBase);

foreach (var dic in dict)
{
XmlElement characterInfo = xmlDoc.CreateElement("effectPointsInfo");
infoBase.AppendChild(characterInfo);

XmlElement characterKey = xmlDoc.CreateElement("Character");

XmlElement Head_C_EffectPoint = xmlDoc.CreateElement("Head_C_EffectPoint");
XmlElement Head_T_EffectPoint = xmlDoc.CreateElement("Head_T_EffectPoint");
XmlElement Hand_L_EffectPoint = xmlDoc.CreateElement("Hand_L_EffectPoint");
XmlElement Hand_R_EffectPoint = xmlDoc.CreateElement("Hand_R_EffectPoint");

XmlElement Foot_L_EffectPoint = xmlDoc.CreateElement("Foot_L_EffectPoint");
XmlElement Foot_R_EffectPoint = xmlDoc.CreateElement("Foot_R_EffectPoint");
XmlElement Chest_EffectPoint = xmlDoc.CreateElement("Chest_EffectPoint");
XmlElement Bottom_EffectPoint = xmlDoc.CreateElement("Bottom_EffectPoint");

XmlElement Weapon01_EffectPoint = xmlDoc.CreateElement("Weapon01_EffectPoint");
XmlElement Normal_HurtPoint = xmlDoc.CreateElement("Normal_HurtPoint");
XmlElement Special_HurtPoint = xmlDoc.CreateElement("Special_HurtPoint");
XmlElement Footsteps_EffectPoint = xmlDoc.CreateElement("Footsteps_EffectPoint");

characterKey.InnerText = dic.Key.ToString();

Head_C_EffectPoint.InnerText = dic.Value.Head_C_EffectPoint.ToString();
Head_T_EffectPoint.InnerText = dic.Value.Head_T_EffectPoint.ToString();
Hand_L_EffectPoint.InnerText = dic.Value.Hand_L_EffectPoint.ToString();
Hand_R_EffectPoint.InnerText = dic.Value.Hand_R_EffectPoint.ToString();

Foot_L_EffectPoint.InnerText = dic.Value.Foot_L_EffectPoint.ToString();
Foot_R_EffectPoint.InnerText = dic.Value.Foot_R_EffectPoint.ToString();
Chest_EffectPoint.InnerText = dic.Value.Chest_EffectPoint.ToString();
Bottom_EffectPoint.InnerText = dic.Value.Bottom_EffectPoint.ToString();

Weapon01_EffectPoint.InnerText = dic.Value.Weapon01_EffectPoint.ToString();
Normal_HurtPoint.InnerText = dic.Value.Normal_HurtPoint.ToString();
Special_HurtPoint.InnerText = dic.Value.Special_HurtPoint.ToString();
Footsteps_EffectPoint.InnerText = dic.Value.Footsteps_EffectPoint.ToString();

characterInfo.AppendChild(characterKey);
characterInfo.AppendChild(Head_C_EffectPoint);
characterInfo.AppendChild(Head_T_EffectPoint);
characterInfo.AppendChild(Hand_L_EffectPoint);
characterInfo.AppendChild(Hand_R_EffectPoint);

characterInfo.AppendChild(Foot_L_EffectPoint);
characterInfo.AppendChild(Foot_R_EffectPoint);
characterInfo.AppendChild(Chest_EffectPoint);
characterInfo.AppendChild(Bottom_EffectPoint);

characterInfo.AppendChild(Weapon01_EffectPoint);
characterInfo.AppendChild(Normal_HurtPoint);
characterInfo.AppendChild(Special_HurtPoint);
characterInfo.AppendChild(Footsteps_EffectPoint);

}

xmlDoc.Save(xmlPath); //创建EffectPointsInfo.xml文件
AssetDatabase.Refresh();
this.ShowNotification(new GUIContent("数据生成:" + xmlPath));
}

数据生成XML导入Excel

标签:

原文地址:http://www.cnblogs.com/DragonXin/p/4665341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!