Пример #1
0
            /// <summary>
            /// Ajoute une langue
            /// </summary>
            /// <param name="name">Nom de la langue à ajouter</param>
            /// <param name="langToCopy">Langue à partir de laquelle copier les textes</param>
            private static void AddLanguage(string name, LanguagesEnum font, LanguagesEnum langToCopy)
            {
                List <string> names = new List <string>();

                foreach (LanguagesEnum val in Enum.GetValues(typeof(LanguagesEnum)))
                {
                    names.Add(val.ToString());
                }
                if (!names.Contains(name))
                {
                    names.Add(name);
                    SaveLanguageList(names);
                }

                if (System.IO.Directory.Exists("Assets/Resources/Lang/Fonts/" + name))
                {
                    System.IO.Directory.Delete("Assets/Resources/Lang/Fonts/" + name, true);
                }
                if (System.IO.Directory.Exists("Assets/Resources/Lang/Fonts/" + font.ToString()))
                {
                    CopyFolder("Assets/Resources/Lang/Fonts/" + font.ToString(), "Assets/Resources/Lang/Fonts/" + name);
                }
                else
                {
                    System.IO.Directory.CreateDirectory("Assets/Resources/Lang/Fonts/" + name);
                }

                AddLanguageToText(name);
                AddLanguageToText(name, langToCopy);
            }
