Unity 3 d読み出しcsvファイル
1379 ワード
原文住所:http://blog.csdn.net/dingkun520wy/article/details/26594991
(一)ファイルパス
csvファイルをStreamingAssetsというフォルダに入れる必要があります.StreamingAssetsにバイナリ・ファイルをパッケージ化すると、Unityはこれらのバイナリ・ファイルを対応するプラットフォームの下のパスの下に配置します.そのため、プラットフォームによってアクセス経路が異なります.だからバイナリファイルは必ずStreamingAssetsに入れなければなりません.
(二)解析ファイル
(一)ファイルパス
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();
}