unity对Xml文件进行读取
来源:互联网 发布:淘宝限额5000怎么修改 编辑:程序博客网 时间:2024/05/17 09:42
<?xml version="1.0" standalone="yes"?><RECORDS><RECORD Id="1" Title="年满18周岁才可以成为志愿者?" Answer="0"/></RECORDS>
xml文件格式
/** *Copyright(C) 2017 by MMHD *All rights reserved. *FileName: XmlMgr.cs *Author: Joel *Version: 1.0 *UnityVersion:5.6.1f1 *Date: 2017-09-04 *Description: *History: */ using System.Collections;using System.Collections.Generic;using UnityEngine;using System.Xml;public class XmlMgr : MonoBehaviour { private static XmlMgr mInstance = null; public static DictionaryQAk = null; public void Awake() { QAk = LoadXml(); //Debug.Log(QAk[1].title); } public static XmlMgr GetInstance() { if (mInstance == null) { mInstance = new GameObject("XmlMgr").AddComponent (); } return mInstance; } private string path1 = "DaTi"; private Dictionary mNeedleDic = null; private Dictionary mDishDic = null; /// 读取xml public DictionaryLoadXml() { string path = Application.streamingAssetsPath + @"\" + path1 + ".xml"; XmlReader reader = new XmlTextReader(path); Dictionary dic = new Dictionary (); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName == "RECORD") { QAData data = new QAData(); for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); if (reader.Name == "Id") data.id = int.Parse(reader.Value); else if (reader.Name == "Title") data.title = reader.Value; else if (reader.Name == "Answer") data.answer = int.Parse(reader.Value); }; if (!dic.ContainsKey(data.id)) dic.Add(data.id, data); } } } return dic; } //public QAData GetTitleInfo(int id) //{ // QAData data; // if (mNeedleDic == null) mNeedleDic = LoadXml(); // data = mNeedleDic[id]; // Debug.Log(111111111); // return data; //} //public float[] GetAnswerAll() //{ // if (mNeedleDic == null) mNeedleDic = LoadXml(); // float[] pro = new float[mNeedleDic.Count]; // int i = 0; // foreach (int key in mNeedleDic.Keys) // { // pro[i] = mNeedleDic[key].answer; // i++; // } // Debug.Log(pro); // return pro; //} public class QAData { public int id; public string title; public int answer; }}
阅读全文
0 0
- unity对Xml文件进行读取
- SAXRead对xml文件进行读取
- Unity 读取xml 文件
- Unity 读取xml 文件
- Unity 读取XML文件
- TXMLDocument对XML文件进行读取和写入 (bcb)
- TXMLDocument对XML文件进行读取和写入
- 用dom4j+xpath的方式对xml文件进行读取
- 使用LINQ技术对XML文件进行读取
- 使用dom4j对xml文件进行读取和输出操作
- unity中读取xml文件
- Unity 中读取XML文件
- Unity对XML文件加密
- 【Unity&XML】读取XML文件内容
- unity Android 打包后读取 xml 文件
- Unity快捷读取XML、JSON文件
- 使用libxml2对xml进行SAX读取
- XPath对xml进行读取操作
- Redis使用认证密码登录
- 从零开始···maven创建web项目
- MySQL数据库多级关联删除失败
- 链路层到网络层(eth->ip->udp)
- ue4 delegate event
- unity对Xml文件进行读取
- 【安全牛学习笔记】WEP加密、RC4算法
- UNIX主机文件导入数据库方法以及sqlldr在AIX主机使用方法
- ActiveMQ系列—ActiveMQ安装
- 【求最小权值割边】HDU
- cache一致性入门级解答
- Crash-fix-2:org.springframework.http.converter.HttpMessageNotReadableException
- keras小点记录
- validate表单校验