u3d读取xml文件和u3d 读取txt外部文件

using UnityEngine;
using System.Collections;

using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Text;

public class u3dxml : MonoBehaviour
{
    private string m_filename = "2.txt";
    private string m_path =null ;

// Use this for initialization
    void Start ()
    {
        XmlDocument xmlDoc = new XmlDocument();
        string xmlPath = Application.dataPath + "\\1.xml";
        
        //FileStream fs = new FileStream(xmlPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
        xmlDoc.Load(xmlPath);
        //xmlDoc.Load(fs);//可以Load文件的路径也可以Load文件的流

XmlNodeList componentList = xmlDoc.SelectSingleNode("ttx").ChildNodes;//获取car节点的所有子节点

foreach (XmlNode componentXN in componentList)//遍历所有子节点,得到component结点
        {
            XmlElement componentXE = (XmlElement)componentXN;//将子节点类型转换为XmlElement类型

XmlNodeList nls = componentXE.ChildNodes;//继续获取component子节点的所有子节点

Debug.Log("data:" + nls.Item(0).InnerText);

// dictionaryOfActionName.Add(int.Parse(nls.Item(0).InnerText), nls.Item(1).InnerText);//取值

}

readTXT();
    }
    
    // Update is called once per frame
    void Update ()
    {
    
    }
///////////////////////////////////////////////////////////////////////////// 1.txt
   using UnityEngine;
using System.Collections;

using System.Runtime.InteropServices;
using System.Text;
using System.IO;

void readTXT()
{
StreamReader m_reader = null;
m_reader = File.OpenText(Application.dataPath + "\\" + "config.txt");
string s_line; int Count = ;
while ((s_line = m_reader.ReadLine()) != null)
{
// Debug.Log(s_line);
int numt;
string[] words = s_line.Split(':');
numt = int.Parse(words[]);
if (Count == )
{ m_WheelCenter = numt;
Debug.Log("Wheelcenter:" + m_WheelCenter);
}
if (Count == )
{ m_WheelLeft = numt;
Debug.Log("wheelleft:" + m_WheelLeft);
}
if (Count == )
{ m_WheelRight = numt;
Debug.Log("wheelright:" + m_WheelRight);
} if (Count == )
{
m_YouMenMin = numt;
Debug.Log("YouMenMin:" + m_YouMenMin); } if (Count == )
{
m_YouMenMax = numt;
Debug.Log("YouMenMax:" + m_YouMenMax);
} Count++;
}
m_YouMenFanWei = m_YouMenMax - m_YouMenMin;
m_ShaCheFanWei = m_ShaCheMax - m_YouMenMin; m_reader.Close();
m_reader.Dispose();
}

更新

txt文件读和写

void ReadConfig(string _name)
{
StreamReader m_reader = null;
m_reader = File.OpenText(Application.dataPath + "\\" + _name);
string s_line; int Count = ;
while ((s_line = m_reader.ReadLine()) != null)
{
if (Count == )
{ int numt;
string[] words = s_line.Split(' '); int v = int.Parse(words[]); Debug.Log("Debug Mode:" + v);
} if (Count == )
{
int numt;
string[] words = s_line.Split(' '); int v = int.Parse(words[]); Debug.Log("Load Config CameraID:" + v);
} ++Count;
} m_reader.Close();
m_reader.Dispose();
} void WriteTxtMaxScore(string _name)
{
StreamWriter writeStream = new StreamWriter(Application.dataPath +"\\"+ _name); string histroyMaxscore = "HistoryMaxScore:"+ m_HistoryMaxScore;
string todayScore = "TotadyMaxScore:" + m_TodayMaxScore; writeStream.WriteLine(histroyMaxscore);
writeStream.WriteLine(todayScore);
//关闭流
writeStream.Close();
//销毁流
writeStream.Dispose(); }

u3d读取xml txt的更多相关文章

  1. MFC如何读取XML

    <?xml version="1.0" encoding="utf-8"?> <Cases> <case> <No&g ...

  2. Java获取路径方法&相对路径读取xml文件方法

    (1).request.getRealPath("/");//不推荐使用获取工程的根路径 (2).request.getRealPath(request.getRequestURI ...

  3. 第一周:读取XML深度数据并将其重建为三维点云

    本周主要任务:学习PCL点云库,掌握利用PCL对点云处理的方法 任务时间:2014年9月1日-2014年9月7日 任务完成情况:完成了读取单幅xml深度数据,并重建三维点云并显示 任务涉及基本方法: ...

