Exemple #1
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);
        }