using System; using System.Collections.Generic; using System.IO; using UnityEngine; public class CSVHelper { public static IList Csv2List(string fileName, Func setFunc) { List list = new List(); TextAsset textAsset = Asset.LoadFromResources("Conf/DB", fileName); using (StringReader stringReader = new StringReader(textAsset.text)) { string text; while ((text = stringReader.ReadLine()) != null) { string[] arg = text.Split(new char[] { ',' }); list.Add(setFunc(arg)); } } return list; } public static IDictionary Csv2Dictionary(string fileName, Func setKey, Func setValue) { Dictionary dictionary = new Dictionary(); TextAsset textAsset = Asset.LoadFromResources("Conf/DB", fileName); using (StringReader stringReader = new StringReader(textAsset.text)) { string text; while ((text = stringReader.ReadLine()) != null) { string[] array = text.Split(new char[] { ',' }); dictionary.Add(setKey(array[0]), setValue(array)); } } return dictionary; } }