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 ...
随机推荐
- 【Vue】Echart图表
vue-echart-ui vue 集成 echart 图表的小 demo. 基础 series.type 包括:line(折线图).bar(条形图).pie(饼图).scatter(散点图).gra ...
- 数据库连接池之c3p0-0.9.1.2,16年的古董,发生连接泄露怎么查(一)
背景 这篇文章是写给有缘人的,为什么这么说呢,因为本篇主要讲讲数据库连接池之c3p0-0.9.1.2版本. 年轻的朋友,可能没怎么听过c3p0了,或者也仅限于听说,这都很正常,因为c3p0算是200几 ...
- Redis的设计与实现(5)-整数集合
整数集合(intset)是集合键的底层实现之一: 当一个集合只包含整数值元素, 并且这个集合的元素数量不多时, Redis 就会使用整数集合作为集合键的底层实现. 整数集合 (intset) 是 Re ...
- 【Dotnet 工具箱】推荐一个使用 C# 开发的轻量级压测工具
你好,这里是 Dotnet 工具箱,定期分享 Dotnet 有趣,实用的工具和组件,希望对您有用! 轻量级压测工具 LoadTestToolbox 是一个使用 C# 开发的轻量级压测工具,基于 .NE ...
- U8接口开发
https://console-docs.apipost.cn/preview/b9674fcd9949865b/a5a249fb27736c15 模块 单据 功能说明 库存管理 其他出库 ...
- zabbix 修改模板中单个主机的触发器
参考文档:zabbix 修改模板中单个主机的触发器 在主机的 Triggers,克隆后修改,再disable原来的触发器.
- 探究eFuse:硬件保障与系统安全的核心
探究eFuse:硬件保障与系统安全的核心 图1: 编程熔断的 eFuse eFUSE的全名是"Electrically Programmable Read-Only Memory Fuse& ...
- Rollup 编译资源离不开 plugin
rollup 也是一个 JavaScript 的模块化编译工具,可以帮助我们处理资源. 与webpack比较 rollup相比 webpack 理念更为简单,能处理的场景也更有限. 资源类型 处理方式 ...
- LabVIEW图形化的AI视觉开发平台(非NI Vision)VI简介
前言 今天想和大家分享的是:仪酷LabVIEW AI视觉工具包的VI简介,如介绍内容有误,欢迎各位朋友们帮忙纠正~ 一.AI视觉工具包VI简介 已经安装好的AI工具包位于程序框图-函数选板-Addon ...
- 基于 ASP.NET 的投票系统
OnlineVoting 基于 ASP.NET 的投票系统 功能页面 登录 注册 首页 投票广场 查看别人发布的投票. 个人中心 个人资料 换头像.修改密码和其他信息. 发布投票 项目地址:https ...