Beispiel #1
0
        public override void OnInspectorGUI()
        {
            if (_rootLines.Length == 0)
            {
                EditorGUILayout.LabelField("No Labels set in the label file", EditorStyles.boldLabel);
                if (GUILayout.Button("Open Localization Editor Window"))
                {
                    CustomEditorWindow_Localizator.OpenWindow();
                }
            }
            else
            {
                string value = EditorGUILayout.TextField("Current Fragment :", _target._fragmentInternal);
                if (!_target._fragmentInternal.Equals(value))
                {
                    _target._fragmentInternal = value;

                    if (Application.isPlaying)
                    {
                        _target.OnChangeLanguage();
                    }
                    else
                    {
                        //_target.GetComponent<Text>().text = "<" + _target.Fragment + ">";
                        _target.gameObject.SetActive(false);
                        _target.gameObject.SetActive(true);
                    }
                }
            }
        }
Beispiel #2
0
        public static void OpenWindow()
        {
            CustomEditorWindow_Localizator window = EditorWindow.GetWindow <CustomEditorWindow_Localizator>("Localization Editor Window");

            window.minSize = new Vector2(640, 640);
            window.Show();
        }
        public override void OnInspectorGUI()
        {
            SystemLanguage targetLanguage = LanguageManager.Instance.CurrentLanguage;

            if (Application.isPlaying)
            {
                targetLanguage = (SystemLanguage)EditorGUILayout.EnumPopup("Current Language", targetLanguage);
                LanguageManager.Instance.CurrentLanguage = (SystemLanguage)Enum.Parse(typeof(SystemLanguage), targetLanguage.ToString());
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Default Language", EditorStyles.boldLabel);
                    EditorGUILayout.LabelField(LanguageManager.Instance.CurrentLanguage.ToString(), EditorStyles.boldLabel);
                }
                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(30);
            GUILayout.Label("Tools", EditorStyles.boldLabel);
            if (GUILayout.Button("Open Localization Editor Window"))
            {
                CustomEditorWindow_Localizator.OpenWindow();
            }
            if (GUILayout.Button("Debug languages localized"))
            {
                BinaryFormatter bf   = new BinaryFormatter();
                FileStream      file = File.Open(Localizator.Path.DatabaseFilePath, FileMode.Open);
                Dictionary <SystemLanguage, string> dic = (Dictionary <SystemLanguage, string>)bf.Deserialize(file);
                file.Close();

                string output = "Localized Languages : \n";
                foreach (KeyValuePair <SystemLanguage, string> value in dic)
                {
                    output += value.Key.ToString() + ", ";
                }
                output = output.Trim(' ').Trim(',');
                Debug.Log(output);
            }
        }
        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;

            EditorGUILayout.BeginVertical();
            {
                GUILayout.Label("Language " + CurrentLang, centeredMediumStyle);

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.BeginVertical("box", GUILayout.Width(position.width * 0.9f - 20), GUILayout.ExpandHeight(true));
                    {
                        GUILayout.Label("Traductions", centeredMediumStyle);
                        _scrollPositionLanguages = EditorGUILayout.BeginScrollView(_scrollPositionLanguages);
                        {
                            if (CurrentLang == null)
                            {
                                GUILayout.Label("No Language Selected", centeredMediumStyle);
                            }
                            else if (_rootLines.Count > 0)
                            {
                                for (int i = 0; i < _rootLines.Count; ++i)
                                {
                                    GUILayout.Space(5);
                                    EditorGUILayout.BeginHorizontal();
                                    {
                                        EditorGUILayout.LabelField(_rootLines[i], EditorStyles.label, GUILayout.ExpandWidth(false));

                                        string testFrag;
                                        if (!_languageLines.TryGetValue(_rootLines[i], out testFrag))
                                        {
                                            _languageLines.Add(_rootLines[i], "");
                                        }
                                        _languageLines[_rootLines[i]] = EditorGUILayout.TextField(_languageLines[_rootLines[i]], GUILayout.ExpandWidth(true));
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                                GUILayout.Space(10);
                            }
                            else
                            {
                                GUILayout.Label("No root label found", centeredMediumStyle);
                            }
                        }
                        EditorGUILayout.EndScrollView();
                    }
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginVertical("box", GUILayout.Width(position.width * 0.1f), GUILayout.ExpandHeight(true), GUILayout.MinWidth(100));
                    {
                        GUILayout.Label("Options", centeredMediumStyle);
                        if (GUILayout.Button("Export"))
                        {
                            Export(CurrentLang);
                        }
                        if (GUILayout.Button("Update"))
                        {
                            Update(CurrentLang);
                            LoadFiles();
                        }
                        if (GUILayout.Button("Backup"))
                        {
                            Backup(CurrentLang);
                        }
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();

                if (CurrentLang != null)
                {
                    GUI.color = Color.green;
                    if (GUILayout.Button("Save File", titleStyle))
                    {
                        CustomEditorWindow_Localizator.SaveLocalizationFile(CurrentLang, _languageLines);
                        LoadFiles();
                        CustomEditorWindow_Localizator.SaveWorkspace();
                    }
                    GUI.color = _defaultColor;
                }
            }
            EditorGUILayout.EndVertical();
        }
        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;

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

            EditorGUILayout.BeginVertical();
            {
                GUILayout.Label("Edit Root ");

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.BeginVertical("box", GUILayout.Width(position.width * 0.5f - 5), GUILayout.ExpandHeight(true));
                    {
                        GUILayout.Label("Root Labels", centeredMediumStyle);
                        _scrollPositionRootLabels = EditorGUILayout.BeginScrollView(_scrollPositionRootLabels, "box");
                        {
                            if (_rootLines.Count > 0)
                            {
                                for (int i = 0; i < _rootLines.Count; ++i)
                                {
                                    GUILayout.Space(10);
                                    EditorGUILayout.BeginHorizontal();
                                    {
                                        EditorGUILayout.LabelField(i.ToString(), EditorStyles.boldLabel, GUILayout.Width(50));
                                        _rootLines[i] = EditorGUILayout.TextField(_rootLines[i], GUILayout.ExpandWidth(true));
                                        GUI.color     = Color.red;
                                        if (GUILayout.Button("-", GUILayout.Width(50)))
                                        {
                                            labelsToRemove.Add(_rootLines[i]);
                                        }
                                        GUI.color = _defaultColor;
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                                GUILayout.Space(10);
                            }
                            else
                            {
                                GUILayout.Label("No root label found", centeredMediumStyle);
                            }
                        }
                        EditorGUILayout.EndScrollView();
                        if (GUILayout.Button("Add Root Label"))
                        {
                            _rootLines.Add("");
                        }
                    }
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginVertical("box", GUILayout.Width(position.width * 0.5f - 5), GUILayout.ExpandHeight(true));
                    {
                        GUILayout.Label("Options", centeredMediumStyle);
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();

                for (int i = 0; i < labelsToRemove.Count; ++i)
                {
                    _rootLines.Remove(labelsToRemove[i]);
                }

                GUI.color = Color.green;
                if (GUILayout.Button("Save File", titleStyle))
                {
                    CustomEditorWindow_Localizator.SaveRootFile(_rootLines);
                    LoadRootFile();
                    CustomEditorWindow_Localizator.SaveWorkspace();
                }
                GUI.color = _defaultColor;
            }
            EditorGUILayout.EndVertical();
        }