  4. java+反射+多线程+生产者消费者模式+读取xml(SAX)入数据库mysql-【费元星Q9715234】

    java+反射+多线程+生产者消费者模式+读取xml(SAX)入数据库mysql-[费元星Q9715234] 说明如下,不懂的问题直接我[费元星Q9715234] 1.反射的意义在于不将xml tag ...

  5. JavaScript 解析读取XML文档 实例代码(转)

    JavaScript解析读取XML文件,主要就是加载并解析XML文件,然后就可以测试解析的XML文件的内容,打印输出来. 在线演示:http://demo.jb51.net/js/2012/readx ...

  6. 读取xml数据装配到字典中之应用场景

    前段时间看到支付宝设置里面有个多语言这个功能,蛮有意思的,就想双休没事的话做个相关的demo玩玩,可是礼拜六被妹子拽出去玩了一天,来大上海有大半年了,基本没有出去玩过,妹子说我是超级宅男,也不带她出去 ...

  7. 自己动手之使用反射和泛型,动态读取XML创建类实例并赋值

    前言: 最近小匹夫参与的游戏项目到了需要读取数据的阶段了,那么觉得自己业余时间也该实践下数据相关的内容.那么从哪入手呢?因为用的是Unity3d的游戏引擎,思来想去就选择了C#读取XML文件这个小功能 ...

  8. 使用dom4j读取xml连接数据库与之单例模式

    使用dom4j读取xml ,加入jar包 dom4j-1.6.1.jar jaxen-1.1-beta-6.jar public class XmlConfigReader { //懒汉式,延迟加载 ...

  9. java DOM4J 读取XML

    最近学习Java,在处理XML文档的时候,查阅相关资料,发现了DOM4J这个jre库,相对C#的XML处理来说,功能还算是跟得上 下面展示一篇我自己写的一个XML读取测试 import java.ut ...

随机推荐

  1. HDU 2256 Problem of Precision(矩阵高速幂)

    题目地址:HDU 2256 思路: (sqrt(2)+sqrt(3))^2*n=(5+2*sqrt(6))^n; 这时要注意到(5+2*sqrt(6))^n总能够表示成an+bn*sqrt(6); a ...

  2. 重温java中的String,StringBuffer,StringBuilder类

    不论什么一个系统在开发的过程中, 相信都不会缺少对字符串的处理. 在 java 语言中, 用来处理字符串的的类经常使用的有 3 个: String.StringBuffer.StringBuilder ...

  3. 创建C3P0数据源

    [Author]: kwu 创建C3P0数据源,实际开发中直接用JDBC连接数据库是非常少的.一般使用数据源的形式,C3P0是开源的数据源,实际项目用得非常多: 1.添加maven的支持 <de ...

  4. vs2010静态链接Qt

    先按照这个帖子弄好静态库 http://www.cnblogs.com/rollenholt/articles/2518642.html 注意原文中config那一步最后一个"-" ...

  5. Spring Boot干货系列:(六)静态资源和拦截器处理

    Spring Boot干货系列:(六)静态资源和拦截器处理 原创 2017-04-05 嘟嘟MD 嘟爷java超神学堂 前言 本章我们来介绍下SpringBoot对静态资源的支持以及很重要的一个类We ...

  6. linux 基本配置tab键和显示行号 和中文输入法

    一.仅设置当前用户的Tab键宽度 输入命令:vim ~/.vimrc 然后:set tabstop=4   //我这里将Tab键的宽度设置为4 保存:ctrl+z+z(或:wq!) OK! 二.设置所 ...

  7. JAVA-JAVA、JavaScript、JavaWeb的关系

    相关资料:1.http://www.cnblogs.com/youring2/archive/2013/06/06/3120645.html2.https://jingyan.baidu.com/ar ...

  8. C++笔记 2

    1.程序由函数组成,函数只完成自己特定的功能即可   把函数声明写在头文件里(想使用函数时,可直接导入头文件,调用函数),把函数实现写在".cc"文件中   把多个".c ...

  9. upupw phpmyadmin写shell

    废话: upupw给我的感觉是一个充当了waf毁三观的垃圾程序.然而,我讨厌的程序,管理员都特别喜欢用. 你会发现直接用之前那套写shell的建表然后在值里添加shell代码写到一个路径不可以了. C ...

  10. Python内置字典;dict ,set

    dict and set dict:  键-值 /重复添加 set :  键 / key不能重复 对于不变对象来说,调用对象自身的任意方法,也不会改变该对象自身的内容.相反,这些方法会创建新的对象并返 ...