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 ...
随机推荐
- 【游记】NOIP2022 预备赛游记
Day -2 \(NOIP\) 就要来了,\(CSYZ\) 斥巨资给我们在 \(NOIP\) 正式考点举办了一场 \(NOIP\) 预备赛,真是太感动了~~ \(cy\) 说明天要颁奖,激动激动! D ...
- java无法加载maper.xml问题
项目依赖其他模块,模块中有 mapper,本项目也有mapper,导致项目无法正常运行. 解决办法: 1.配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.X ...
- React: 路由重定向
解决方案 参考链接 https://v5.reactrouter.com/web/example/route-config
- Python操纵数据库:peewee
模块名:peewee 安装方法: pip install peewee 官方教程:http://docs.peewee-orm.com/en/latest/
- pycharm链接mysql报错: Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually.
检查驱动 我本机安装的mysql版本是5.6的,那么IDEA要连接mysql也应该匹配下驱动版本.把Driver改成MySQL for 5.1就可以了. 参考链接:https://blog.csdn. ...
- 用 Tensorflow.js 做了一个动漫分类的功能(一)
前言: 浏览某乎网站时发现了一个分享各种图片的博主,于是我顺手就保存了一些.但是一张一张的保存实在太麻烦了,于是我就想要某虫的手段来处理.这样保存的确是很快,但是他不识图片内容,最近又看了 mobil ...
- 【更新】【解决中文文件名乱码】mac一键获取最新datagrid 2017.3注册码到剪贴板
背景与前版实现请见: 前版原文 需要the unarchiver 解决中文文件名在mac上创建文件异常. 代码调整 IDEA_JIHUOMA_HOME="/tmp/idea-jihuoma& ...
- 论文解读(DWL)《Dynamic Weighted Learning for Unsupervised Domain Adaptation》
[ Wechat:Y466551 | 付费咨询,非诚勿扰 ] 论文信息 论文标题:Dynamic Weighted Learning for Unsupervised Domain Adaptatio ...
- 【go笔记】标准库-strconv
前言 标准库strconv提供了字符串类型与其他常用数据类型之间的转换. strconv.FormatX()用于X类型转字符串,如strconv.FormatFloat()用于浮点型转字符串. str ...
- WPF --- 非Button自定义控件实现点击功能
引言 今天在做一个设置文件夹路径的功能,就是一个文本框,加个按钮,点击按钮,弹出 FolderBrowserDialog 再选择文件夹路径,简单做法,可以直接 StackPanel 横向放置一个 Te ...