public static string Generate(string csvText, string className)
        {
            if (string.IsNullOrEmpty(csvText))
            {
                return(null);
            }

            string[][] grid = CsvParser2.Parse(csvText);
            if (grid.Length < 1)
            {
                return(null);
            }

            string rowMemberCode = "";
            string rowReadCode   = "";
            string findCode      = "";

            for (int i = 0; i < grid[0].Length; i++)
            {
                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);
                findCode      += findCodeTemplate.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("$FIND_CODE", findCode);

            return(code);
        }
示例#2
0
        void OnGUI()
        {
            var newCsv = EditorGUILayout.ObjectField("CSV", csv, typeof(TextAsset), false) as TextAsset;

            if (newCsv != csv)
            {
                csv = newCsv;
                arr = CsvParser2.Parse(csv.text);
            }
            if (GUILayout.Button("Refresh") && csv != null)
            {
                arr = CsvParser2.Parse(csv.text);
            }

            if (csv == null)
            {
                return;
            }

            if (arr == null)
            {
                arr = CsvParser2.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();
            }
        }
示例#3
0
        void OnGUI()
        {
            // CSV
            TextAsset newCsv = EditorGUILayout.ObjectField("CSV", csv, typeof(TextAsset), false) as TextAsset;

            if (newCsv != csv)
            {
                csv = newCsv;
                if (csv != null)
                {
                    arr = CsvParser2.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 = CsvParser2.Parse(csv.text);
            }
            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 = CsvParser2.Parse(csv.text);
                    }
                    if (arr != null)
                    {
                        for (int i = 0; i < arr[0].Length; i++)
                        {
                            EditorGUILayout.LabelField(arr[0][i]);
                        }
                    }
                    EditorGUI.indentLevel--;
                }
            }
        }