unity 与 XML 解析

来源:互联网 发布:淘宝上为啥不卖电视棒 编辑:程序博客网 时间:2024/06/05 17:48

xml文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><HeadSelect xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">    <info HeadID="1">        <Head_Name>精灵男</Head_Name>        <Head_Type>1</Head_Type>        <Atlas>TeamHead2</Atlas>        <Atlas_Num>16</Atlas_Num>        <Used_Condition>0</Used_Condition>        <Account_Level>1</Account_Level>    </info>    <info HeadID="2">        <Head_Name>精灵女</Head_Name>        <Head_Type>2</Head_Type>        <Atlas>TeamHead2</Atlas>        <Atlas_Num>17</Atlas_Num>        <Used_Condition>0</Used_Condition>        <Account_Level>1</Account_Level>    </info></HeadSelect>


解析如下:

public class ReadHeroHeadConfig{    XmlDocument xmlDoc = null;    public ReadHeroHeadConfig(string xmlFilePath)    {        //TextAsset xmlfile = Resources.Load(xmlFilePath) as TextAsset;        ResourceUnit xmlfileUnit = ResourcesManager.Instance.loadImmediate(xmlFilePath, ResourceType.ASSET);        TextAsset xmlfile = xmlfileUnit.Asset as TextAsset;        if (!xmlfile)        {            Debug.LogError(" error infos: 没有找到指定的xml文件:" + xmlFilePath);        }        xmlDoc = new XmlDocument();        xmlDoc.LoadXml(xmlfile.text);        XmlNodeList infoNodeList = xmlDoc.SelectSingleNode("HeadSelect").ChildNodes;        for (int i = 0; i < infoNodeList.Count; i++)//XmlNode xNode in infoNodeList)        {            if ((infoNodeList[i] as XmlElement).GetAttributeNode("HeadID") == null) continue;            string typeName = (infoNodeList[i] as XmlElement).GetAttributeNode("HeadID").InnerText;            HeadSelectConfigInfo HeadSelectInfo = new HeadSelectConfigInfo();            HeadSelectInfo.HeroHeadID = Convert.ToInt32(typeName);            foreach (XmlElement xEle in infoNodeList[i].ChildNodes)            {                #region 搜索                switch (xEle.Name)                {                    case "Head_Name":                        HeadSelectInfo.HeroHeadName = Convert.ToString(xEle.InnerText);                        break;                    case "Head_Type":                        HeadSelectInfo.HeroHeadType = GameMethod.ResolveToIntList(xEle.InnerText);                        break;                    case "Atlas":                        HeadSelectInfo.HeroHeadAtlas = Convert.ToString(xEle.InnerText);                        break;                    case "Atlas_Num":                        HeadSelectInfo.HeroHeadAtlas_Num = xEle.InnerText;                        break;                    case "Used_Condition":                        HeadSelectInfo.HeroUsedCondition = Convert.ToInt32(xEle.InnerText);                        break;                    case "Account_Level":                        HeadSelectInfo.HeroUsedLevel = Convert.ToInt32(xEle.InnerText);                        break;                }                #endregion            }            ConfigReader.headSelectXmlInfoDict.Add(HeadSelectInfo.HeroHeadID, HeadSelectInfo);        }    }    //public st}


FR:海涛高软(hunk Xu)
QQ技术交流群:386476712

阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 开户送白菜赢到100可提款 无需申请开户送588元 开户手机验证即送38元体验金 开户送体验金赢100可提款 新开户送体验金68 开户送体验金不限id 开户即送58体验金 开户免费送体验金 注册开户首存1元送30 开户送体验金无需申请 注册开户送免费体验金 开户就送 开户送金 开户送8 贵金属开户送 贵金属开户送赠金 棋牌开户送体验金 黄金开户送金 古阿扎资源 古阿扎图片 古阿扎花椒 古a扎 古阿扎自舔两分钟 古阿扎31秒什么梗 古阿扎早期福利 古a扎2分51秒 古阿扎2分51秒 血色古阿扎那个胸 血色古阿扎流出 血色古阿扎7部 血色古阿扎2分51秒 数据漫游开了会扣费吗 无限流量开热点扣费吗 咪咕阅读乱扣费 快捷金额扣费是什么 解除自动扣费怎么解除 好医保自动扣费怎么取消 社保扣费不成功如何补交 2018医保自动扣费不成功当月 养老保险怎么扣费 位面开拓者 温柔