Esempio n. 1
0
        public void CreateWorkspace(bool bOpenRoot = true)
        {
            if (!WorkspaceExists())
            {
                Directory.CreateDirectory(Localizator.Path.WorkspaceRootPath);
                Directory.CreateDirectory(Localizator.Path.DatabaseRootPath);
                Directory.CreateDirectory(Localizator.Path.BackupRootPath);
                Directory.CreateDirectory(Localizator.Path.GeneratedFilesRootPath);
                Directory.CreateDirectory(Localizator.Path.ScriptRootPath);

                DefaultLanguage = _currentDefaultLanguage;

                _localizationDatabaseFiles = new Dictionary <SystemLanguage, string>();
                _localizationDatabaseFiles.Add(DefaultLanguage, DefaultLanguage.ToString() + ".csv");

                SaveRootFile();
                SaveLocalizationFile(DefaultLanguage.ToString());
                SaveWorkspace();

                LanguageManager.CreateInstance();

                if (bOpenRoot)
                {
                    EditorWindow.GetWindow <CustomEditorWindow_Localizator_EditRoot>("Edit Root", true, typeof(CustomEditorWindow_Localizator));
                }
            }
            AssetDatabase.Refresh();
        }
Esempio n. 2
0
        void OnGUI()
        {
            GUIStyle titleStyle = new GUIStyle("button");

            titleStyle.alignment = TextAnchor.MiddleCenter;
            titleStyle.fontSize  = 20;
            titleStyle.fontStyle = FontStyle.Bold;

            GUIStyle centeredStyle = new GUIStyle();

            centeredStyle.alignment = TextAnchor.MiddleCenter;

            GUIStyle centeredMediumStyle = new GUIStyle();

            centeredMediumStyle.alignment = TextAnchor.MiddleCenter;
            centeredMediumStyle.fontSize  = 15;
            centeredMediumStyle.fontStyle = FontStyle.Bold;

            GUIStyle leftMiddleStyle = new GUIStyle();

            leftMiddleStyle.alignment = TextAnchor.MiddleLeft;
            leftMiddleStyle.fontSize  = 15;
            leftMiddleStyle.fontStyle = FontStyle.Bold;

            GUIStyle enumPopup = new GUIStyle("popup");

            enumPopup.alignment = TextAnchor.MiddleCenter;
            enumPopup.fontSize  = 20;
            enumPopup.fontStyle = FontStyle.Bold;

            List <SystemLanguage> languageToRemove = new List <SystemLanguage>();

            EditorGUILayout.BeginVertical();
            {
                GUILayout.Label("Localization Editor Workspace v" + LanguageManager.VERSION, titleStyle);
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.Separator();

            if (!WorkspaceExists())
            {
                EditorGUILayout.BeginHorizontal("box", GUILayout.Height(titleStyle.lineHeight));
                {
                    GUILayout.Label("Select Default Language:", titleStyle);
                    EditorGUILayout.BeginVertical();
                    {
                        GUILayout.FlexibleSpace();
                        _currentDefaultLanguage = (SystemLanguage)EditorGUILayout.EnumPopup(_currentDefaultLanguage);
                        GUILayout.FlexibleSpace();
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();
                if (!_currentDefaultLanguage.Equals(SystemLanguage.Unknown))
                {
                    GUI.color = Color.green;
                    if (GUILayout.Button("Create Localization Workspace", titleStyle))
                    {
                        CreateWorkspace();
                    }
                    GUI.color = _defaultColor;
                }
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.BeginVertical(GUILayout.Width(position.width * 0.5f - 10));
                    {
                        GUILayout.Label("Add Language", centeredMediumStyle);
                        EditorGUILayout.BeginHorizontal("box");
                        {
                            _scrollPositionLanguagesAdd = EditorGUILayout.BeginScrollView(_scrollPositionLanguagesAdd, GUILayout.ExpandHeight(true));
                            {
                                foreach (string langName in Enum.GetNames(typeof(SystemLanguage)))
                                {
                                    SystemLanguage currentLang = (SystemLanguage)Enum.Parse(typeof(SystemLanguage), langName);

                                    if (currentLang != SystemLanguage.Unknown && !_localizationDatabaseFiles.ContainsKey(currentLang))
                                    {
                                        EditorGUILayout.BeginHorizontal("box", GUILayout.ExpandWidth(true));
                                        {
                                            EditorGUILayout.LabelField(langName);
                                            if (GUILayout.Button("+", GUILayout.Width(50)))
                                            {
                                                _localizationDatabaseFiles.Add(currentLang, currentLang.ToString() + ".csv");
                                                if (!File.Exists(Localizator.Path.DatabaseRootPath + langName + ".csv"))
                                                {
                                                    SaveLocalizationFile(currentLang.ToString());
                                                }
                                            }
                                        }
                                        EditorGUILayout.EndHorizontal();
                                    }
                                }
                            }
                            EditorGUILayout.EndScrollView();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                    {
                        GUILayout.Label("Options", centeredMediumStyle);
                        EditorGUILayout.BeginVertical("box");
                        {
                            EditorGUILayout.BeginHorizontal("box");
                            {
                                EditorGUILayout.LabelField("Change Default Language");
                                List <string> list = new List <string>();
                                foreach (KeyValuePair <SystemLanguage, string> value in _localizationDatabaseFiles)
                                {
                                    list.Add(value.Key.ToString());
                                }
                                string[] langs = list.ToArray();

                                int index    = list.IndexOf(DefaultLanguage.ToString());
                                int selected = EditorGUILayout.Popup(index, langs);
                                if (selected != index)
                                {
                                    DefaultLanguage = (SystemLanguage)Enum.Parse(typeof(SystemLanguage), langs[selected]);
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.Separator();
                            EditorGUILayout.BeginHorizontal("box");
                            {
                                EditorGUILayout.LabelField("Language Manager");
                                if (LanguageManager.Instance == null)
                                {
                                    if (GUILayout.Button("Create"))
                                    {
                                        LanguageManager.CreateInstance();
                                    }
                                }
                                else
                                {
                                    if (GUILayout.Button("Select"))
                                    {
                                        Selection.activeGameObject = LanguageManager.Instance.gameObject;
                                    }
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginVertical("box", GUILayout.Height(250));
                {
                    GUILayout.Label("Created Languages", centeredMediumStyle);

                    if (GUILayout.Button("Edit Root File", GUILayout.ExpandWidth(true), GUILayout.Height(30)))
                    {
                        EditorWindow.GetWindow <CustomEditorWindow_Localizator_EditRoot>(typeof(CustomEditorWindow_Localizator));
                    }

                    _scrollPositionLanguagesEdit = EditorGUILayout.BeginScrollView(_scrollPositionLanguagesEdit);
                    {
                        foreach (KeyValuePair <SystemLanguage, string> value in _localizationDatabaseFiles)
                        {
                            EditorGUILayout.BeginHorizontal("box", GUILayout.Height(30));
                            {
                                GUILayout.Space(10);
                                GUILayout.Label(value.Key.ToString(), leftMiddleStyle, GUILayout.Width(150), GUILayout.ExpandHeight(true));

                                GUILayout.FlexibleSpace();

                                if (GUILayout.Button("Translate", GUILayout.ExpandWidth(true), GUILayout.MaxWidth(150), GUILayout.ExpandHeight(true)))
                                {
                                    CustomEditorWindow_Localizator_EditLang.OpenWindow(value.Key.ToString());
                                }
                                if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.MaxWidth(150), GUILayout.ExpandHeight(true)))
                                {
                                    CustomEditorWindow_Localizator_EditLang.Export(value.Key.ToString());
                                }
                                if (GUILayout.Button("Update", GUILayout.ExpandWidth(true), GUILayout.MaxWidth(150), GUILayout.ExpandHeight(true)))
                                {
                                    CustomEditorWindow_Localizator_EditLang.Update(value.Key.ToString());
                                }
                                if (GUILayout.Button("Backup", GUILayout.ExpandWidth(true), GUILayout.MaxWidth(150), GUILayout.ExpandHeight(true)))
                                {
                                    CustomEditorWindow_Localizator_EditLang.Backup(value.Key.ToString());
                                }
                                GUI.color = value.Key.Equals(DefaultLanguage) ? Color.gray : Color.red;
                                if (GUILayout.Button("Delete", GUILayout.ExpandWidth(true), GUILayout.MaxWidth(150), GUILayout.ExpandHeight(true)) && !value.Key.Equals(DefaultLanguage))
                                {
                                    languageToRemove.Add(value.Key);
                                }
                                GUI.color = _defaultColor;
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();

                for (int i = 0; i < languageToRemove.Count; ++i)
                {
                    DeleteLocalizationFile(languageToRemove[i]);
                }
            }
        }