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 ...
随机推荐
- 【Springboot】过滤器
Springboot实现过滤器 实现过滤器方式有两种: Filter过滤器具体实现类 通过@WebFilter 注解来配置 1.Filter过滤器具体实现类 1.1 实现Filter @Compone ...
- ZEGO 即构音乐场景降噪技术解析
随着线上泛娱乐的兴起,语聊房.在线 KTV 以及直播等场景在人们的日常生活中占据越来越重要的地位,用户对于音质的要求也越来越高,因此超越传统语音降噪算法的 AI 降噪算法应运而生,所以目前各大 RTC ...
- PhotoShop AI 爱国版保姆级安装和使用
上篇Photoshop AI 令人惊叹的生成式填充介绍了 PhotoShop AI 的新特性功能,有人以为我收了 Adobe 公司的钱帮它们做推广~~~.别不信,事实上确有其事,某平台审核直接把它删掉 ...
- 跟运维学 Linux - 01
跟运维学 Linux - 01 运维的诞生 运维工程师有很多叫法:系统运维.Linux 工程师.系统管理员... 网管可以说是运维工程师最早的雏形.在个人电脑未普及时,大家去网吧玩游戏. 玩家:&qu ...
- Stable Diffusion修复老照片-图生图
修复老照片的意义就不多说了,相信大家都明白,这里直接开讲方法. 1.原理 这个方法需要一个真实模型,以便让修复的照片看起来比较真实,我这里选择:realisticVisionV20,大家有更好的给我推 ...
- 【技术积累】HTML+CSS+JavaScript中的基础知识【一】
HTML基础标签 <html> 定义HTML文档的根元素. <!DOCTYPE html> <html> <head> <title>My ...
- ElementUi使用el-tooltip实现超出部分显示省略号
效果前: 效果后: 创建myTooltio.vue组件 <template> <div class="tooltip-container"> <el- ...
- Centos7中Oracle占用CPU过高(解决方案)
Centos7中Oracle占用CPU过高(解决方案) 前言: 99%的问题几乎都是SQL的问题,一般SQL可能会出现以下几种情况: 相关SQL搜索条件没有加索引 索引失效 联合查询过多 数据量过大 ...
- 阿里如何实现秒级百万TPS?搜索离线大数据平台架构解读
★ 淘宝搜索阶段 在2008-2012这个阶段,我们重点支持淘宝搜索的业务发展,随着淘宝商品量的不断增加,逐步引入Hadoop.Hbase等开源大数据计算和存储框架,实现了搜索离线系统的分布式化,有力 ...
- [python]enumerate迭代
Python中有个内置的函数叫做 enumerate,可以在迭代时返回元素的索引. # 示例代码01 warframe = ["saryn", "wisp", ...