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

}

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM