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 ...
随机推荐
- 一文了解io包中的discard类型
1. 引言 io.discard是Go语言标准库提供一个结构体类型,其在丢弃不需要的数据场景下非常好用.本文我们将从io.discard 类型的基本定义出发,讲述其基本使用和实现原理,接着简单描述 i ...
- 【go语言】2.3.2 error 接口
在 Go 语言中,error 是一个内置的接口类型,用于表示错误情况.error 接口的定义如下: type error interface { Error() string } 任何具有 Error ...
- Pandas:在DataFrame中添加一行,并设置行索引
解决方案 效果图 参考链接 https://blog.csdn.net/Caiqiudan/article/details/107788525
- python数据处理:获取Dataframe中的一列或一行
解决方案 df['w'] #选择表格中的'w'列,使用类字典属性,返回的是Series类型 df.w #选择表格中的'w'列,使用点属性,返回的是Series类型 df[['w']] #选择表格中的' ...
- AcWing 第 92 场周赛 C题 4866. 最大数量 题解
原题链接 链表 + 并查集乱搞做法: 思路 首先可以发现,想要让度数尽量大,那我们应该构造成菊花图,即下图所示: 对于每个需求,我们可以知道,如果之前他们没有连在一起,那我们一定得把他们连在一起,该过 ...
- Javascript执行原理 网页引入javascript的三种方式* javascript核心语法 数据类型 Typeof运算符
Javascript执行原理: 用户端发送请求到服务器端 将js解析出来的数据(用户身份表示)绑定在请求路径中 服务器端获取到参数后会响应客户端 客户端通过浏览器解析响应的数据并将数据展现在浏览器上 ...
- 解码Transformer:自注意力机制与编解码器机制详述与代码实现
本文全面探讨了Transformer及其衍生模型,深入分析了自注意力机制.编码器和解码器结构,并列举了其编码实现加深理解,最后列出基于Transformer的各类模型如BERT.GPT等.文章旨在深入 ...
- VulnStack - ATT&CK红队评估实战(四) Writeup
VulnStack - ATT&CK红队评估实战(四) Writeup VulnStack(四)环境搭建 1.项目地址 http://vulnstack.qiyuanxuetang.net/v ...
- 2023羊城杯RE部分
vm_wo 代码copy下来调了一下 vm_body[0]=input[i] vm_body[1]=vm_body[0]>>1 v12=vm_body[0] vm_body[2]=v12& ...
- mysql 大表如何ddl 👑
大家好,我是蓝胖子,mysql对大表(千万级数据)的ddl语句,在生产上执行时一定要千万小心,一不小心就有可能造成业务阻塞,数据库io和cpu飙高的情况.今天我们就来看看如何针对大表执行ddl语句. ...