1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using System; public class CSVFileWriter : MonoBehaviour { private List<string[]> studentData = new List<string[]>(); void Write(){ string[] tempStudentData = new string[3]; tempStudentData[0] = “Name"; tempStudentData[1] = “Age"; tempStudentData[2] = “ID"; studentData.Add(tempStudentData); for(int i = 0; i < 10; i++) { tempStudentData = new string[3]; tempStudentData[0] = “Micheal"+i; // Name tempStudentData[1] = (i+20).ToString(); // Age tempStudentData[2] = i.ToString() // ID studentData.Add(tempStudentData); } string[][] output = new string[studentData.Count][]; for(int i = 0; i < output.Length; i++) { output[i] = studentData[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(); } private string getPath(){ #if UNITY_EDITOR return Application.dataPath +"/CSV/“+”/Student Data.csv"; #elif UNITY_ANDROID return Application.persistentDataPath+"Student Data.csv"; #elif UNITY_IPHONE return Application.persistentDataPath+"/"+"Student Data.csv"; #else return Application.dataPath +"/"+"Student Data.csv"; #endif } } | cs |
'게임 개발 > Unity3D' 카테고리의 다른 글
[Unity | 유니티] 메모리 최적화 (0) | 2019.09.06 |
---|---|
[Unity | 유니티] Manager vs. Controller vs. Handler (1) | 2019.03.11 |
[Unity | 유니티] 로그 On/Off를 위한 전용 로깅 스크립트 만들기 (0) | 2018.11.29 |
[Unity | 유니티] 커스텀 정렬 알고리즘 만들기 (0) | 2018.11.21 |
[Unity | 유니티] Serializable Class 활용하기 (30) | 2018.11.21 |