public static CSVFileEx CreateCSVFileFromMemory(string textData) { string[] Split = { "\r\n" }; string[] lineArray = textData.Split(Split, StringSplitOptions.RemoveEmptyEntries); if (lineArray.Length <= 1) { return(null); } CSVFileEx newCSVFile = new CSVFileEx(); newCSVFile.m_Path = ""; newCSVFile.Elem = new string[lineArray.Length][]; for (int i = 0; i < lineArray.Length; i++) { newCSVFile.Elem[i] = lineArray[i].Split(new char[] { ',', '\t' }); } for (int i = 0; i < newCSVFile.Elem[0].Length; ++i) { newCSVFile.NameToCol.Add(newCSVFile.Elem[0][i], i); } newCSVFile.TypeToCol = new CSVType[newCSVFile.Elem[2].Length]; for (int i = 0; i < newCSVFile.Elem[2].Length; ++i) { newCSVFile.TypeToCol[i] = (CSVType)Enum.Parse(typeof(CSVType), newCSVFile.Elem[2][i].ToUpper()); } return(newCSVFile); }
public static CSVFileEx CreateCSVFile(string strPath) { UnityEngine.Object obj = Resources.Load(strPath); TextAsset textAsset = obj as TextAsset; if (textAsset == null) { return(null); } CSVFileEx newCSVFile = CreateCSVFileFromMemory(textAsset.text); newCSVFile.m_Path = strPath; return(newCSVFile); }
public static CSVFileEx CreateCSVFileByStream(string strPath) { // FileStream file = null; // try // { // file = new FileStream(strPath, FileMode.Open); // } // catch (Exception ) // { // return null; // } // // long FileSize = file.Length; // if (FileSize == 0) // { // return null; // } // // byte[] byData = new byte[FileSize]; // // //file.Seek(0, SeekOrigin.Begin); // file.Read(byData, 0, (int)FileSize); // // file.Close(); string textAsset = ""; #if !UNITY_WEBPLAYER try { textAsset = File.ReadAllText(strPath, System.Text.Encoding.UTF8); } catch (Exception e) { Log.Print(Log.Level.Error, "Read File Path:" + strPath + " Error, Exception:" + e.Message + " Stack:" + e.StackTrace); return(null); } #else Log.Print(Log.Level.Error, "This function is not support on webplayer"); #endif CSVFileEx newCSVFile = CreateCSVFileFromMemory(textAsset); newCSVFile.m_Path = strPath; return(newCSVFile); }