Unity3d读取.csv文件

原文地址:http://blog.csdn.net/dingkun520wy/article/details/26594991

(一)文件路径

需要把csv文件放在StreamingAssets这个文件夹中。放在StreamingAssets中二进制文件打包后,Unity会将这些二进制文件放置在对应平台下的路径下。所以根据不同平台,访问的路径是不一样的。所以二进制文件一定要放在StreamingAssets 中。

//传人文件名返回路径
public static string FileCSV(string _str)
{
        string path = "";
#if UNITY_EDITOR     
	path = Application.dataPath + "/StreamingAssets/Csv/" + _str + ".csv";
#elif UNITY_IPHONE
	path = Application.dataPath + "/Raw/Csv/" + _str + ".csv";
#elif UNITY_ANDROID
	path = "jar:file://" + Application.dataPath + "!/assets/Csv/"+ _str +".csv";
#endif
      	Debug.Log (path);
        return path;
}


(二)解析文件

//解析文件
public static void readCSV_guide()
{
        string path = BaseFile.FileCSV("guide");
        while (!srReadFile.EndOfStream)
        {
            //检索出行
            string value = srReadFile.ReadLine();
            Debug.Log(value);
        }
        // 关闭读取流文件
        srReadFile.Close();
}







原文地址:https://www.cnblogs.com/lexiaoyao-jun/p/5208258.html