Пример #2
0
            //****************************************************************************************************************
            //**                                                   Private                                                  **
            //****************************************************************************************************************

            /// <summary>
            /// Affiche la partie vérification
            /// </summary>
            private static void FontCheckGUI()
            {
                GUILayout.BeginVertical();
                {
                    if (!showingDetails)
                    {
                        GUILayout.Space(8);
                        GUILayout.Label(LangWindowOption.EditorInEnglish ? "Font global state:" : "État global des polices :");
                        GUILayout.Space(8);

                        //Scrollview de toutes les langues
                        languageScrollPosition = GUILayout.BeginScrollView(languageScrollPosition);
                        {
                            GUILayout.BeginVertical();
                            {
                                GUILayout.Label("", GUI.skin.horizontalSlider);
                                foreach (LanguagesEnum language in Enum.GetValues(typeof(LanguagesEnum)))
                                {
                                    GUILayout.BeginHorizontal();
                                    {
                                        GUILayout.Label(language.ToString());
                                        GUILayout.FlexibleSpace();
                                        GUILayout.Space(5);
                                        int missings = 0;
                                        foreach (FontsEnum font in Enum.GetValues(typeof(FontsEnum)))
                                        {
                                            if (System.IO.Directory.Exists("Assets/Resources/Lang/Fonts/" + language.ToString()))
                                            {
                                                if (!System.IO.File.Exists("Assets/Resources/Lang/Fonts/" + language.ToString() + "/" + font.ToString() + ".ttf") &&
                                                    !System.IO.File.Exists("Assets/Resources/Lang/Fonts/" + language.ToString() + "/" + font.ToString() + ".dfont") &&
                                                    !System.IO.File.Exists("Assets/Resources/Lang/Fonts/" + language.ToString() + "/" + font.ToString() + ".otf"))
                                                {
                                                    missings++;
                                                }
                                            }
                                            else
                                            {
                                                missings++;
                                            }
                                        }
                                        if (missings <= 0)
                                        {
                                            Color oldGUIContentColor = GUI.contentColor;
                                            GUI.contentColor = Color.green;
                                            GUILayout.Label("OK");
                                            GUI.contentColor = oldGUIContentColor;
                                        }
                                        else
                                        {
                                            Color oldGUIContentColor = GUI.contentColor;
                                            GUI.contentColor = Color.red;
                                            GUILayout.Label(LangWindowOption.EditorInEnglish ? ("Missing " + missings + " font" + (missings > 1 ? "s" : "")) : (missings + " police" + (missings > 1 ? "s" : "") + " manquante" + (missings > 1 ? "s" : "")));
                                            GUI.contentColor = oldGUIContentColor;
                                        }
                                        GUILayout.Space(5);
                                        if (GUILayout.Button(LangWindowOption.EditorInEnglish ? "Details" : "Détails"))
                                        {
                                            showingDetails = true;
                                            langToDetail   = language;
                                        }
                                    }
                                    GUILayout.EndHorizontal();
                                    GUILayout.Label("", GUI.skin.horizontalSlider);
                                }
                            }
                            GUILayout.EndVertical();
                        }
                        GUILayout.EndScrollView();
                        GUILayout.Space(8);
                        GUILayout.FlexibleSpace();
                    }
                    else
                    {
                        GUILayout.Space(8);
                        GUILayout.Label(LangWindowOption.EditorInEnglish ? "The fonts of " + langToDetail.ToString() + ":" : "Polices en " + langToDetail.ToString() + " :");
                        GUILayout.Space(8);

                        //Scrollview de toutes les langues
                        languageScrollPosition = GUILayout.BeginScrollView(languageScrollPosition);
                        {
                            GUILayout.BeginVertical();
                            {
                                GUILayout.Label("", GUI.skin.horizontalSlider);
                                foreach (FontsEnum font in Enum.GetValues(typeof(FontsEnum)))
                                {
                                    GUILayout.BeginHorizontal();
                                    {
                                        GUILayout.Label(font.ToString());
                                        GUILayout.FlexibleSpace();
                                        GUILayout.Space(5);
                                        bool ok;
                                        if (System.IO.Directory.Exists("Assets/Resources/Lang/Fonts/" + langToDetail.ToString()))
                                        {
                                            ok = !System.IO.File.Exists("Assets/Resources/Lang/Fonts/" + langToDetail.ToString() + "/" + font.ToString() + ".ttf") &&
                                                 !System.IO.File.Exists("Assets/Resources/Lang/Fonts/" + langToDetail.ToString() + "/" + font.ToString() + ".dfont") &&
                                                 !System.IO.File.Exists("Assets/Resources/Lang/Fonts/" + langToDetail.ToString() + "/" + font.ToString() + ".otf");
                                        }
                                        else
                                        {
                                            ok = true;
                                        }

                                        if (!ok)
                                        {
                                            Color oldGUIContentColor = GUI.contentColor;
                                            GUI.contentColor = Color.green;
                                            GUILayout.Label("OK");
                                            GUI.contentColor = oldGUIContentColor;
                                        }
                                        else
                                        {
                                            Color oldGUIContentColor = GUI.contentColor;
                                            GUI.contentColor = Color.red;
                                            GUILayout.Label(LangWindowOption.EditorInEnglish ? "Missing" : "Manquante");
                                            GUI.contentColor = oldGUIContentColor;
                                        }
                                        GUILayout.Space(10);
                                        if (GUILayout.Button(LangWindowOption.EditorInEnglish ? "Modify" : "Modifier"))
                                        {
                                            newFontPath = EditorUtility.OpenFilePanel(LangWindowOption.EditorInEnglish ? "Modify font" : "Modifier la police", "", "ttf,otf,dfont");
                                            if (newFontPath.Length != 0)
                                            {
                                                string tmp = System.IO.Path.GetExtension(newFontPath);
                                                if (tmp == ".ttf")
                                                {
                                                    System.IO.File.Copy(newFontPath, "Assets/Resources/Lang/Fonts/" + langToDetail.ToString() + "/" + font.ToString() + ".ttf");
                                                }
                                                else if (tmp == ".otf")
                                                {
                                                    System.IO.File.Copy(newFontPath, "Assets/Resources/Lang/Fonts/" + langToDetail.ToString() + "/" + font.ToString() + ".otf");
                                                }
                                                else if (tmp == ".dfont")
                                                {
                                                    System.IO.File.Copy(newFontPath, "Assets/Resources/Lang/Fonts/" + langToDetail.ToString() + "/" + font.ToString() + ".dfont");
                                                }
                                                else
                                                {
                                                    EditorUtility.DisplayDialog(LangWindowOption.EditorInEnglish ? "Extension Error" : "Erreur d'extension", LangWindowOption.EditorInEnglish ? "Only .ttf, .otf and .dfont fonts are unity compatible." : "Seules les polices de type .ttf, .otf et .dfont sont compatibles avec unity.", "OK");
                                                }
                                            }
                                        }
                                        GUILayout.Space(5);
                                    }
                                    GUILayout.EndHorizontal();
                                    GUILayout.Label("", GUI.skin.horizontalSlider);
                                }

                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.FlexibleSpace();
                                    if (GUILayout.Button(LangWindowOption.EditorInEnglish ? "Back" : "Retour"))
                                    {
                                        showingDetails = false;
                                    }
                                }
                                GUILayout.EndHorizontal();
                                GUILayout.Space(8);
                                GUILayout.FlexibleSpace();
                            }
                            GUILayout.EndVertical();
                        }
                        GUILayout.EndScrollView();
                        GUILayout.Space(8);
                        GUILayout.FlexibleSpace();
                    }
                }
                GUILayout.EndVertical();
            }
Пример #3
0
 private Font LoadFont(FontsEnum font, LanguagesEnum lang)
 {
     return(Resources.Load <Font>("Lang/Fonts/" + lang.ToString() + "/" + font.ToString()));
 }
