void AnalizeSheet(ExcelSheet sheet)
        {
            sheet.SetHeaderAndSelectRow(1);
            var headers = sheet.CurrentRow;

            while (sheet.MoveNext())
            {
                var row     = sheet.CurrentRow;
                var mapping = row.ValuesWithHeader;
                if (!mapping.ContainsKey(HEADER_ID))
                {
                    Debug.LogErrorFormat("Sheet {0} doesn't have header {1}", sheet.Name, HEADER_ID);
                    return;
                }
                if (!mapping.ContainsKey(HEADER_REMARK))
                {
                    Debug.LogErrorFormat("Sheet {0} doesn't have header {1}", sheet.Name, HEADER_ID);
                    return;
                }
                var id     = mapping[HEADER_ID];
                var remark = mapping[HEADER_REMARK];
                VocabularyEntryType type = (VocabularyEntryType)System.Enum.Parse(typeof(VocabularyEntryType), mapping[HEADER_TYPE]);

                foreach (var kv in mapping)
                {
                    if (!string.IsNullOrEmpty(kv.Value) && kv.Key.StartsWith(HEADER_CONTENT))
                    {
                        var language = kv.Key.Substring(HEADER_CONTENT.Length);
                        var content  = kv.Value;
                        var font     = mapping[HEADER_FONT + language];

                        VocabularyEntryMap entryMap;
                        if (!_multiLanguageData.TryGetValue(language, out entryMap))
                        {
                            entryMap = new VocabularyEntryMap()
                            {
                                Language = language
                            };
                            _multiLanguageData.Add(language, entryMap);
                        }

                        entryMap.Add(new VocabularyEntry()
                        {
                            ID       = id,
                            Type     = type,
                            Remark   = remark,
                            Language = language,
                            Content  = content,
                            FontName = font,
                        });

                        if (string.IsNullOrEmpty(content))
                        {
                            Debug.LogWarningFormat("Vocabulary [{0}] content in language {1} is null!", id, language);
                        }
                    }
                }
            }
        }
예제 #2
0
        public static void CreateSourceFile(VocabularyEntryMap data, string @namespace, string baseClassName)
        {
            var list = data.Select(t => new IDWithComment(t.ID, t.Remark)).ToList();
            var str  = GenerateFileContent(list, @namespace, baseClassName);

            var fileFullPath = Application.dataPath + Localization.CONSTANT_ID_FILE.Substring(6);
            var directory    = Directory.GetParent(fileFullPath);

            if (!Directory.Exists(directory.FullName))
            {
                Directory.CreateDirectory(directory.FullName);
            }

            File.WriteAllText(fileFullPath, str);

            Debug.Log("Generated id constant file. " + Localization.CONSTANT_ID_FILE);

            AssetDatabase.Refresh();
        }