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. Android Hawk数据库 github开源项目

    Android Hawk数据库 github开源项目 Hawk 是一个很便捷的数据库  . 操作数据库仅仅需一行代码 , 能存不论什么数据类型 . github 地址: https://github. ...

  2. C++ 链接Mysql 函数介绍

    通过MySQL自己的API函数进行连接 1.使用API的方式连接,需要加载mysql的头文件和lib文件.在VS2010的附加包含目录中添加\MySQL\MySQL Server 5.1\includ ...

  3. java多线程实验 滚动字

    package com.rgy.Test; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt ...

  4. CLR Debug extention

    https://github.com/Microsoft/clrmd https://www.nuget.org/packages/Microsoft.Diagnostics.Runtime http ...

  5. The DiskSpd Storage Performance Tool

    https://enterpriseitnotes.wordpress.com/2013/05/31/understanding-ios-iops-and-outstanding-ios/ https ...

  6. Eclipse无法启动小结

    Eclipse启动的时候出现: The Eclipse executable launcher was unable to locate its companion shared library 针对 ...

  7. 手动挡C1驾驶学车@长建驾校

    2015-11-01 下午取钱去长建驾校报名学车 4600(学费) + 100(暂住证) + 30(照片) + 10(体检) 2015-11-14 8:00-12:00 理论课2 光盘10  2015 ...

  8. C#创建资源文件

    资源文件顾名思义就是存放资源的文件.资源文件在程序设计中有着自身独特的优势,他独立于源程序,这样资源文件就可以被多个程序使用.同时在程序设计的时候,有时出于安全或者其他方面因素的考虑,把重要东西存放在 ...

  9. 【Unity笔记】协程Coroutine的简单优化

    一个最简单的协程,也至少需要2帧才能完成.第一帧走到yield return null停止,第二帧从此处接着执行完下面的操作.需求:如果缓存中存在某数据则直接使用,否则联网异步下载. private ...

  10. 【Unity/Kinect】Kinect入门——项目搭建

    本文是Unity Store里的官方Demo包中的ReadMe翻译(别人翻的),介绍了用Unity如何入门搭建起一个Kinect项目工程. 非常感谢下面这位大大的无私奉献! http://www.ma ...