Unity3D ConfigMan.cs For XML File
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using UnityEngine; namespace Assets.Scripts.Models
{
public class ConfigMan
{
/// <summary>
/// 读取指定节点的属性
/// </summary>
/// <param name="nodeName">节点名</param>
/// <param name="attributeName">属性名</param>
/// <returns></returns>
public static string ReadNode(string nodeName,string attributeName) {
//Debug.Log("Application.dataPath:" + Application.dataPath);
//Debug.Log("Application.streamingAssetsPath:" + Application.streamingAssetsPath);
//Debug.Log("Application.consoleLogPath:" + Application.consoleLogPath);
//Debug.Log("Application.temporaryCachePath:" + Application.temporaryCachePath); var path = Application.dataPath + "/Configrations/MyConfig.xml";
var path1 = Application.streamingAssetsPath + "/Configrations/MyConfig.xml"; //StreamReader sr = new StreamReader(newPath, Encoding.UTF8); /**判断文件是否存在**/
if (File.Exists(path))
{
XmlDocument doc = new XmlDocument();
doc.Load(path);//载入对应的配置文件
XmlNodeList configs = doc.SelectSingleNode("Root").ChildNodes;//读取根节点下所有子节点 foreach (XmlElement item in configs)
{
if (item.HasAttribute(attributeName) && item.Name == nodeName)
{
return item.GetAttribute(attributeName);
}
}
return "";
}
else {
return "";
} }
/// <summary>
/// 创建新的节点
/// </summary>
public void CreateNode() { } /// <summary>
/// 更新已有节点属性值
/// </summary>
/// <param name="name">节点名称</param>
/// <param name="attributeName">要修改的属性名称</param>
/// <param name="value">属性值</param>
public static void UpdateNode(string name, string attributeName, string value) {
string path = Application.dataPath + "/Configrations/MyConfig.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path);//载入xml文件
XmlNodeList nodes=doc.SelectSingleNode("Root").ChildNodes;//获取根节点下所有子节点
try
{
if (nodes.Count > 0) {
//如果目录下有内容
foreach (XmlElement e in nodes) {
if (e.Name == name&& e.HasAttribute(attributeName)) {
e.SetAttribute(attributeName, value);//update the value
doc.Save(path);//save file
break;
}
}
}
}
catch (Exception ex) {
Debug.Log(ex.GetBaseException());
}
}
}
}
Unity3D ConfigMan.cs For XML File的更多相关文章
- ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id
出现场景:当点击"分类"再返回"首页"时,发生error退出 BUG描述:Caused by: java.lang.IllegalArgumentExcep ...
- Binary XML file line #2: Error inflating
06-27 14:29:27.600: E/AndroidRuntime(6936): FATAL EXCEPTION: main 06-27 14:29:27.600: E/AndroidRunti ...
- Android项目部署时,发生AndroidRuntime:android.view.InflateException: Binary XML file line #168: Error inflating class错误
这个错误也是让我纠结了一天,当时写的项目在安卓虚拟机上运行都很正常,于是当我部署到安卓手机上时,点击登陆按钮跳转到用户主界面的时候直接结束运行返回登陆界面. 当时,我仔细检查了一下自己的代码,并 ...
- ADT开发AndroidManifest.xml file missing错误
一个错误“AndroidManifest.xml file missing”但helloworld目录下有此文件,几番google仍没能解决.想起曾经在网络上看到的一个修复project的办法,抱着死 ...
- SVN :This XML file does not appear to have any style information associated with it.
SVN :This XML file does not appear to have any style information associated with it. The document tr ...
- [vb.net]XML File Parsing in VB.NET
Introduction Parsing XML files has always been time consuming and sometimes tricky. .NET framework p ...
- The AndroidManifest.xml File
manifest (船运的)载货清单 http://www.android-doc.com/guide/topics/manifest/manifest-intro.html Every applic ...
- bug_ _图片_android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
=========== 1 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zgan.communit ...
- bug_ _ android.view.InflateException: Binary XML file line #2: Error inflating class <unknown
========= 5.0 android异常“android.view.InflateException: Binary XML file line # : Error inflating ...
- How to: Read Object Data from an XML File
This example reads object data that was previously written to an XML file using the XmlSerializer cl ...
随机推荐
- 打包 IPA processing failed 失败
查看报错日志:有些SDK含有x86_64架构,移除即可 1. cd 该库SDK路径下 2.执行 lipo -remove x86_64 BaiduTraceSDK -o BaiduTraceSDK 解 ...
- Web网页音视频通话之Webrtc相关操作(一)
目录 打开摄像头/关闭摄像头 静音/解除静音 打开视频/关闭视频 截图且下载 打开摄像头/关闭摄像头 效果图 HTML <!DOCTYPE html> <html lang=&quo ...
- <学习笔记> 关于错排列
1 是做排列计数的时候了解到这个东西: 一开始想的是用容斥原理,先加上全排列,再减去不满足的,再加上重复的,再减去不满足的...... 后来发现还涉及到杨辉三角,麻烦死了,时空复杂度也过不去,然后就知 ...
- Selenium+2Captcha 自动化+验证码识别实战
本文深入探讨了使用Selenium库进行网页自动化操作,并结合2Captcha服务实现ReCAPTCHA验证码的破解.内容涵盖Selenium的基础知识.验证码的分类.2Captcha服务的使用,以及 ...
- python下的jstack - pystack
背景 python 多进程任务,卡在某个地方没有继续执行也没有报出异常,进程被hang住 日志没有捕获到相关信息,需要知道进程阻塞在哪里,为什么阻塞 jvm提供了jstack.jmap类工具进行性能分 ...
- 一起来自定义loader吧
loader 在 webpack 编译中起到非常重要的作用,用于对模块的源代码进行转换,比如 css-loader 将 css 代码处理成字符串,style-loader 创建 style 标签将 c ...
- [python]格式化字符串的几种方式
目录 方式一:C风格%操作符 方式二:内置的format函数与str类的format方法 方式三:插值格式字符串 python中有以下几种方法可以格式化字符串 方式一:C风格%操作符 这种方法偏C语言 ...
- Programming abstractions in C阅读笔记:p107-p110
<Programming Abstractions In C>学习第46天,p107-p110,3.1小节--"The concept of interface",总结 ...
- Programming abstractions in C阅读笔记:p127-p129
<Programming Abstractions In C>学习第51天,p127-p129,总结如下: 一.技术总结 1. string library 掌握常用函数如strlen,s ...
- Python图片与Base64相互转换
import base64 #必须的 pic=open("img.png","rb")#读取本地文件 pic_base=base64.b64encode(pic ...