您的位置:首页 > 移动开发 > Unity3D

Unity 读取文件 TextAsset读取配置文件

2016-01-27 09:37 906 查看
1 支持文件类型

.txt
.html
.htm
.xml
.bytes
.json
.csv
.yaml
.fnt


2 寻找文件

1   //Load texture from disk
TextAsset bindata= Resources.Load("Texture") as TextAsset;
Texture2D tex = new Texture2D(1,1);
tex.LoadImage(bindata.bytes);
2   直接在编辑器中赋值
public TextAsset textFile;


3 配置文件通常分行配置属性

例如:
英雄名称,等级,生命,攻击
hero1,1,1,1
hero2,1,1,1
string[] lines = textFile.text.Split("\n"[0]); 可以读出属性
lines[0] = "英雄名称,等级,生命,攻击"
lines[1] = "hero1,1,1,1"
lines[2] = "hero2,1,1,1"

然后可以读出每条数据的具体属性
for (int i = 0; i < lines.Length - 2; i++) {
string[] parts = lines[i + 1].Split(","[0]);
}
parts[0] = "hero1" parts[1] = "1" parts[2] = "1" parts[2] = "1"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息