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