Пример #4
0
            /// <summary>
            /// Renvoi le dictionnaire associé au dictionnaire <paramref name="dictionary"/> pour la langue <paramref name="lang"/>.
            /// </summary>
            /// <param name="dictionary">dictionnaire qu'on veut charger</param>
            /// <param name="lang">langue qu'on veut charger</param>
            /// <returns></returns>
            private Dictionary <string, string> LoadTextDictionary(DictionariesEnum dictionary, LanguagesEnum lang)
            {
                TextAsset txtAsset = Resources.Load <TextAsset>("Lang/Texts/" + dictionary.ToString());

                if (txtAsset == null)
                {
                    Debug.LogError("Lang : no file at: Lang/Texts/" + dictionary.ToString());
                    return(null);
                }
                string txtString = txtAsset.text;

                string[] lines = txtString.Split(System.Environment.NewLine.ToCharArray());

                if (lines.Length <= 0)
                {
                    Debug.LogError("Lang : not enough lines in Lang/Texts/" + dictionary.ToString());
                    return(null);
                }

                string[] languages     = lines[0].Split('|');
                int      languageIndex = -1;

                for (int i = 0; i < languages.Length; i++)
                {
                    if (languages[i].Equals(lang.ToString()))
                    {
                        languageIndex = i;
                        break;
                    }
                }
                if (languageIndex < 0)
                {
                    Debug.LogError("Lang : " + lang.ToString() + " not found in Lang/Texts/" + dictionary.ToString());
                    return(null);
                }

                Dictionary <string, string> ret = new Dictionary <string, string>();

                string[] line;
                char[]   tmpCharArray;
                for (int i = 1; i < lines.Length; i++)
                {
                    line = lines[i].Split('|');
                    if (line.Length <= 0 || lines[i] == "")
                    {
                    }
                    else if (line.Length == 1)
                    {
                        Debug.LogError("LangPackage: dictionary " + dictionary + "  line " + i + " found only the key, skipping this line");
                    }
                    else if (!line[0].Equals(""))
                    {
                        tmpCharArray = line[languageIndex].ToCharArray();
                        if (tmpCharArray[0] == '"' && tmpCharArray[tmpCharArray.Length - 1] == '"')
                        {
                            line[languageIndex] = line[languageIndex].Substring(1, line[languageIndex].Length - 2);
                        }
                        line[languageIndex] = line[languageIndex].Replace("\"\"", "\"");
                        line[languageIndex] = line[languageIndex].Replace("\\n", "\n");
                        line[languageIndex] = line[languageIndex].Replace("{$pipe}", "|");
                        ret.Add(line[0], line[languageIndex]);
                    }
                }
                return(ret);
            }
Пример #5
0
            /// <summary>
            /// Retire <paramref name="lang"/> des dictionnaires
            /// </summary>
            /// <param name="lang">Langue à retirer</param>
            private static void RemoveLanguage(LanguagesEnum lang)
            {
                if (System.IO.Directory.Exists("Assets/Resources/Lang/Fonts/" + lang.ToString()))
                {
                    System.IO.Directory.Delete("Assets/Resources/Lang/Fonts/" + lang.ToString(), true);
                }

                List <string> names = new List <string>();

                foreach (LanguagesEnum val in Enum.GetValues(typeof(LanguagesEnum)))
                {
                    names.Add(val.ToString());
                }
                if (names.Contains(lang.ToString()))
                {
                    names.Remove(lang.ToString());
                    SaveLanguageList(names);
                }

                foreach (DictionariesEnum dictionary in Enum.GetValues(typeof(DictionariesEnum)))
                {
                    TextAsset txtAsset = Resources.Load <TextAsset>("Lang/Texts/" + dictionary.ToString());

                    if (txtAsset == null)
                    {
                        continue;
                    }
                    string txtString = txtAsset.text;

                    string[] lines = txtString.Split(System.Environment.NewLine.ToCharArray());

                    if (lines.Length <= 0)
                    {
                        continue;
                    }

                    string[] languages = lines[0].Split('|');
                    Dictionary <string, int> languagesIndexes = new Dictionary <string, int>();
                    List <string>            languagesList    = new List <string>();
                    for (int i = 1; i < languages.Length; i++)
                    {
                        languagesList.Add(languages[i]);
                        languagesIndexes.Add(languages[i], i);
                    }
                    if (!languagesList.Contains(lang.ToString()))
                    {
                        continue;
                    }

                    languagesList.Remove(lang.ToString());
                    languagesIndexes.Remove(lang.ToString());
                    languagesList.Sort();

                    Dictionary <string, string[]> tmpDico = new Dictionary <string, string[]>();
                    string[] line;
                    string[] newline;
                    for (int i = 1; i < lines.Length; i++)
                    {
                        if (lines[i] == "")
                        {
                            continue;
                        }
                        line    = lines[i].Split('|');
                        newline = new string[languagesList.Count];
                        for (int j = 0; j < newline.Length; j++)
                        {
                            if (languagesIndexes.ContainsKey(languagesList[j]))
                            {
                                newline[j] = line[languagesIndexes[languagesList[j]]];
                            }
                        }
                        tmpDico.Add(line[0], newline);
                    }

                    string dictionaryText = "";
                    for (int i = 0; i < languagesList.Count; i++)
                    {
                        dictionaryText += "|" + languagesList[i];
                    }
                    dictionaryText += System.Environment.NewLine;
                    foreach (KeyValuePair <string, string[]> pair in tmpDico)
                    {
                        dictionaryText += pair.Key;
                        for (int i = 0; i < pair.Value.Length; i++)
                        {
                            dictionaryText += "|" + pair.Value[i];
                        }
                        dictionaryText += System.Environment.NewLine;
                    }

                    System.IO.File.WriteAllText("Assets/Resources/Lang/Texts/" + dictionary.ToString() + ".txt", dictionaryText);
                }
                AssetDatabase.Refresh();
            }