void OnGUI() { TextAsset newCsv = EditorGUILayout.ObjectField("CSV", csv, typeof(TextAsset), false) as TextAsset; if (newCsv != csv) { csv = newCsv; arr = ParserCSV.Parse(csv.text); } if (GUILayout.Button("Refresh") && csv != null) { arr = ParserCSV.Parse(csv.text); } if (csv == null) { return; } if (arr == null) { arr = ParserCSV.Parse(csv.text); } for (int i = 0; i < arr.Length; i++) { EditorGUILayout.BeginHorizontal(); for (int j = 0; j < arr[i].Length; j++) { EditorGUILayout.TextField(arr[i][j]); } EditorGUILayout.EndHorizontal(); } }
private void ImportNameAndInfo() { var path = EditorUtility.OpenFilePanel("选择信息文档", Application.dataPath, "csv"); if (!string.IsNullOrEmpty(path)) { var text = System.IO.File.ReadAllText(path, System.Text.Encoding.GetEncoding("gb2312")); var csv = ParserCSV.Parse(text); for (int i = 1; i < csv.Length; i++) { var array = csv[i]; var name = array[0]; var infomation = array[1]; if (nodeList.Count > i - 1) { var item = nodeList[i - 1]; Debug.Assert(item.name == name, item.name + " != " + name); item.infomation = infomation; } else { nodeList.Add(new NaviNode()); var item = nodeList[i - 1]; Debug.Log("add:" + item.name); item.name = name; item.infomation = infomation; } } } }
public static string Generate(string csvText, string[] type, string className) { if (string.IsNullOrEmpty(csvText)) { return(null); } string[][] grid = ParserCSV.Parse(csvText); return(Generate(grid, type, className)); }
/// <summary> /// 加载数据 /// </summary> private void LoadConfigData() { if (inportText != null) { var grid = ParserCSV.Parse(inportText.text); for (int i = 1; i < grid.Length; i++) { Port row = new Port(); row.id = int.Parse(grid[i][0]); row.active = bool.Parse(grid[i][1]); row.supportTypes = grid[i][2].Split('|'); row.closeinfomation = grid[i][3]; inPorts.Add(row); } } if (outportText != null) { var grid = ParserCSV.Parse(outportText.text); for (int i = 1; i < grid.Length; i++) { Port row = new Port(); row.id = int.Parse(grid[i][0]); row.active = bool.Parse(grid[i][1]); row.supportTypes = grid[i][2].Split('|'); row.closeinfomation = grid[i][3]; outPorts.Add(row); } } if (equationText != null) { var grid = ParserCSV.Parse(equationText.text); for (int i = 1; i < grid.Length; i++) { Equation row = new Equation(); if (!string.IsNullOrEmpty(grid[i][0])) { row.intypes = grid[i][0].Split('|'); } if (!string.IsNullOrEmpty(grid[i][1])) { row.outtypes = grid[i][1].Split('|'); } row.interactTime = float.Parse(grid[i][2]); if (!string.IsNullOrEmpty(grid[i][3])) { row.conditions = grid[i][3].Split('|'); } row.illustrate = grid[i][4]; equations.Add(row); } } }
public override void Load(string csvData) { rowList.Clear(); grid = ParserCSV.Parse(csvData); for (int i = 1; i < grid.Length; i++) { Row row = new Row(); row.name = grid[i][0]; row.sex = grid[i][1]; rowList.Add(row); } isLoaded = true; }
public static string Generate(string csvText, string[] type, string className) { if (string.IsNullOrEmpty(csvText)) { return(null); } string[][] grid = ParserCSV.Parse(csvText); if (grid.Length < 1) { return(null); } string rowMemberCode = ""; string rowReadCode = ""; string rowSaveCode = ""; string findCode = ""; string whileNullCode1 = string.Format("\t\t\tif (grid[0] == null) grid[0] = new string[{0}];\n", grid[0].Length); string whileNullCode2 = string.Format("\t\t\tif (grid[i] == null) grid[i] = new string[{0}];", grid[0].Length); for (int i = 0; i < grid[0].Length; i++) { whileNullCode1 += string.Format("\t\t\tgrid[0][{0}] = \"{1}\";\n", i, grid[0][i]); if (type[i] == "string") { rowMemberCode += string.Format("\t\tpublic string {0};\n", grid[0][i]); rowReadCode += string.Format("\t\t\trow.{0} = grid[i][{1}];\n", grid[0][i], i); rowSaveCode += string.Format("\t\t\tgrid[i][{0}] = row.{1};\n", i, grid[0][i]); findCode += findCodeTemplate.Replace("$FIND_COLUMN", grid[0][i]).Replace("$COLUMN", grid[0][i]); } else { rowMemberCode += string.Format("\t\tpublic {0} {1};\n", type[i], grid[0][i]); rowReadCode += string.Format("\t\t\trow.{0} = {1}.Parse(grid[i][{2}]);\n", grid[0][i], type[i], i); rowSaveCode += string.Format("\t\t\tgrid[i][{0}] = row.{1}.ToString();\n", i, grid[0][i]); findCode += findCodeTemplate.Replace("$FIND_COLUMN", grid[0][i] + ".ToString()").Replace("$COLUMN", grid[0][i]); } } string code = codeTemplate; code = code.Replace("$CLASS", className); code = code.Replace("$ROW_MEMBER_CODE", rowMemberCode); code = code.Replace("$ROW_READ_CODE", rowReadCode); code = code.Replace("$ROW_SAVE_CODE", rowSaveCode); code = code.Replace("$FIND_CODE", findCode); code = code.Replace("$ROW_WHILENULL_CODE1", whileNullCode1); code = code.Replace("$ROW_WHILENULL_CODE2", whileNullCode2); return(code); }
public override void Load(string csvData) { rowList.Clear(); string[][] grid = ParserCSV.Parse(csvData); for (int i = 1; i < grid.Length; i++) { Row row = new Row(); row.title = grid[i][0]; row.information = grid[i][1]; rowList.Add(row); } isLoaded = true; }
public override void Load(string csvData) { rowList.Clear(); grid = ParserCSV.Parse(csvData); for (int i = 1; i < grid.Length; i++) { Row row = new Row(); row.a = byte.Parse(grid[i][0]); row.b = bool.Parse(grid[i][1]); row.c = float.Parse(grid[i][2]); rowList.Add(row); } isLoaded = true; }
/// <summary> /// 加载数据 /// </summary> private void LoadConfigData() { if (portText != null) { var grid = ParserCSV.Parse(portText.text); for (int i = 1; i < grid.Length; i++) { Port row = new Port(); row.id = int.Parse(grid[i][0]); row.active = bool.Parse(grid[i][1]); row.supportTypes = grid[i][2].Split('|'); row.closeinfomation = grid[i][3]; ports.Add(row); } } }
void FunctionButtons() { using (var hor = new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button("CSV<--")) { } if (GUILayout.Button("加载CSV")) { if (!string.IsNullOrEmpty(_path)) { string text = System.IO.File.ReadAllText(_path); if (!string.IsNullOrEmpty(text)) { arr = ParserCSV.Parse(text); } } } if (GUILayout.Button("加载Asset")) { } if (GUILayout.Button("-->Asset")) { Type listType = fielditem.FieldType; Type type = listType.GetMethod("Find").ReturnType; FieldInfo[] fields = type.GetFields(); for (int i = 0; i < fields.Length; i++) { Debug.Log(fields[i]); } //fielditem.FieldType.GetMethod("Clear").Invoke(fielditem.GetValue(obj),null); fielditem.SetValue(obj, Activator.CreateInstance(fielditem.FieldType)); for (int i = 0; i < arr.Length; i++) { var instance1 = Activator.CreateInstance(type); for (int j = 0; j < arr[i].Length; j++) { fields[j].SetValue(instance1, arr[i][j]); } fielditem.FieldType.GetMethod("Add").Invoke(fielditem.GetValue(obj), new object[] { instance1 }); } EditorUtility.SetDirty(obj); } } }
public override void Load(string csvData) { rowList.Clear(); grid = ParserCSV.Parse(csvData); for (int i = 1; i < grid.Length; i++) { Row row = new Row(); row.nodeID = int.Parse(grid[i][0]); row.inType = grid[i][1]; row.outType = grid[i][2]; row.information = grid[i][3]; row.action = grid[i][4]; row.outFailInformation = grid[i][5]; row.outFailAction = grid[i][6]; rowList.Add(row); } isLoaded = true; }
void LoadArrayDataFromFile() { if (System.IO.File.Exists(filePath)) { using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite)) { using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding("gb2312"))) { arr.Clear(); var newarray = ParserCSV.Parse(sr.ReadToEnd()); foreach (var item in newarray) { arr.Add(new List <string>(item)); } UpdateTypes(); } } } }
void OnGUI() { // CSV TextAsset newCsv = EditorGUILayout.ObjectField("CSV", csv, typeof(TextAsset), false) as TextAsset; if (newCsv != csv) { csv = newCsv; if (csv != null) { arr = ParserCSV.Parse(csv.text); } else { arr = null; } } // Script script = EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false) as MonoScript; // buttons EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Refresh") && csv != null) { arr = ParserCSV.Parse(csv.text); type = new string[arr[0].Length]; } if (GUILayout.Button("Generate Code")) { string path = ""; if (script != null) { path = AssetDatabase.GetAssetPath(script); } else { path = EditorUtility.SaveFilePanel("Save Script", "Assets", csv.name + "Table.cs", "cs"); } if (!string.IsNullOrEmpty(path)) { script = CreateScript(csv, path); } } EditorGUILayout.EndHorizontal(); // columns if (arr != null) { foldout = EditorGUILayout.Foldout(foldout, "Columns"); if (foldout) { EditorGUI.indentLevel++; if (csv != null && arr == null) { arr = ParserCSV.Parse(csv.text); type = new string[arr[0].Length]; } if (arr != null) { if (type == null) { type = new string[arr[0].Length]; } for (int i = 0; i < arr[0].Length; i++) { EditorGUILayout.LabelField(arr[0][i]); type[i] = EditorGUILayout.TextField(type[i]); if (string.IsNullOrEmpty(type[i])) { type[i] = "string"; } } } EditorGUI.indentLevel--; } } }