This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} |
ㅇ
'🌍 Unity > 유니티 프로그래밍' 카테고리의 다른 글
gereric singleton의 RuntimeInitializeOnLoadMethod 실행문제 (3) | 2021.11.13 |
---|---|
Unity NavMesh RandomPoint (0) | 2020.08.20 |
유니티 csv 파일 읽기 ( Unity csv file read ) 수정 19.11.15 (2) | 2019.11.15 |
유니티 싱글톤(싱글턴) 기본 패턴 Unity singleton parttern (0) | 2019.11.15 |
유니티 안드로이드 스크린샷 / 스크린캡쳐 (Unity Android screenCapture) (1) | 2019.11.14 |