2019
11.19

 

 

 

 

 

 

// CSV 파일로 내보내기
private List<string[]> rowData = new List<string[]>();
[Button]
void Write()
{
// Creating First row of titles manually..
string[] rowDataTemp = new string[3];
rowDataTemp[0] = "key";
rowDataTemp[1] = "talker";
rowDataTemp[2] = "talk";
rowData.Add(rowDataTemp);
// You can add up the values in as many cells as you want.
for (int i = 0; i < TalkAddText.Count; i++)
{
rowDataTemp = new string[3];
rowDataTemp[0] = name.Substring(0, 10) + "dialogue" + i; // name
rowDataTemp[1] = TalkAddText[i].talker; // name
rowDataTemp[2] = TalkAddText[i].talk; // ID
rowData.Add(rowDataTemp);
}
string[][] output = new string[TalkAddText.Count + 1][];
for (int i = 0; i < output.Length; i++)
{
output[i] = rowData[i];
}
int length = output.GetLength(0);
string delimiter = ",";
StringBuilder sb = new StringBuilder();
for (int index = 0; index < length; index++)
{
sb.AppendLine(string.Join(delimiter, output[index]));
}
string filePath = getPath();
StreamWriter outStream = System.IO.File.CreateText(filePath);
outStream.WriteLine(sb);
outStream.Close();
Debug.Log(filePath);
}
private string getPath()
{
#if UNITY_EDITOR
return Application.dataPath + "/TalkData.csv";
#elif UNITY_ANDROID
return Application.persistentDataPath+"TalkData.csv";
#elif UNITY_IPHONE
return Application.persistentDataPath+"/"+"TalkData.csv";
#else
return Application.dataPath +"/"+"TalkData.csv";
#endif
}
view raw CSVWriter.cs hosted with ❤ by GitHub