Esempio n. 1
0
 private static void Init()
 {
     wordsAllDics.Clear();
     foreach (var val in Enum.GetNames(typeof(XIHLanguage)))
     {
         Enum.TryParse(val, out XIHLanguage lge);
         if (lge == XIHLanguage.none)
         {
             continue;
         }
         LanguageCfg cfg = ResUtil.LoadScriptableObject <LanguageCfg>($"Config/Localization/{val}");
         if (cfg == null)
         {
             Debug.LogError($"File Not Exits in Config/Localization/{val}");
             continue;
         }
         if (cfg.keyWords == null)
         {
             continue;
         }
         foreach (var kw in cfg.keyWords)
         {
             if (!wordsAllDics.ContainsKey(kw.key))
             {
                 wordsAllDics[kw.key] = new Dictionary <XIHLanguage, string>();
             }
             wordsAllDics[kw.key][lge] = kw.word;
         }
     }
 }
        static HashSet <string> GetCfg(XIHLanguage language, ISheet sheet, int col)
        {
            LanguageCfg cfg = AssetDatabase.LoadAssetAtPath <LanguageCfg>($"Assets/Resources/Config/Localization/{language}");

            if (cfg == null)
            {
                cfg = ScriptableObject.CreateInstance <LanguageCfg>();
                AssetDatabase.CreateAsset(cfg, $"Assets/Resources/Config/Localization/{language}.asset");
            }
            cfg.keyWords = new List <KeyWord>();
            int              rowNum = 1;
            IRow             row    = sheet.GetRow(rowNum);
            string           key    = row?.GetCell(0)?.StringCellValue;
            HashSet <string> keys   = new HashSet <string>();

            while (!string.IsNullOrEmpty(key))
            {
                key = key.ToLower();
                if (keys.Contains(key))
                {
                    Debug.LogWarning($"包含重复Key:{key},在表中位置【{rowNum + 1}】行");
                }
                else
                {
                    string word = row.GetCell(col)?.StringCellValue;
                    if (string.IsNullOrEmpty(word))
                    {
                        Debug.LogWarning($"Key:{key}所对应word为空,在表中位置【{rowNum + 1}】行,【{col + 1}】列");
                    }
                    else
                    {
                        cfg.keyWords.Add(new KeyWord()
                        {
                            key = key, word = word
                        });
                    }
                }
                keys.Add(key);
                row = sheet.GetRow(++rowNum);
                key = row?.GetCell(0)?.StringCellValue;
            }
            EditorUtility.SetDirty(cfg);
            AssetDatabase.SaveAssets();
            return(keys);
        }
Esempio n. 3
0
        public static void SetLanguage(XIHLanguage language)
        {
            if (SavedLanguage == language && wordsDics.Count > 0)
            {
                return;
            }
            PlayerPrefs.SetInt("FATTY_LANGUAGE", (int)language);
            PlayerPrefs.Save();
            SavedLanguage = language;
            LanguageCfg cfg = ResUtil.LoadScriptableObject <LanguageCfg>($"Config/Localization/{SavedLanguage}");

            if (cfg == null)
            {
                Debug.LogError($"File Not Exits in Config/Localization/{SavedLanguage}");
                return;
            }
            wordsDics.Clear();
            foreach (var kw in cfg.keyWords)
            {
                wordsDics[kw.key] = kw.word;
            }
            LanugeChanged?.Invoke(SavedLanguage);
        }