public void OnEnable()
 {
     if (!PlayerPrefs.HasKey("LocaleLanguage"))
     {
         LocaleSettings localeSettings = (LocaleSettings)target;
         if (localeSettings.defaultLocale != LocaleCode.Null)
         {
             PlayerPrefs.SetString("LocaleLanguage", localeSettings.defaultLocale.ToString());
         }
     }
 }
Beispiel #2
0
        public static void WindowOpen()
        {
            GetWindow <EditorWindowLocaleCore>(false, "Locale Core", true);
            string editorCachePath = EditorPrefs.GetString("LocaleExportPath");

            if (string.IsNullOrEmpty(editorCachePath))
            {
                EditorPrefs.SetString("Locale Export Path", "Resources/" + Locale.defaultResourcePath);
            }
            else
            {
                exportPath = editorCachePath;
            }
            cachedLocaleSettings = GetLocaleSettings();
            isPreload            = true;
        }
Beispiel #3
0
 public static LocaleSettings GetLocaleSettings()
 {
     if (cachedLocaleSettings == null)
     {
         cachedLocaleSettings = Resources.Load <LocaleSettings>(Locale.defaultResourcePath + "/" + Locale.localeSettingsName);
         if (cachedLocaleSettings == null)
         {
             LocaleSettings _settings = CreateAsset <LocaleSettings>("Resources/" + Locale.defaultResourcePath, Locale.localeSettingsName);
             _settings.availableLocale     = new LocaleCode[0];
             _settings.sheetTitles         = new string[0];
             _settings.defaultLocale       = LocaleCode.EN;
             _settings.isUseSystemLanguage = true;
             EditorUtility.SetDirty(_settings);
             AssetDatabase.SaveAssets();
             AssetDatabase.Refresh();
         }
     }
     return(cachedLocaleSettings);
 }
Beispiel #4
0
        public static void BatchExport()
        {
            LocaleSettings _settings = GetLocaleSettings();

            if (_settings == null)
            {
                EditorUtility.DisplayDialog("Error", "Cannot perform this action because the editor cannot find any \'LocalizationSettings\' in resource path.", "Okay");
                Debug.LogError("Cannot find LocalizationSettings.asset");
                return;
            }
            if (sourceCSV == null)
            {
                EditorUtility.DisplayDialog("Error", "Cannot perform this action because CSV source are null.", "Okay");
                Debug.LogError("Source are null.");
                return;
            }
            if (string.IsNullOrEmpty(exportPath))
            {
                string exportPath = EditorUtility.OpenFolderPanel("Select localization for export XML file.", Application.dataPath, "");
                if (string.IsNullOrEmpty(exportPath))
                {
                    exportPath = "";
                    return;
                }
                else
                {
                    EditorPrefs.SetString("LocaleExportPath", exportPath);
                }
            }
            TextAsset textAssetCSV = sourceCSV as TextAsset;
            string    fileName     = textAssetCSV.name;

            string[][] table = CSVTextAsset(textAssetCSV);
            if (table == null)
            {
                return;
            }
            List <LocaleSheetData> sheets = new List <LocaleSheetData>();

            for (int c = 1; c < table[0].Length; c++)
            {
                LocaleSheetData sheet = new LocaleSheetData();
                sheet.LocaleName = table[0][c];
                sheet.List       = new LocaleKey[table.Length - 1];
                for (int r = 1; r < table.GetLength(0); r++)
                {
                    sheet.List[r - 1] = new LocaleKey(table[r][0], table[r][c]);
                }
                sheets.Add(sheet);
            }

            List <LocaleCode> availableLocale;

            if (_settings.availableLocale != null)
            {
                availableLocale = new List <LocaleCode>(_settings.availableLocale);
            }
            else
            {
                availableLocale = new List <LocaleCode>();
            }
            foreach (LocaleSheetData sheet in sheets)
            {
                try
                {
                    LocaleCode code       = LocaleCode.Null;
                    LocaleData localeData = null;
                    code = (LocaleCode)System.Enum.Parse(typeof(LocaleCode), sheet.LocaleName);
#if LOCALE_DATATH
                    if (code == LocaleCode.TH)
                    {
                        localeData = CreateAsset <LocaleDataTH>(exportPath + "/" + sheet.LocaleName, fileName);
                    }
                    else
                    {
                        localeData = CreateAsset <LocaleData>(exportPath + "/" + sheet.LocaleName, fileName);
                    }
#else
                    localeData = CreateAsset <LocaleData>(exportPath + "/" + sheet.LocaleName, fileName);
#endif
                    localeData.list = sheet.List;
                    if (code != LocaleCode.Null && !availableLocale.Contains(code))
                    {
                        availableLocale.Add(code);
                    }
                    EditorUtility.SetDirty(localeData);
                }
                catch
                {
                    EditorUtility.DisplayDialog("Error", "Cannot parse \'" + sheet.LocaleName + "\' into \'LocaleCode\' enum. Please check your LocaleCode in CSV.", "Okay");
                }
            }
            _settings.availableLocale = availableLocale.ToArray();

            if (isPreload)
            {
                List <string> sheetTitle;
                if (_settings.availableLocale != null)
                {
                    sheetTitle = new List <string>(_settings.sheetTitles);
                }
                else
                {
                    sheetTitle = new List <string>();
                }
                if (!sheetTitle.Contains(fileName))
                {
                    sheetTitle.Add(fileName);
                }
                _settings.sheetTitles = sheetTitle.ToArray();
                EditorUtility.SetDirty(_settings);
            }
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }