예제 #1
0
        // Token: 0x06002381 RID: 9089 RVA: 0x000ADC88 File Offset: 0x000ABE88
        public string GetData(CsvTable.LineBreak lineBreak = CsvTable.LineBreak.None, char separator = ',')
        {
            this.stringBuilder.Length = 0;
            if (lineBreak == CsvTable.LineBreak.None)
            {
                lineBreak = this.m_LineBreak;
            }
            if (lineBreak == CsvTable.LineBreak.None)
            {
                lineBreak = CsvTable.LineBreak.CRLF;
            }
            int num = 0;

            foreach (List <string> list in this.m_RawDataList)
            {
                num = Mathf.Max(num, list.Count);
            }
            foreach (List <string> list2 in this.m_RawDataList)
            {
                int count = list2.Count;
                for (int i = 0; i < num; i++)
                {
                    bool flag   = false;
                    int  length = this.stringBuilder.Length;
                    if (i < count)
                    {
                        string text    = list2[i];
                        int    length2 = text.Length;
                        for (int j = 0; j < length2; j++)
                        {
                            char c = text[j];
                            if (c == separator)
                            {
                                flag = true;
                            }
                            else if (c == '\n' || c == '\r')
                            {
                                flag = true;
                            }
                            else if (c == '"')
                            {
                                this.stringBuilder.Append('"');
                                flag = true;
                            }
                            this.stringBuilder.Append(c);
                        }
                    }
                    if (flag)
                    {
                        this.stringBuilder.Insert(length, '"');
                        this.stringBuilder.Append('"');
                    }
                    this.stringBuilder.Append(separator);
                }
                this.stringBuilder.Remove(this.stringBuilder.Length - 1, 1);
                this.stringBuilder.Append(CsvTable.lineBreakDict[lineBreak]);
            }
            return(this.stringBuilder.ToString());
        }
예제 #2
0
        private void OnGUI()
        {
            var enable = GUI.enabled;

            using (var scope = new GUILayout.HorizontalScope())
            {
                if (GUILayout.RepeatButton(new GUIContent("Select"), GUILayout.Width(60)))
                {
                    selectFile = EditorUtility.OpenFilePanelWithFilters("Select csv", selectDirectiry, new string[] { "Csv File", "csv" });
                    if (!string.IsNullOrEmpty(selectFile))
                    {
                        selectDirectiry = Path.GetDirectoryName(selectFile);
                    }
                }
                GUI.enabled = false;
                EditorGUILayout.TextArea(selectFile);
            }

            GUILayout.FlexibleSpace();

            GUI.enabled = !string.IsNullOrEmpty(selectFile);

            using (var scope = new GUILayout.HorizontalScope())
            {
                saveLienBreak = (CsvTable.LineBreak)EditorGUILayout.EnumPopup("Line break", saveLienBreak);

                EditorGUILayout.Space();

                var  newSeparator = EditorGUILayout.TextField("Separator", separator.ToString());
                char c;
                if (System.Char.TryParse(newSeparator, out c))
                {
                    separator = c;
                }
            }
            if (GUILayout.RepeatButton(new GUIContent("Save as...")))
            {
                var saveFile = EditorUtility.SaveFilePanel("Save csv", selectDirectiry, "Csv File", "csv");
                if (!string.IsNullOrEmpty(saveFile))
                {
                    var csvTable = new CsvTable("", File.ReadAllText(selectFile), false, false);
                    var csvData  = csvTable.GetData(saveLienBreak, separator);
                    File.WriteAllText(saveFile, csvData);

                    AssetDatabase.Refresh();

                    EditorUtility.DisplayDialog("Successful", saveFile, "Ok", "Cancel");
                }
            }

            GUI.enabled = enable;
        }