// Reads a CSV that is formatted as comma separated values per line // The first line must contain the legend public static CSVResult ReadCSVFile(string filePath) { FileStream fileStream = FileUtils.OpenFileStream(filePath, FileMode.Open, FileAccess.Read); if (fileStream == null) { return(null); } StreamReader streamReader = new StreamReader(fileStream); if (streamReader.Peek() < 0) { TimiDebug.LogErrorColor("Empty file", LogColor.grey); return(null); } CSVResult result = new CSVResult(); // Read the legend from the first line string legendLine = streamReader.ReadLine(); string[] legend = legendLine.Split(','); for (int i = 0; i < legend.Length; ++i) { result.keysPerItem.Add(legend[i]); } int lineNumber = 0; while (streamReader.Peek() >= 0) { ++lineNumber; string line = streamReader.ReadLine(); string[] words = line.Split(','); if (result.keysPerItem.Count != words.Length) { TimiDebug.LogWarningColor("Malformed item on line number: " + lineNumber, LogColor.grey); continue; } CSVItem item = new CSVItem(); for (int i = 0; i < result.keysPerItem.Count; ++i) { item.values[result.keysPerItem[i]] = words[i]; } result.items.Add(item); } fileStream.Close(); return(result); }
/// <summary> /// 绘制一条内容 /// </summary> /// <param name="str">大标题内容</param> /// <param name="message">小标题内容</param> public static void DrawOneContent(CSVItem info) { if (_H1 == null) { Init(); } //说明样式 if (!string.IsNullOrEmpty(info.H1)) { GUILayout.BeginHorizontal(); if (!string.IsNullOrEmpty(info.Url)) { if (GUILayout.Button(info.H1, _LinkH1, GUILayout.ExpandWidth(true))) { Application.OpenURL(info.Url); } } else { GUILayout.Label(info.H1, _H1, GUILayout.ExpandWidth(true)); } GUILayout.EndHorizontal(); } else { //绘制正常的 EditorGUILayout.BeginVertical(new GUIStyle("Box")); EditorGUILayout.TextArea(info.H2, _style01); EditorGUILayout.TextArea(info.Description, _Tx_Dec); EditorGUILayout.EndVertical(); } }