sing UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Collections.Generic;
/**
* <summary>
* <para>作者:巨星电艺</para>
* <para>编写日期:巨星电艺</para>
**/
public class ouyLoadText : MonoBehaviour
{
//文本中每行的内容
ArrayList infoall;
//皮肤资源,这里用于显示中文
public GUISkin skin;
// Use this for initialization
void Start ()
{
print("当前文件路径:"+Application.persistentDataPath);
//得到文本中每一行的内容
//infoall = LoadFile(Application.persistentDataPath,"FileName.txt");
}
/**
* 读取文本文件
* path:读取文件的路径
* name:读取文件的名称
*/
ArrayList LoadFile(string path,string name)
{
//使用流的形式读取
StreamReader sr =null;
try{
sr = File.OpenText(path+"//"+ name);
}catch(Exception e)
{
//路径与名称未找到文件则直接返回空
return null;
}
string line;
ArrayList arrlist = new ArrayList();
while ((line = sr.ReadLine()) != null)
{
//一行一行的读取
//将每一行的内容存入数组链表容器中
arrlist.Add(line);
}
//关闭流
sr.Close();
//销毁流
sr.Dispose();
//将数组链表容器返回
return arrlist;
}
// Update is called once per frame
void Update ()
{
}
}
Unity 3D 载入 TEXT 文件
最新推荐文章于 2018-12-19 10:24:45 发布