Beispiel #1
0
        private void ExportCSV(string csvFilename, bool separateFiles)
        {
            if (separateFiles)
            {
                foreach (var languageKvp in m_textTable.languages)
                {
                    var language   = languageKvp.Key;
                    var languageID = languageKvp.Value;
                    var content    = new List <List <string> >();
                    var row        = new List <string>();
                    row.Add("Language");
                    row.Add(language);
                    content.Add(row);
                    foreach (var fieldKvp in m_textTable.fields)
                    {
                        var field = fieldKvp.Value;
                        row = new List <string>();
                        row.Add(field.fieldName);
                        row.Add(field.GetTextForLanguage(languageID));
                        content.Add(row);
                    }
                    var languageFilename = csvFilename.Substring(0, csvFilename.Length - 4) + "_" + language + ".csv";
                    CSVUtility.WriteCSVFile(content, languageFilename, GetEncodingType());
                }
            }
            else
            {
                // All in one file:
                var content     = new List <List <string> >();
                var languageIDs = new List <int>();

                // Heading rows:
                var row = new List <string>();
                content.Add(row);
                row.Add("Field");
                foreach (var kvp in m_textTable.languages)
                {
                    var language   = kvp.Key;
                    var languageID = kvp.Value;
                    languageIDs.Add(languageID);
                    row.Add(language);
                }

                // One row per field:
                foreach (var kvp in m_textTable.fields)
                {
                    var field = kvp.Value;
                    row = new List <string>();
                    content.Add(row);
                    row.Add(field.fieldName);
                    for (int i = 0; i < languageIDs.Count; i++)
                    {
                        var languageID = languageIDs[i];
                        var value      = field.GetTextForLanguage(languageID);
                        row.Add(value);
                    }
                }
                CSVUtility.WriteCSVFile(content, csvFilename, GetEncodingType());
            }
        }
Beispiel #2
0
        private void ImportCSV(string csvFilename)
        {
            var content = CSVUtility.ReadCSVFile(csvFilename, GetEncodingType());

            if (content == null || content.Count < 1 || content[0].Count < 2)
            {
                return;
            }
            var firstCell = content[0][0];

            if (string.Equals(firstCell, "Language"))
            {
                // Single language file:
                var language = content[0][1];
                if (!m_textTable.HasLanguage(language))
                {
                    m_textTable.AddLanguage(language);
                }
                for (int y = 1; y < content.Count; y++)
                {
                    var field = content[y][0];
                    if (!m_textTable.HasField(field))
                    {
                        m_textTable.AddField(field);
                    }
                    for (int x = 1; x < content[y].Count; x++)
                    {
                        m_textTable.SetFieldTextForLanguage(field, language, content[y][x]);
                    }
                }
            }
            else
            {
                // All-in-one file:
                for (int x = 1; x < content[0].Count; x++)
                {
                    var language = content[0][x];
                    if (!m_textTable.HasLanguage(language))
                    {
                        m_textTable.AddLanguage(language);
                    }
                    for (int y = 1; y < content.Count; y++)
                    {
                        var field = content[y][0];
                        if (!m_textTable.HasField(field))
                        {
                            m_textTable.AddField(field);
                        }
                        m_textTable.SetFieldTextForLanguage(field, language, content[y][x]);
                    }
                }
            }
            EditorUtility.SetDirty(m_textTable);
        }
        private void ImportCSV(string csvFilename)
        {
            var content = CSVUtility.ReadCSVFile(csvFilename, GetEncodingType());

            if (content == null || content.Count < 1 || content[0].Count < 2)
            {
                return;
            }
            var fieldList = new List <string>();
            var firstCell = content[0][0];

            if (string.Equals(firstCell, "Language"))
            {
                // Single language file:
                var language = content[0][1];
                if (!string.IsNullOrEmpty(language))
                {
                    if (!m_textTable.HasLanguage(language))
                    {
                        m_textTable.AddLanguage(language);
                    }
                    for (int y = 1; y < content.Count; y++)
                    {
                        var field = content[y][0];
                        if (string.IsNullOrEmpty(field))
                        {
                            continue;
                        }
                        fieldList.Add(field);
                        if (!m_textTable.HasField(field))
                        {
                            m_textTable.AddField(field);
                        }
                        for (int x = 1; x < content[y].Count; x++)
                        {
                            m_textTable.SetFieldTextForLanguage(field, language, content[y][x]);
                        }
                    }
                }
            }
            else
            {
                // All-in-one file:
                for (int x = 1; x < content[0].Count; x++)
                {
                    var language = content[0][x];
                    if (string.IsNullOrEmpty(language))
                    {
                        continue;
                    }
                    if (!m_textTable.HasLanguage(language))
                    {
                        m_textTable.AddLanguage(language);
                    }
                    for (int y = 1; y < content.Count; y++)
                    {
                        var field = content[y][0];
                        if (string.IsNullOrEmpty(field))
                        {
                            continue;
                        }
                        if (x == 1)
                        {
                            fieldList.Add(field);
                        }
                        if (!m_textTable.HasField(field))
                        {
                            m_textTable.AddField(field);
                        }
                        if ((0 <= y && y < content.Count) && (0 <= x && x < content[y].Count))
                        {
                            m_textTable.SetFieldTextForLanguage(field, language, content[y][x]);
                        }
                    }
                }
            }
            m_textTable.ReorderFields(fieldList);
            m_textTable.OnBeforeSerialize();
            m_serializedObject.Update();
            RebuildFieldCache();
            EditorUtility.SetDirty(m_textTable);
        }