unity中CSV的读取

unity中读取数据的格式有很多种,现在为大家介绍的是读取CSV,

static CSV csv;
public List<string[]> m_ArratData;


public static CSV Getinstance()
{
if (csv == null)
{
csv = new CSV();
}
return csv;
}
public string getstring(int row, int col)
{
return m_ArratData[row][col];
}
public int getInt(int row, int col)
{
return int.Parse(m_ArratData[row][col]);
}

private CSV() {
m_ArratData = new List<string[]>();
}

public void loadFile(string path,string fileName)
{
m_ArratData.Clear();
StreamReader sr = null;
try
{
sr = File.OpenText(path + "//" + fileName);
Debug.Log("file is finded!");
}
catch
{
Debug.Log("file dont not exist");
}
string line;
while ((line = sr.ReadLine()) != null)
{
m_ArratData.Add(line.Split(','));
}
sr.Close();
sr.Dispose();

}

}

posted @ 2017-03-14 23:27  carsonche  阅读(2843)  评论(0编辑  收藏  举报