private void LoadHistoryData() { if (_historyDatas != null) { return; } _historyDatas = new List <History>(); TextAsset csv = Resources.Load("history") as TextAsset; using (var streamReader = new StreamReader(new MemoryStream(csv.bytes))) { using (var reader = new Mono.Csv.CsvFileReader(streamReader)) { var stringArray = new List <List <string> >(); reader.ReadAll(stringArray); stringArray.RemoveAt(0); //Index 2: 이미지 //Index 3: 스크립트 foreach (List <string> column in stringArray) { History data = new History(); data.sprites = column[2]; data.script = column[3]; _historyDatas.Add(data); } } } }
private void LoadEndingData() { _endingDatas = new List <EndingData>(); TextAsset csv = Resources.Load("ending") as TextAsset; using (var streamReader = new StreamReader(new MemoryStream(csv.bytes))) { using (var reader = new Mono.Csv.CsvFileReader(streamReader)) { var stringArray = new List <List <string> >(); reader.ReadAll(stringArray); stringArray.RemoveAt(0); //Index 0: 현재 투표 인덱스 //Index 1: 날짜 //Index 2: 질문 //Index 4: 제목 //Index 9: 설명 //Index 12: 힌트 foreach (List <string> column in stringArray) { EndingData data = new EndingData(); data.endingQuestion = column[2]; data.endingHint = column[12]; data.endingDescription = column[9]; data.endingTitle = column[4]; _endingDatas.Add(data); } } } }
public static bool Initialize(string fileName) { _voteDatas = new List <VoteData>(); _endingCodition = new List <string>(); TextAsset csv = Resources.Load(fileName) as TextAsset; if (csv == null) { return(false); } using (var streamReader = new StreamReader(new MemoryStream(csv.bytes))) { using (var reader = new Mono.Csv.CsvFileReader(streamReader)) { var stringArray = new List <List <string> >(); reader.ReadAll(stringArray); stringArray.RemoveAt(0); //Index 0: 현재 투표 인덱스 //Index 1: 날짜 //Index 2: 질문 //Index 7: 동의시 다음 투표 인덱스 //Index 8: 비동의시 다음 투표 인덱스 //Index 9 : 기권시 다음 투표 값 (에 || 아니오) //Index 10: 동의 economy //Index 11: 동의 political //Index 12: 동의 mechanic //Index 13: 비동의 economy //Index 14: 비동의 political //Index 15: 비동의 mechanic //Index 19: 엔딩조건 foreach (List <string> column in stringArray) { if (!column[19].Equals("")) { _endingCodition.Add(column[19]); } _voteDatas.Add(GenerateVoteData(column)); } } } return(true); }
// Use this for initialization void Start() { if (news == null) { // load once TV04.news = new List <News>(); TextAsset csv = Resources.Load(newsFile) as TextAsset; if (csv == null) { Debug.Assert(false); return; } using (var streamReader = new StreamReader(new MemoryStream(csv.bytes))) { using (var reader = new Mono.Csv.CsvFileReader(streamReader)) { // 0: id (N1) // 1: article List <string> row = new List <string>(); reader.ReadRow(row); // first row is header // keep read content while (reader.ReadRow(row)) { var news = new News(); news.article = row[1]; TV04.news.Add(news); } } } Debug.Log("news loaded"); } var currentNews = news[VoteManager.currentVote.id - 1]; transform.Find("Article").GetComponent <Text>().text = currentNews.article; }
public static bool TestWithRow(string inputFile, string outputFile) { using (var sr = new StreamReader (inputFile, Encoding.GetEncoding ("gbk"))) { var reader = new CsvFileReader (sr); using( var sw = new StreamWriter (outputFile, false, Encoding.GetEncoding ("gbk")) ) { var writer = new CsvFileWriter(sw); Console.WriteLine ("------------------------------------------------------------------------------"); var row = new List<string> (); while (reader.ReadRow(row)) { PrintRow(row); writer.WriteRow( row ); } Console.WriteLine ("------------------------------------------------------------------------------"); } } return CompareFile (inputFile, outputFile); }
public static List<List<string>> ReadAll(string path, Encoding encoding) { using (var sr = new StreamReader (path, encoding)) { var cfr = new CsvFileReader(sr); List<List<string>> dataGrid = new List<List<string>>(); if(cfr.ReadAll(dataGrid)) return dataGrid; } return null; }