ConfigReader(三十八)—— ReadMsgConfig
来源:互联网 发布:软件测试毕业总结 编辑:程序博客网 时间:2024/05/16 02:01
目录为:Assets/Scripts/ConfigReader/目录下
ReadMsgConfig.cs
读取一些静态的信息
对应XML配置文件:
Assets/Resources/Config/MsgConfig.xml
部分如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><MsgCfg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <info id="8"> <content>您已成为房主</content> <effect>4</effect> <type>1</type> </info> <info id="10"> <content>请选择英雄</content> <effect>5</effect> <type>1</type> </info> <info id="-12"> <content>目标已死亡</content> <effect>1</effect> <type>1</type> </info> <info id="-13"> <content>无法对友方单位施放</content> <effect>1</effect> <type>1</type> </info> <info id="-14"> <content>无效的目标</content> <effect>1</effect> <type>1</type> </info> <info id="-15"> <content>怒气不足</content> <effect>1</effect> <type>1</type> </info> <info id="-16"> <content>发送内容不能为空</content> <effect>4</effect> <type>1</type> </info>
ReadMsgConfig.cs
using System;using UnityEngine;using System.Xml;using System.Collections.Generic;//读取一些静态的信息//Assets/Resources/MsgCfg.xmlpublic class ReadMsgConfig{ XmlDocument xmlDoc = null; //构造函数 public ReadMsgConfig(string xmlFilePath) { 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 ("MsgCfg").ChildNodes; for (int i = 0; i < infoNodeList.Count; i++) { if ((infoNodeList[i] as XmlElement).GetAttributeNode("id") == null) { continue; } string typeName = (infoNodeList [i] as XmlElement).GetAttributeNode ("id").InnerText; MsgConfigInfo msgInfo = new MsgConfigInfo (); msgInfo.id = Convert.ToInt32 (typeName); foreach (XmlElement xEle in infoNodeList[i].ChildNodes) { switch (xEle.Name) { case "content": msgInfo.content = Convert.ToString (xEle.InnerText); break; case "type": msgInfo.msgType = Convert.ToInt32 (xEle.InnerText); break; case "errorcode": { string codes = Convert.ToString (xEle.InnerText); string[] words = codes.Split (new char[] { ',' }); if (words != null && words.Length > 0) { foreach (string s in words) { //msgInfo.serverErrorCode.Add(Convert.ToInt32(s)); } } } break; case "sound": msgInfo.audio_name = Convert.ToString (xEle.InnerText); break; case "effect": msgInfo.effect = Convert.ToInt32 (xEle.InnerText); break; } } ConfigReader.msgXmlInfoDic.Add (msgInfo.id, msgInfo); } }}/*<info id="-65476"> <content>帐号不存在</content> <effect>3</effect> <type>1</type></info>*/public class MsgConfigInfo: System.Object{ public int id; //id public int msgType; public string content;//字符串 public int effect; //效果 public string audio_name; //音效 public List<int> serverErrorCode = new List<int> (); public MsgConfigInfo(MsgConfigInfo info) { id = info.id; msgType = info.msgType; content = info.content; effect = info.effect; audio_name = info.audio_name; serverErrorCode.AddRange (info.serverErrorCode); }}
阅读全文
0 0
- ConfigReader(三十八)—— ReadMsgConfig
- ConfigReader(六十)—— ConfigReader
- Commom(十)—— ConfigReader
- ConfigReader(一)—— MapConfig
- ConfigReader(二)—— MapLoadConfig
- ConfigReader(三)—— ReadAdvancedGuideConfig
- ConfigReader(四)—— ReadBuffConfig
- ConfigReader(五)—— ReadBuySkinConfig
- ConfigReader(六)—— ReadCombineConfig
- ConfigReader(七)—— ReadDailyBonusConfig
- ConfigReader(八)—— ReadDailyTaskConfig
- ConfigReader(九)—— ReadGuideAbsorbTaskConfig
- ConfigReader(十)—— ReadGuideBornNpcTaskConfig
- ConfigReader(十一)—— ReadGuideCameraTaskConfig
- ConfigReader(十二)—— ReadGuideClickButtonTaskConfig
- ConfigReader(十三)—— ReadGuideFlashTaskConfig
- ConfigReader(十四)—— ReadGuideHelpConfig
- ConfigReader(十五)—— ReadGuideKillHeroTaskConfig
- 给定n个字符串,请对n个字符串按照字典序排列。
- softmax回归
- 2017自己前端面试题总结
- Java中对数组的两种操作方法Arrays、foreach()
- unity优化《二》--Texture图片空间和内存占用分析
- ConfigReader(三十八)—— ReadMsgConfig
- 解决Python爬虫在爬资源过程中使用urlretrieve函数下载文件不完全且避免下载时长过长陷入死循环,并在下载文件的过程中显示下载进度
- Maven无法下载依赖包解决办法
- 联系第五天总结
- 匿名方法、lambda
- Python基础教程(2)列表和元组
- 【UVA1169】Robotruck
- HDU 4343 Interval query
- Samba服务器创建与使用