首页 > 代码库 > unity中CSV的读取

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 = http://www.mamicode.com/new List();
}

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();

}

}

unity中CSV的读取