ファイルの置き場所(Unity PCとスマホ実機の違い)
Resourceフォルダならいいんだけど、Resourceフォルダ外でやる場合はたぶん場所が違うので不都合が起きる。
# if UNITY_EDITOR
private static string custom_csv_path_ = "C:/default.csv";
# elif UNITY_ANDROID || UNITY_IOS
private static string custom_csv_path_ = Application.persistentDataPath + "/default.csv";
# endif
ファイルの入力(読み込み)
Resourceフォルダから
string file_name = "default";
TextAsset ta = Resources.Load(file_name, typeof(TextAsset)) as TextAsset;
string read_data = ta.text;
外部フォルダから
string read_data = "";
FileInfo file_info = new FileInfo("C:/default.csv");
try
{
using (StreamReader sr = new StreamReader(file_info.OpenRead(), Encoding.UTF8))
{
// 最初から最後まで全部読み込む
read_data = sr.ReadToEnd();
}
}
catch (Exception e)
{
//ここにエラーメッセージを書く?
}