Unity AndroidでCSVファイルを読み込む方法
CSVファイルを、/Assets/Resources/CSV/sample.csv という場所に置いています。
Unity Editorでビルドするときは、
C#
1public int[,] redadCSVData(string sFile) { 2// 返り値の2次元配列 3int[,] readToIntData; 4String sFile = "sample.csv"; 5StreamReader sr = new StreamReader(Application.dataPath + "/Resources/CSV/" + sFile); 6string strStream = sr.ReadToEnd(); 7 8System.StringSplitOptions option = StringSplitOptions.RemoveEmptyEntries; 9 10string []lines = strStream.Split(new char[]{'\r','\n'},option); 11 12char []spliter = new char[1]{','}; 13 14int heightLength = lines.Length; 15int widthLength = lines[0].Split(spliter, option).Length; 16 17返り値の2次元配列の要素数を設定 18readToIntData = new int[heightLength, widthLength]; 19 20for (int i = 0; i < heightLength; i++) { 21 for (int j = 0; j < widthLength; j++) { 22 //カンマ分け 23 string [ ] readStrData = lines[i].Split(spliter, option); 24 //型変換 25 readToIntData[i, j] = int.Parse(readStrData[j]); 26 } 27} 28return readToIntData; 29}
のようにしています。
Android用にビルドして実行したいのですが、エラーが出てしまいます。
Androidでは読み込む場所が違うのでしょうか?
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/12 04:28