private bool IsEditingOverrideSettings()
                {
                    LocalisedTextMeshPro localisedUITextMesh = (LocalisedTextMeshPro)target;
                    SystemLanguage       language            = localisedUITextMesh._editingLanguage;

                    if (language == SystemLanguage.Unknown)
                    {
                        language = Localisation.GetCurrentLanguage();
                    }

                    if (localisedUITextMesh._languageSettingsOverrides != null)
                    {
                        for (int i = 0; i < localisedUITextMesh._languageSettingsOverrides.Length; i++)
                        {
                            if (localisedUITextMesh._languageSettingsOverrides[i]._language == language)
                            {
                                return(true);
                            }
                        }
                    }

                    if (localisedUITextMesh._editingLanguage != SystemLanguage.Unknown)
                    {
                        localisedUITextMesh._editingLanguage = SystemLanguage.Unknown;
                    }

                    return(false);
                }
示例#2
0
            public string GetLocalisedString(params LocalisationLocalVariable[] variables)
            {
                _cachedLanguage  = Localisation.GetCurrentLanguage();
                _cachedText      = Localisation.Get(_localisationKey, variables);
                _cachedVariables = Localisation.GetGlobalVariables(_cachedText);

                return(_cachedText);
            }
            public string GetLocalisedString()
            {
                if (_cachedLanguage != Localisation.GetCurrentLanguage())
                {
                    _cachedLanguage = Localisation.GetCurrentLanguage();
                    _cachedText     = Localisation.GetString(_localisationKey);
                }

                return(_cachedText);
            }
示例#4
0
            public string GetLocalisedString(params LocalisationLocalVariable[] variables)
            {
                if (variables.Length > 0 || _cachedLanguage != Localisation.GetCurrentLanguage() || Localisation.AreGlobalVariablesOutOfDate(_cachedVariables))
                {
                    _cachedLanguage  = Localisation.GetCurrentLanguage();
                    _cachedText      = Localisation.Get(_localisationKey, variables);
                    _cachedVariables = Localisation.GetGlobalVariables(_cachedText);
                }

                return(_cachedText);
            }
示例#5
0
                private void DuplicateSelected()
                {
                    if (!string.IsNullOrEmpty(_editorPrefs._selectedKey))
                    {
                        string newKey = _editorPrefs._selectedKey + " (Copy)";
                        Localisation.Set(newKey, Localisation.GetCurrentLanguage(), Localisation.GetRawString(_editorPrefs._selectedKey));
                        _keys = GetKeys();
                        SelectKey(newKey);

                        _needsRepaint = true;
                    }
                }
示例#6
0
                private void RenderBottomBar()
                {
                    EditorGUILayout.Separator();

                    EditorGUILayout.BeginHorizontal(GUILayout.Height(kBottomBarHeight));
                    {
                        if (GUILayout.Button("Add New", EditorStyles.toolbarButton, GUILayout.Width(_editorPrefs._keyWidth)))
                        {
                            if (!Localisation.Exists(_addNewKey) && !string.IsNullOrEmpty(_addNewKey))
                            {
                                Localisation.Set(_addNewKey, Localisation.GetCurrentLanguage(), string.Empty);
                                _keys = GetKeys();
                                SelectKey(_addNewKey);
                                _addNewKey = "";
                            }
                        }

                        string[] folders            = Localisation.GetStringFolders();
                        int      currentFolderIndex = 0;
                        string   keyWithoutFolder;
                        Localisation.GetFolderIndex(_addNewKey, out currentFolderIndex, out keyWithoutFolder);

                        EditorGUI.BeginChangeCheck();
                        int    newFolderIndex = EditorGUILayout.Popup(currentFolderIndex, folders);
                        string currentFolder  = newFolderIndex == 0 ? "" : folders[newFolderIndex];
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (newFolderIndex != 0)
                            {
                                _addNewKey = currentFolder + "/" + keyWithoutFolder;
                            }
                        }

                        EditorGUILayout.LabelField("/", GUILayout.Width(8));

                        if (newFolderIndex != 0)
                        {
                            keyWithoutFolder = EditorGUILayout.TextField(keyWithoutFolder);
                            _addNewKey       = currentFolder + "/" + keyWithoutFolder;
                        }
                        else
                        {
                            _addNewKey = EditorGUILayout.TextField(_addNewKey);
                        }

                        GUILayout.FlexibleSpace();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.Separator();
                }
示例#7
0
            public void RefreshText(SystemLanguage language = SystemLanguage.Unknown)
            {
                if (language == SystemLanguage.Unknown)
                {
                    language = Localisation.GetCurrentLanguage();
                }

                if (_cachedLanguage != language || Localisation.AreGlobalVariablesOutOfDate(_cachedGlobalVariables)
#if UNITY_EDITOR
                    || !Application.isPlaying
#endif
                    )
                {
                    UpdateText(language);
                }
            }
                private float GetItemHeight(string key)
                {
                    float keyHeight = _keyStyle.fontSize;

                    if (key == _editorPrefs._selectedKey)
                    {
                        keyHeight += kEditKeyBarHeight;
                    }

                    string textA       = Localisation.GetRawString(key, Localisation.GetCurrentLanguage());
                    float  textAHeight = _textStyle.CalcSize(new GUIContent(textA)).y;

                    string textB       = Localisation.GetRawString(key, _editorPrefs._secondLanguage);
                    float  textBHeight = _textStyle.CalcSize(new GUIContent(textB)).y;

                    return(Mathf.Max(keyHeight, textAHeight, textBHeight));
                }
示例#9
0
                private void RenderBottomBar()
                {
                    EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                    {
                        GUILayout.Button("Add New Key:", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false));

                        string[] folders = Localisation.GetStringFolders();
                        Localisation.GetFolderIndex(_addNewKey, out int currentFolderIndex, out string keyWithoutFolder);

                        EditorGUI.BeginChangeCheck();
                        int    newFolderIndex = EditorGUILayout.Popup(currentFolderIndex, folders, EditorStyles.toolbarDropDown);
                        string currentFolder  = newFolderIndex == 0 ? "" : folders[newFolderIndex];
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (newFolderIndex != 0)
                            {
                                _addNewKey = currentFolder + "/" + keyWithoutFolder;
                            }
                        }

                        EditorGUILayout.LabelField("/", GUILayout.Width(8));

                        if (newFolderIndex != 0)
                        {
                            keyWithoutFolder = EditorGUILayout.TextField(keyWithoutFolder, GUILayout.ExpandWidth(true));
                            _addNewKey       = currentFolder + "/" + keyWithoutFolder;
                        }
                        else
                        {
                            _addNewKey = EditorGUILayout.TextField(_addNewKey, GUILayout.ExpandWidth(true));
                        }

                        if (GUILayout.Button(" Ok ", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
                        {
                            if (!Localisation.Exists(_addNewKey) && !string.IsNullOrEmpty(_addNewKey))
                            {
                                Localisation.Set(_addNewKey, Localisation.GetCurrentLanguage(), string.Empty);
                                UpdateKeys();
                                SelectKey(_addNewKey);
                                _addNewKey = "";
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
示例#10
0
                private void DuplicateSelected()
                {
                    List <string> newKeys = new List <string>();

                    for (int i = 0; i < _editorPrefs._selectedKeys.Length; i++)
                    {
                        string newKey = _editorPrefs._selectedKeys[i] + " (Copy)";

                        //To do! Set text for all loaded languages?
                        Localisation.Set(newKey, Localisation.GetCurrentLanguage(), Localisation.GetRawString(_editorPrefs._selectedKeys[i], Localisation.GetCurrentLanguage()));

                        newKeys.Add(newKey);
                    }

                    UpdateKeys();
                    SelectKey(newKeys.ToArray());
                    _needsRepaint = true;
                }
示例#11
0
            public string GetLocalisedString()
            {
                if (_cachedLanguage != Localisation.GetCurrentLanguage() || Localisation.AreGlobalVariablesOutOfDate(_cachedVariables)
#if UNITY_EDITOR
                    || !Application.isPlaying
#endif
                    )
                {
                    if (_localVariables != null && _localVariables.Length > 0)
                    {
                        _cachedText = Localisation.Get(_localisationKey, _localVariables);
                    }
                    else
                    {
                        _cachedText = Localisation.Get(_localisationKey);
                    }

                    _cachedLanguage  = Localisation.GetCurrentLanguage();
                    _cachedVariables = Localisation.GetGlobalVariables(_cachedText);
                }

                return(_cachedText);
            }
示例#12
0
                private void RenderTable()
                {
                    Vector2 scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, false, false);

                    {
                        if (_scrollPosition != scrollPosition)
                        {
                            _scrollPosition = scrollPosition;
                            EditorGUI.FocusTextInControl(string.Empty);
                        }

                        //On layout, check what part of table is currently being viewed
                        if (Event.current.type == EventType.Layout)
                        {
                            _keys = GetKeys();
                            GetViewableRange(_scrollPosition.y, GetTableAreaHeight(), out _viewStartIndex, out _viewEndIndex, out _contentStart, out _contentHeight);
                        }

                        EditorGUILayout.BeginVertical(GUILayout.Height(_contentHeight));
                        {
                            GUILayout.Label(GUIContent.none, GUILayout.Height(_contentStart));

                            for (int i = _viewStartIndex; i < _viewEndIndex; i++)
                            {
                                bool selected = _keys[i] == _editorPrefs._selectedKey;

                                Color origBackgroundColor = GUI.backgroundColor;
                                GUI.backgroundColor = selected ? kSelectedTextLineBackgroundColor : i % 2 == 0 ? kTextLineBackgroundColorA : kTextLineBackgroundColorB;

                                EditorGUILayout.BeginHorizontal(EditorUtils.ColoredRoundedBoxStyle);
                                {
                                    GUI.backgroundColor = kKeyBackgroundColor;

                                    if (selected && _editingKeyName)
                                    {
                                        EditorGUI.BeginChangeCheck();
                                        GUI.SetNextControlName(kEditKeyId);
                                        string key = EditorGUILayout.DelayedTextField(_keys[i], _keyEditStyle, GUILayout.Width(_editorPrefs._keyWidth), GUILayout.ExpandHeight(true));
                                        if (EditorGUI.EndChangeCheck())
                                        {
                                            _editingKeyName = false;
                                            Localisation.ChangeKey(_keys[i], key);
                                        }

                                        if (!_wasEditingKeyName)
                                        {
                                            EditorGUI.FocusTextInControl(kEditKeyId);
                                        }

                                        _wasEditingKeyName = true;
                                    }
                                    else
                                    {
                                        if (GUILayout.Button(_keys[i], _keyStyle, GUILayout.Width(_editorPrefs._keyWidth), GUILayout.ExpandHeight(true)))
                                        {
                                            _editorPrefs._selectedKey = _keys[i];
                                            _editingKeyName           = false;
                                            EditorGUI.FocusTextInControl(string.Empty);
                                        }
                                    }

                                    GUI.backgroundColor = i % 2 == 0 ? kTextBackgroundColorA : kTextBackgroundColorB;
                                    EditorGUI.BeginChangeCheck();

                                    string text = Localisation.GetRawString(_keys[i]);
                                    text = EditorGUILayout.TextArea(text, _textStyle, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                                    if (EditorGUI.EndChangeCheck())
                                    {
                                        Localisation.Set(_keys[i], Localisation.GetCurrentLanguage(), text);
                                    }
                                }
                                EditorGUILayout.EndHorizontal();

                                if (selected)
                                {
                                    GUI.backgroundColor = kSelectedButtonsBackgroundColor;
                                    EditorGUILayout.BeginHorizontal(EditorUtils.ColoredRoundedBoxStyle);
                                    {
                                        GUI.backgroundColor = origBackgroundColor;

                                        if (GUILayout.Button("Edit Key", EditorStyles.toolbarButton))
                                        {
                                            _editingKeyName    = true;
                                            _wasEditingKeyName = false;
                                        }

                                        if (GUILayout.Button("Delete", EditorStyles.toolbarButton))
                                        {
                                            DeleteSelected();
                                        }

                                        if (GUILayout.Button("Duplicate", EditorStyles.toolbarButton))
                                        {
                                            DuplicateSelected();
                                        }

                                        GUILayout.FlexibleSpace();
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }

                                GUI.backgroundColor = origBackgroundColor;
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndScrollView();
                }
 public void OnAfterDeserialize()
 {
     _language = Localisation.GetCurrentLanguage();
     _text     = Localisation.GetString(_localisationKey);
 }
示例#14
0
                private string[] GetKeys()
                {
                    string[]      allKeys = Localisation.GetStringKeys();
                    List <string> keys    = new List <string>();

                    for (int i = 1; i < allKeys.Length; i++)
                    {
                        if (MatchsFilter(allKeys[i]) || MatchsFilter(Localisation.GetRawString(allKeys[i], Localisation.GetCurrentLanguage())))
                        {
                            keys.Add(allKeys[i]);
                        }
                    }

                    switch (_sortOrder)
                    {
                    case eKeySortOrder.Desc:
                        keys.Sort(StringComparer.InvariantCulture);
                        keys.Reverse();
                        break;

                    default:
                    case eKeySortOrder.Asc:
                        keys.Sort(StringComparer.InvariantCulture);
                        break;
                    }

                    return(keys.ToArray());
                }
示例#15
0
                private void RenderTitleBar()
                {
                    EditorGUILayout.BeginVertical(GUILayout.Height(kToolBarHeight));
                    {
                        //Title
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            string titleText = kWindowTitle + " - <b>Localisation.xml</b>";

                            if (Localisation.HasUnsavedChanges())
                            {
                                titleText += "<b>*</b>";
                            }

                            EditorGUILayout.LabelField(titleText, _titleStyle);
                        }
                        EditorGUILayout.EndHorizontal();

                        //Load save
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            if (GUILayout.Button("Save", EditorStyles.toolbarButton))
                            {
                                Localisation.SaveStrings();
                            }

                            if (GUILayout.Button("Reload", EditorStyles.toolbarButton))
                            {
                                Localisation.LoadStrings();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Scale", EditorStyles.toolbarButton);

                            int fontSize = EditorGUILayout.IntSlider(_editorPrefs._fontSize, 8, 16);

                            if (GUILayout.Button("Reset Scale", EditorStyles.toolbarButton))
                            {
                                fontSize = kDefaultFontSize;
                                EditorGUI.FocusTextInControl(string.Empty);
                            }

                            if (_editorPrefs._fontSize != fontSize)
                            {
                                _editorPrefs._fontSize = fontSize;
                                _keyStyle.fontSize     = _editorPrefs._fontSize;
                                _textStyle.fontSize    = _editorPrefs._fontSize;
                                SaveEditorPrefs();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Font", EditorStyles.toolbarButton);

                            Font currentFont = _editorPrefs._font.GetAsset();
                            Font font        = (Font)EditorGUILayout.ObjectField(currentFont, typeof(Font), false);

                            if (currentFont != font)
                            {
                                _editorPrefs._font = new EditorAssetRef <Font>(font);

                                if (font == null)
                                {
                                    _textStyle.font = _keyStyle.font;
                                }
                                else
                                {
                                    _textStyle.font = font;
                                }

                                SaveEditorPrefs();
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Filters
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            GUILayout.Button("Filter", EditorStyles.toolbarButton);

                            EditorGUI.BeginChangeCheck();
                            _filter = EditorGUILayout.TextField(_filter);
                            if (EditorGUI.EndChangeCheck())
                            {
                                _needsRepaint = true;
                            }

                            if (GUILayout.Button("Clear", EditorStyles.toolbarButton))
                            {
                                _filter = "";
                                EditorGUI.FocusTextInControl(string.Empty);
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Headers
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            //Key
                            if (GUILayout.Button("Key", EditorStyles.toolbarButton, GUILayout.Width(_editorPrefs._keyWidth - 11)))
                            {
                                _sortOrder = _sortOrder == eKeySortOrder.Desc ? eKeySortOrder.Asc : eKeySortOrder.Desc;
                            }

                            EditorGUILayout.Separator();

                            //Resizer
                            RenderResizer();

                            //Text
                            EditorGUI.BeginChangeCheck();
                            SystemLanguage language = (SystemLanguage)EditorGUILayout.EnumPopup(Localisation.GetCurrentLanguage(), EditorStyles.toolbarButton);
                            if (EditorGUI.EndChangeCheck())
                            {
                                Localisation.SetLanguage(language);
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
示例#16
0
 public void SetVariables(params LocalisationLocalVariable[] variables)
 {
     _text.SetVariables(variables);
     UpdateText(Localisation.GetCurrentLanguage());
 }
            public bool RenderObjectProperties(GUIContent label)
            {
                bool dataChanged = false;

                _editorFoldout = EditorGUILayout.Foldout(_editorFoldout, label);

                if (_editorFoldout)
                {
                    int origIndent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel++;

                    //Draw list of possible keys
                    int currentKey = 0;
                    {
                        string[] keys = Localisation.GetStringKeys();

                        for (int i = 0; i < keys.Length; i++)
                        {
                            if (keys[i] == _localisationKey)
                            {
                                currentKey = i;
                                break;
                            }
                        }

                        EditorGUI.BeginChangeCheck();
                        currentKey = EditorGUILayout.Popup("Localisation Key", currentKey, keys);

                        if (EditorGUI.EndChangeCheck())
                        {
                            if (currentKey == 0)
                            {
                                _localisationKey = null;
                                _language        = SystemLanguage.Unknown;
                                _text            = "";
                            }
                            else
                            {
                                _localisationKey = keys[currentKey];
                                _language        = Localisation.GetCurrentLanguage();
                                _text            = Localisation.GetString(_localisationKey);
                            }

                            dataChanged = true;
                        }
                    }

                    //Draw buttons for adding new key
                    if (currentKey == 0)
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            _localisationKey = EditorGUILayout.DelayedTextField("New Key", _localisationKey);

                            if (GUILayout.Button("Auto", GUILayout.Width(36)))
                            {
                                _localisationKey = GetAutoKey();
                            }

                            if (GUILayout.Button("Add", GUILayout.Width(32)) && !string.IsNullOrEmpty(_localisationKey))
                            {
                                //Add new string for new key
                                _language = Localisation.GetCurrentLanguage();
                                Localisation.UpdateString(_localisationKey, _language, _text);

                                string[] keys = Localisation.GetStringKeys();
                                for (int i = 0; i < keys.Length; i++)
                                {
                                    if (keys[i] == _localisationKey)
                                    {
                                        currentKey = i;
                                        break;
                                    }
                                }

                                dataChanged = true;
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    //Draw displayed text (can be edited to update localisation file)
                    {
                        EditorGUI.BeginChangeCheck();
                        _text = EditorGUILayout.TextArea(_text);
                        if (EditorGUI.EndChangeCheck() && currentKey != 0)
                        {
                            _language = Localisation.GetCurrentLanguage();
                            Localisation.UpdateString(_localisationKey, _language, _text);
                            dataChanged = true;
                        }
                    }

                    EditorGUI.indentLevel = origIndent;
                }

                return(dataChanged);
            }
示例#18
0
                private void RenderTitleBar()
                {
                    EditorGUILayout.BeginVertical();
                    {
                        //Load save
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            if (GUILayout.Button("Save", EditorStyles.toolbarButton))
                            {
                                Localisation.SaveStrings();
                            }

                            if (GUILayout.Button("Reload", EditorStyles.toolbarButton))
                            {
                                Localisation.ReloadStrings();
                                UpdateKeys();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Scale", EditorStyles.toolbarButton);

                            int fontSize = EditorGUILayout.IntSlider(_editorPrefs._tableFontSize, kMinFontSize, kMaxFontSize);

                            if (GUILayout.Button("Reset Scale", EditorStyles.toolbarButton))
                            {
                                fontSize = kDefaultFontSize;
                            }

                            if (_editorPrefs._tableFontSize != fontSize)
                            {
                                _editorPrefs._tableFontSize = fontSize;
                                _textStyle.fontSize         = _editorPrefs._tableFontSize;
                                _selectedTextStyle.fontSize = _editorPrefs._tableFontSize;
                                SaveEditorPrefs();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Font", EditorStyles.toolbarButton);

                            Font currentFont = _editorPrefs._font.GetAsset();
                            Font font        = (Font)EditorGUILayout.ObjectField(currentFont, typeof(Font), false);

                            if (currentFont != font)
                            {
                                _editorPrefs._font = new EditorAssetRef <Font>(font);

                                if (font == null)
                                {
                                    _textStyle.font = _keyStyle.font;
                                }
                                else
                                {
                                    _textStyle.font = font;
                                }

                                SaveEditorPrefs();
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Filters
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            GUILayout.Button("Filter", EditorStyles.toolbarButton);

                            EditorGUI.BeginChangeCheck();
                            _filter = EditorGUILayout.TextField(_filter, EditorStyles.toolbarSearchField);
                            if (EditorGUI.EndChangeCheck())
                            {
                                _needsRepaint = true;
                                UpdateKeys();
                            }

                            if (GUILayout.Button("Clear", EditorStyles.toolbarButton))
                            {
                                _filter = "";
                                UpdateKeys();
                                SelectKey(_editorPrefs._selectedKeys);
                            }

                            if (GUILayout.Button("Choose Localisation Folder", EditorStyles.toolbarButton))
                            {
                                string folder = LocalisationProjectSettings.Get()._localisationFolder;
                                folder = EditorUtility.OpenFolderPanel("Choose Localisation Folder", folder, "");

                                if (!string.IsNullOrEmpty(folder))
                                {
                                    LocalisationProjectSettings.Get()._localisationFolder = AssetUtils.GetAssetPath(folder);
                                    AssetDatabase.SaveAssets();
                                    Localisation.ReloadStrings(true);
                                    _needsRepaint = true;
                                }
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Headers
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            float keyWidth           = _editorPrefs._keyWidth - (kResizerWidth * 0.5f);
                            float firstLanguageWidth = _editorPrefs._firstLanguageWidth - kResizerWidth;
                            float secondLangWidth    = position.width - _editorPrefs._keyWidth - _editorPrefs._firstLanguageWidth;

                            keyWidth -= _scrollPosition.x;

                            //Key
                            if (GUILayout.Button("Key", EditorStyles.toolbarButton, GUILayout.Width(Mathf.Max(keyWidth, 0f))))
                            {
                                _sortOrder = _sortOrder == eKeySortOrder.Desc ? eKeySortOrder.Asc : eKeySortOrder.Desc;
                            }

                            //Keys Resizer
                            RenderResizer(ref _keysResizerRect);

                            //Current Language
                            string label = "Current Language (" + Localisation.GetCurrentLanguage().ToString() + ")";
                            if (GUILayout.Button(label, EditorStyles.toolbarButton, GUILayout.Width(firstLanguageWidth)))
                            {
                                GenericMenu menu = new GenericMenu();

                                foreach (SystemLanguage lang in Enum.GetValues(typeof(SystemLanguage)))
                                {
                                    menu.AddItem(new GUIContent(lang.ToString()), false, OnChangeCurrentLanguage, lang);
                                }

                                menu.ShowAsContext();
                            }

                            //Language Resizer
                            RenderResizer(ref _languageResizerRect);

                            //Second Language
                            EditorGUI.BeginChangeCheck();
                            SystemLanguage language = (SystemLanguage)EditorGUILayout.EnumPopup(_editorPrefs._secondLanguage, EditorStyles.toolbarPopup, GUILayout.Width(secondLangWidth));
                            if (EditorGUI.EndChangeCheck())
                            {
                                //Unload the strings if second language is not current
                                if (_editorPrefs._secondLanguage != Localisation.GetCurrentLanguage())
                                {
                                    Localisation.UnloadStrings(_editorPrefs._secondLanguage);
                                }

                                _editorPrefs._secondLanguage = language;

                                //If new language isn't current load strings
                                if (language != Localisation.GetCurrentLanguage())
                                {
                                    Localisation.LoadStrings(language);
                                }
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
                public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
                {
                    EditorGUI.BeginProperty(position, label, property);

                    SerializedProperty localisationkeyProperty = property.FindPropertyRelative("_localisationKey");
                    string             localisationkey         = localisationkeyProperty.stringValue;

                    float yPos = position.y;

                    Rect foldoutPosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight);

                    property.isExpanded = !EditorGUI.Foldout(foldoutPosition, !property.isExpanded, property.displayName + " (Localised String)");
                    yPos += EditorGUIUtility.singleLineHeight;

                    if (!property.isExpanded)
                    {
                        int origIndent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel++;

                        //Draw list of possible keys
                        int currentKey = 0;
                        {
                            string[] keys = Localisation.GetStringKeys();

                            for (int i = 0; i < keys.Length; i++)
                            {
                                if (keys[i] == localisationkey)
                                {
                                    currentKey = i;
                                    break;
                                }
                            }

                            Rect typePosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight);
                            yPos += EditorGUIUtility.singleLineHeight;

                            EditorGUI.BeginChangeCheck();
                            currentKey = EditorGUI.Popup(typePosition, "Localisation Key", currentKey, keys);

                            if (EditorGUI.EndChangeCheck())
                            {
                                if (currentKey == 0)
                                {
                                    localisationkey = UpdateNewLocalisedStringRef(property, null);
                                }
                                else
                                {
                                    localisationkey = UpdateNewLocalisedStringRef(property, keys[currentKey]);
                                }
                            }
                        }

                        //Draw button for adding new key
                        if (currentKey == 0)
                        {
                            string[] folders            = Localisation.GetStringFolders();
                            int      currentFolderIndex = 0;
                            string   keyWithoutFolder;
                            Localisation.GetFolderIndex(localisationkey, out currentFolderIndex, out keyWithoutFolder);


                            float keyTextWidth = position.width - EditorUtils.GetLabelWidth() - (folderNameWidth + buttonSpace + autoKeybuttonWidth + buttonSpace + addButtonWidth);
                            float buttonWidth  = autoKeySlashFakeWidth + keyTextWidth + buttonSpace + autoKeybuttonWidth + buttonSpace + addButtonWidth;


                            //Get list of current folder options
                            Rect folderText = new Rect(position.x, yPos, position.width - buttonWidth, EditorGUIUtility.singleLineHeight);

                            EditorGUI.BeginChangeCheck();
                            int    newFolderIndex = EditorGUI.Popup(folderText, "New Key", currentFolderIndex, folders);
                            string currentFolder  = newFolderIndex == 0 ? "" : folders[newFolderIndex];
                            if (EditorGUI.EndChangeCheck())
                            {
                                if (newFolderIndex != 0)
                                {
                                    localisationkey = UpdateNewLocalisedStringRef(property, currentFolder + "/" + keyWithoutFolder);
                                }
                            }

                            Rect addKeySlash = new Rect(position.x + (position.width - buttonWidth) - fudge, yPos, autoKeySlashWidth, EditorGUIUtility.singleLineHeight);
                            EditorGUI.LabelField(addKeySlash, new GUIContent("/"));

                            Rect addKeyText = new Rect(position.x + (position.width - buttonWidth) - fudge + autoKeySlashFakeWidth, yPos, keyTextWidth + fudge, EditorGUIUtility.singleLineHeight);
                            if (newFolderIndex != 0)
                            {
                                EditorGUI.BeginChangeCheck();
                                keyWithoutFolder = EditorGUI.TextField(addKeyText, keyWithoutFolder);

                                if (EditorGUI.EndChangeCheck())
                                {
                                    localisationkey = UpdateNewLocalisedStringRef(property, currentFolder + "/" + keyWithoutFolder);
                                }
                            }
                            else
                            {
                                EditorGUI.BeginChangeCheck();
                                localisationkey = EditorGUI.TextField(addKeyText, localisationkey);

                                if (EditorGUI.EndChangeCheck())
                                {
                                    UpdateNewLocalisedStringRef(property, localisationkey);
                                }
                            }

                            Rect autoKeyButton = new Rect(position.x + (position.width - buttonWidth) + autoKeySlashFakeWidth + buttonSpace + keyTextWidth, yPos, autoKeybuttonWidth, EditorGUIUtility.singleLineHeight);
                            Rect addKeyButton  = new Rect(position.x + (position.width - buttonWidth) + autoKeySlashFakeWidth + buttonSpace + keyTextWidth + buttonSpace + autoKeybuttonWidth, yPos, addButtonWidth, EditorGUIUtility.singleLineHeight);

                            yPos += addKeyButton.height;

                            if (GUI.Button(autoKeyButton, "Auto"))
                            {
                                LocalisedStringRef localisedStringRef = SerializedPropertyUtils.GetSerializedPropertyValue <LocalisedStringRef>(property);

                                Component component = property.serializedObject.targetObject as Component;
                                if (component != null)
                                {
                                    string parentName = component.gameObject.name;

                                    if (component.gameObject.scene.IsValid())
                                    {
                                        parentName = component.gameObject.scene.name + "_" + parentName;
                                    }

                                    localisedStringRef.SetAutoNameParentName(parentName);
                                }

                                localisationkey = UpdateNewLocalisedStringRef(property, localisedStringRef.GetAutoKey());
                            }

                            if (GUI.Button(addKeyButton, "Add") && !string.IsNullOrEmpty(localisationkey))
                            {
                                if (!Localisation.Exists(localisationkey))
                                {
                                    Localisation.Set(localisationkey, Localisation.GetCurrentLanguage(), string.Empty);
                                    LocalisationEditorWindow.EditString(localisationkey);
                                }
                            }
                        }

                        //Draw displayed text (can be edited to update localization file)
                        {
                            //Only display if have a valid key
                            if (!string.IsNullOrEmpty(localisationkey) && Localisation.Exists(localisationkey))
                            {
                                string text       = StringUtils.GetFirstLine(Localisation.GetRawString(localisationkey));
                                float  height     = EditorGUIUtility.singleLineHeight;
                                float  labelWidth = EditorUtils.GetLabelWidth();

                                Rect textPosition = new Rect(position.x + labelWidth + 2.0f, yPos, position.width - labelWidth - 2.0f - editbuttonWidth - buttonSpace, height);
                                EditorGUI.LabelField(textPosition, text, EditorUtils.ReadonlyTextBoxStyle);
                                Rect editTextPosition = new Rect(textPosition.x + textPosition.width + buttonSpace, yPos, editbuttonWidth, EditorGUIUtility.singleLineHeight);

                                if (GUI.Button(editTextPosition, "Edit"))
                                {
                                    LocalisationEditorWindow.EditString(localisationkey);
                                }

                                yPos += height;
                            }
                        }

                        EditorGUI.indentLevel = origIndent;
                    }

                    EditorGUI.EndProperty();
                }
                public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
                {
                    EditorGUI.BeginProperty(position, label, property);

                    SerializedProperty localisationkeyProperty = property.FindPropertyRelative("_localisationKey");

                    float yPos = position.y;

                    Rect foldoutPosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight);

                    property.isExpanded = EditorGUI.Foldout(foldoutPosition, property.isExpanded, property.displayName + " (Localised String)");
                    yPos += EditorGUIUtility.singleLineHeight;

                    if (property.isExpanded)
                    {
                        int origIndent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel++;

                        //Draw list of possible keys
                        int currentKey = 0;
                        {
                            string[] keys = Localisation.GetStringKeys();

                            for (int i = 0; i < keys.Length; i++)
                            {
                                if (keys[i] == localisationkeyProperty.stringValue)
                                {
                                    currentKey = i;
                                    break;
                                }
                            }

                            Rect typePosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight);
                            yPos += EditorGUIUtility.singleLineHeight;

                            EditorGUI.BeginChangeCheck();
                            currentKey = EditorGUI.Popup(typePosition, "Localisation Key", currentKey, keys);

                            if (EditorGUI.EndChangeCheck())
                            {
                                if (currentKey == 0)
                                {
                                    localisationkeyProperty.stringValue = null;
                                }
                                else
                                {
                                    localisationkeyProperty.stringValue = keys[currentKey];
                                }
                            }
                        }

                        //Draw button for adding new key
                        //show drop downs for where to put the key - enum list of all current folders + empty.
                        //select one to preapend
                        if (currentKey == 0)
                        {
                            float folderNameWidth       = 160.0f;
                            float autoKeySlashFakeWidth = 12.0f;
                            float autoKeySlashWidth     = 40.0f;
                            float autoKeybuttonWidth    = 42.0f;
                            float addButtonWidth        = 38.0f;
                            float buttonSpace           = 2.0f;
                            float fudge        = 13.0f;
                            float keyTextWidth = position.width - EditorUtils.GetLabelWidth() - (folderNameWidth + buttonSpace + autoKeybuttonWidth + buttonSpace + addButtonWidth);
                            float buttonWidth  = autoKeySlashFakeWidth + keyTextWidth + buttonSpace + autoKeybuttonWidth + buttonSpace + addButtonWidth;


                            //Get list of current folder options
                            Rect folderText = new Rect(position.x, yPos, position.width - buttonWidth, EditorGUIUtility.singleLineHeight);

                            string[] folders            = Localisation.GetStringFolders();
                            int      currentFolderIndex = 0;
                            string   currentFolder;
                            for (int i = 0; i < folders.Length; i++)
                            {
                                //To do - if the first bit of our folder exists then thats the current folder eg Roles/NewRole/Name - Roles/
                                if (folders[i] == Localisation.GetFolderName(localisationkeyProperty.stringValue))
                                {
                                    currentFolderIndex = i;
                                    break;
                                }
                            }
                            EditorGUI.BeginChangeCheck();
                            int newFolderIndex = EditorGUI.Popup(folderText, "New Key", currentFolderIndex, folders);
                            currentFolder = newFolderIndex == 0 ? "" : folders[newFolderIndex];
                            if (EditorGUI.EndChangeCheck())
                            {
                                if (newFolderIndex != 0)
                                {
                                    localisationkeyProperty.stringValue = currentFolder + "/" + Localisation.GetKeyWithoutFoldder(localisationkeyProperty.stringValue);
                                }
                                else if (currentFolderIndex != 0)
                                {
                                    localisationkeyProperty.stringValue = Localisation.GetKeyWithoutFoldder(localisationkeyProperty.stringValue);
                                }
                            }

                            Rect addKeySlash = new Rect(position.x + (position.width - buttonWidth) - fudge, yPos, autoKeySlashWidth, EditorGUIUtility.singleLineHeight);
                            EditorGUI.LabelField(addKeySlash, new GUIContent("/"));

                            Rect addKeyText = new Rect(position.x + (position.width - buttonWidth) - fudge + autoKeySlashFakeWidth, yPos, keyTextWidth + fudge, EditorGUIUtility.singleLineHeight);
                            if (newFolderIndex != 0)
                            {
                                string newAddKey = EditorGUI.TextField(addKeyText, Localisation.GetKeyWithoutFoldder(localisationkeyProperty.stringValue));
                                localisationkeyProperty.stringValue = currentFolder + "/" + newAddKey;
                            }
                            else
                            {
                                string newAddKey = EditorGUI.TextField(addKeyText, localisationkeyProperty.stringValue);
                                localisationkeyProperty.stringValue = newAddKey;
                            }

                            Rect autoKeyButton = new Rect(position.x + (position.width - buttonWidth) + autoKeySlashFakeWidth + buttonSpace + keyTextWidth, yPos, autoKeybuttonWidth, EditorGUIUtility.singleLineHeight);
                            Rect addKeyButton  = new Rect(position.x + (position.width - buttonWidth) + autoKeySlashFakeWidth + buttonSpace + keyTextWidth + buttonSpace + autoKeybuttonWidth, yPos, addButtonWidth, EditorGUIUtility.singleLineHeight);

                            yPos += addKeyButton.height;

                            if (GUI.Button(autoKeyButton, "Auto"))
                            {
                                LocalisedStringRef localisedStringRef = (LocalisedStringRef)EditorUtils.GetTargetObjectOfProperty(property);

                                Component component = property.serializedObject.targetObject as Component;
                                if (component != null)
                                {
                                    string parentName = component.gameObject.name;

                                    if (component.gameObject.scene.IsValid())
                                    {
                                        parentName = component.gameObject.scene.name + "_" + parentName;
                                    }

                                    localisedStringRef.SetAutoNameParentName(parentName);
                                }

                                localisationkeyProperty.stringValue = localisedStringRef.GetAutoKey();
                            }

                            if (GUI.Button(addKeyButton, "Add") && !string.IsNullOrEmpty(localisationkeyProperty.stringValue))
                            {
                                if (!Localisation.IsKeyInTable(localisationkeyProperty.stringValue))
                                {
                                    Localisation.UpdateString(localisationkeyProperty.stringValue, Localisation.GetCurrentLanguage(), string.Empty);
                                }
                            }
                        }

                        //Draw displayed text (can be edited to update localization file)
                        {
                            //Only display if have a valid key
                            if (!string.IsNullOrEmpty(localisationkeyProperty.stringValue) && Localisation.IsKeyInTable(localisationkeyProperty.stringValue))
                            {
                                string text       = Localisation.GetString(localisationkeyProperty.stringValue);
                                int    numLines   = StringUtils.GetNumberOfLines(text);
                                float  height     = (EditorGUIUtility.singleLineHeight - 2.0f) * numLines + 4.0f;
                                float  labelWidth = EditorUtils.GetLabelWidth();

                                Rect textPosition = new Rect(position.x + labelWidth, yPos, position.width - labelWidth, height);
                                yPos += height;

                                EditorGUI.BeginChangeCheck();
                                text = EditorGUI.TextArea(textPosition, text);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    Localisation.UpdateString(localisationkeyProperty.stringValue, Localisation.GetCurrentLanguage(), text);
                                }
                            }
                        }

                        EditorGUI.indentLevel = origIndent;
                    }

                    EditorGUI.EndProperty();
                }
                private void RenderTitleBar()
                {
                    EditorGUILayout.BeginVertical(GUILayout.Height(kToolBarHeight));
                    {
                        //Title
                        EditorGUILayout.BeginHorizontal(_toolbarStyle);
                        {
                            string titleText = kWindowTitle + " - <b>Localisation.xml</b>";

                            if (Localisation.HasUnsavedChanges())
                            {
                                titleText += "<b>*</b>";
                            }

                            EditorGUILayout.LabelField(titleText, _titleStyle);
                        }
                        EditorGUILayout.EndHorizontal();

                        //Load save
                        EditorGUILayout.BeginHorizontal(_toolbarStyle);
                        {
                            if (GUILayout.Button("Save", EditorStyles.toolbarButton))
                            {
                                Localisation.SaveStrings();
                            }

                            if (GUILayout.Button("Reload", EditorStyles.toolbarButton))
                            {
                                Localisation.ReloadStrings();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Scale", EditorStyles.toolbarButton);

                            int fontSize = EditorGUILayout.IntSlider(_editorPrefs._fontSize, 8, 16);

                            if (GUILayout.Button("Reset Scale", EditorStyles.toolbarButton))
                            {
                                fontSize = kDefaultFontSize;
                                EditorGUI.FocusTextInControl(string.Empty);
                            }

                            if (_editorPrefs._fontSize != fontSize)
                            {
                                _editorPrefs._fontSize = fontSize;
                                _keyStyle.fontSize     = _editorPrefs._fontSize;
                                _textStyle.fontSize    = _editorPrefs._fontSize;
                                SaveEditorPrefs();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Font", EditorStyles.toolbarButton);

                            Font currentFont = _editorPrefs._font.GetAsset();
                            Font font        = (Font)EditorGUILayout.ObjectField(currentFont, typeof(Font), false);

                            if (currentFont != font)
                            {
                                _editorPrefs._font = new EditorAssetRef <Font>(font);

                                if (font == null)
                                {
                                    _textStyle.font = _keyStyle.font;
                                }
                                else
                                {
                                    _textStyle.font = font;
                                }

                                SaveEditorPrefs();
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Filters
                        EditorGUILayout.BeginHorizontal(_toolbarStyle);
                        {
                            GUILayout.Button("Filter", EditorStyles.toolbarButton);

                            EditorGUI.BeginChangeCheck();
                            _filter = EditorGUILayout.TextField(_filter);
                            if (EditorGUI.EndChangeCheck())
                            {
                                _needsRepaint = true;
                            }

                            if (GUILayout.Button("Clear", EditorStyles.toolbarButton))
                            {
                                _filter = "";
                                EditorGUI.FocusTextInControl(string.Empty);
                            }

                            if (GUILayout.Button("Choose Localisation Folder", EditorStyles.toolbarButton))
                            {
                                string folder = LocalisationProjectSettings.Get()._localisationFolder;
                                folder = EditorUtility.OpenFolderPanel("Choose Localisation Folder", folder, "");
                                LocalisationProjectSettings.Get()._localisationFolder = AssetUtils.GetAssetPath(folder);
                                AssetDatabase.SaveAssets();
                                Localisation.ReloadStrings(true);
                                _needsRepaint = true;
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Headers
                        EditorGUILayout.BeginHorizontal();
                        {
                            //Key
                            EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(_editorPrefs._keyWidth - 3));
                            {
                                if (GUILayout.Button("Key", EditorStyles.toolbarButton, GUILayout.ExpandWidth(true)))
                                {
                                    _sortOrder = _sortOrder == eKeySortOrder.Desc ? eKeySortOrder.Asc : eKeySortOrder.Desc;
                                }
                            }
                            EditorGUILayout.EndHorizontal();

                            //Keys Resizer
                            RenderResizer(ref _keysResizerRect);

                            //Text
                            EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(_editorPrefs._firstLanguageWidth - 3));
                            {
                                //First Language
                                GUILayout.Button(Localisation.GetCurrentLanguage().ToString(), EditorStyles.toolbarButton, GUILayout.ExpandWidth(true));
                            }
                            EditorGUILayout.EndHorizontal();

                            //Language Resizer
                            RenderResizer(ref _languageResizerRect);

                            //Second Language
                            float secondLangWidth = position.width - _editorPrefs._keyWidth - _editorPrefs._firstLanguageWidth;

                            EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(secondLangWidth));
                            {
                                EditorGUI.BeginChangeCheck();
                                SystemLanguage language = (SystemLanguage)EditorGUILayout.EnumPopup(_editorPrefs._secondLanguage, EditorStyles.toolbarButton);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (_editorPrefs._secondLanguage != Localisation.GetCurrentLanguage())
                                    {
                                        Localisation.UnloadStrings(_editorPrefs._secondLanguage);
                                    }

                                    _editorPrefs._secondLanguage = language;
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
示例#22
0
                public void OnBeforeSerialize()
                {
#if UNITY_EDITOR
                    //If this text mesh has language override settings...
                    if (_textMesh != null && EditorUtility.IsDirty(_textMesh) && _languageSettingsOverrides != null && _languageSettingsOverrides.Length > 0)
                    {
                        //...work out which langauage we're currently editing
                        SystemLanguage language      = _editingLanguage != SystemLanguage.Unknown ? _editingLanguage : Localisation.GetCurrentLanguage();
                        bool           foundLanguage = false;

                        //check if we have an override for this language, if so save the current text mesh settings to that language
                        for (int i = 0; i < _languageSettingsOverrides.Length; i++)
                        {
                            if (_languageSettingsOverrides[i]._language == language)
                            {
                                _languageSettingsOverrides[i]._settings = TextMeshProSettings.FromTextMesh(_textMesh);
                                foundLanguage = true;
                                break;
                            }
                        }

                        //otherwise save them to default settings
                        if (!foundLanguage)
                        {
                            _defaultSettings = TextMeshProSettings.FromTextMesh(_textMesh);
                        }
                    }
#endif
                }
示例#23
0
                public static object PropertyField(object obj, GUIContent label, ref bool dataChanged, GUIStyle style, params GUILayoutOption[] options)
                {
                    LocalisedString localisedString = (LocalisedString)obj;

                    //Draw list of possible keys
                    int currentKeyIndex = 0;

                    {
                        string[] keys       = Localisation.GetStringKeys();
                        string   currentKey = localisedString.GetLocalisationKey();

                        for (int i = 0; i < keys.Length; i++)
                        {
                            if (keys[i] == currentKey)
                            {
                                currentKeyIndex = i;
                                break;
                            }
                        }

                        EditorGUI.BeginChangeCheck();
                        currentKeyIndex = EditorGUILayout.Popup("Localisation Key", currentKeyIndex, keys);

                        //If key has changed
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (currentKeyIndex == 0)
                            {
                                localisedString = new LocalisedString();
                            }
                            else
                            {
                                localisedString = keys[currentKeyIndex];
                            }

                            dataChanged = true;
                        }
                    }

                    //Draw actual localised text (can be edited to update localisation file)
                    {
                        string currentKey = localisedString.GetLocalisationKey();

                        //Only display if have a valid key
                        if (!string.IsNullOrEmpty(currentKey) && Localisation.Exists(currentKey))
                        {
                            EditorGUI.BeginChangeCheck();
                            string text;
                            if (style != null)
                            {
                                text = EditorGUILayout.TextArea(Localisation.GetRawString(currentKey, Localisation.GetCurrentLanguage()), style);
                            }
                            else
                            {
                                text = EditorGUILayout.TextArea(Localisation.GetRawString(currentKey, Localisation.GetCurrentLanguage()));
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                Localisation.Set(currentKey, Localisation.GetCurrentLanguage(), text);
                            }
                        }
                    }

                    return(localisedString);
                }
示例#24
0
                public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
                {
                    EditorGUI.BeginProperty(position, label, property);

                    bool hasChanges = false;

                    SerializedProperty localisationkeyProperty = property.FindPropertyRelative("_localisationKey");
                    string             localisationkey         = localisationkeyProperty.stringValue;

                    float yPos = position.y;

                    //Draw list of possible keys
                    int currentKey = 0;

                    {
                        string[] keys = Localisation.GetStringKeys();

                        for (int i = 0; i < keys.Length; i++)
                        {
                            if (keys[i] == localisationkey)
                            {
                                currentKey = i;
                                break;
                            }
                        }

                        Rect typePosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight);
                        yPos += EditorGUIUtility.singleLineHeight;

                        EditorUtils.SetBoldDefaultFont(localisationkeyProperty.prefabOverride);

                        EditorGUI.BeginChangeCheck();
                        currentKey = EditorGUI.Popup(typePosition, property.displayName + " (Localised String)", currentKey, keys);
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (currentKey == 0)
                            {
                                localisationkey = UpdateNewLocalisedStringRef(property, null);
                                hasChanges      = true;
                            }
                            else
                            {
                                localisationkey = UpdateNewLocalisedStringRef(property, keys[currentKey]);
                                hasChanges      = true;
                            }
                        }

                        EditorUtils.SetBoldDefaultFont(false);
                    }

                    //Draw text preview (can be edited to update localization file)
                    if (!string.IsNullOrEmpty(localisationkey) && Localisation.Exists(localisationkey) && !localisationkeyProperty.hasMultipleDifferentValues)
                    {
                        string text       = StringUtils.GetFirstLine(Localisation.GetRawString(localisationkey, Localisation.GetCurrentLanguage()));
                        float  height     = EditorGUIUtility.singleLineHeight;
                        float  labelWidth = EditorUtils.GetLabelWidth();

                        Rect textPosition = new Rect(position.x + labelWidth + 2.0f, yPos, position.width - labelWidth - 2.0f - editbuttonWidth - buttonSpace, height);
                        EditorGUI.LabelField(textPosition, text, EditorUtils.ReadOnlyTextBoxStyle);
                        Rect editTextPosition = new Rect(textPosition.x + textPosition.width + buttonSpace, yPos, editbuttonWidth, EditorGUIUtility.singleLineHeight);

                        if (GUI.Button(editTextPosition, "Edit"))
                        {
                            LocalisationEditorWindow.EditString(localisationkey);
                        }
                    }

                    EditorGUI.EndProperty();

                    if (hasChanges)
                    {
                        property.serializedObject.ApplyModifiedProperties();
                        property.serializedObject.Update();
                    }
                }
                public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
                {
                    EditorGUI.BeginProperty(position, label, property);

                    SerializedProperty localisationkeyProperty = property.FindPropertyRelative("_localisationKey");

                    SerializedProperty editorTextProperty = property.FindPropertyRelative("_editorText");
                    SerializedProperty editorFoldoutProp  = property.FindPropertyRelative("_editorFoldout");
                    SerializedProperty editorHeightProp   = property.FindPropertyRelative("_editorHeight");


                    Rect foldoutPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

                    editorFoldoutProp.boolValue = EditorGUI.Foldout(foldoutPosition, editorFoldoutProp.boolValue, property.displayName + " (Localised String)");
                    editorHeightProp.floatValue = EditorGUIUtility.singleLineHeight;

                    if (editorFoldoutProp.boolValue)
                    {
                        int origIndent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel++;

                        //Draw list of possible keys
                        int currentKey = 0;
                        {
                            string[] keys = Localisation.GetStringKeys();

                            for (int i = 0; i < keys.Length; i++)
                            {
                                if (keys[i] == localisationkeyProperty.stringValue)
                                {
                                    currentKey = i;
                                    break;
                                }
                            }

                            Rect typePosition = new Rect(position.x, position.y + editorHeightProp.floatValue, position.width, EditorGUIUtility.singleLineHeight);
                            EditorGUI.BeginChangeCheck();
                            currentKey = EditorGUI.Popup(typePosition, "Localisation Key", currentKey, keys);
                            editorHeightProp.floatValue += EditorGUIUtility.singleLineHeight;

                            if (EditorGUI.EndChangeCheck())
                            {
                                if (currentKey == 0)
                                {
                                    localisationkeyProperty.stringValue = null;
                                    editorTextProperty.stringValue      = "";
                                }
                                else
                                {
                                    localisationkeyProperty.stringValue = keys[currentKey];
                                    editorTextProperty.stringValue      = Localisation.GetString(localisationkeyProperty.stringValue);
                                }
                            }
                        }

                        //Draw button for adding new key
                        if (currentKey == 0)
                        {
                            float buttonWidth = 48.0f;

                            Rect addKeyText = new Rect(position.x, position.y + editorHeightProp.floatValue, position.width - buttonWidth, EditorGUIUtility.singleLineHeight);
                            localisationkeyProperty.stringValue = EditorGUI.DelayedTextField(addKeyText, "New Key", localisationkeyProperty.stringValue);

                            Rect addKeyButton = new Rect(position.x + (position.width - buttonWidth), position.y + editorHeightProp.floatValue, buttonWidth, EditorGUIUtility.singleLineHeight);
                            editorHeightProp.floatValue += EditorGUIUtility.singleLineHeight;

                            if (GUI.Button(addKeyButton, "Add") && !string.IsNullOrEmpty(localisationkeyProperty.stringValue))
                            {
                                //Add new string for new key
                                Localisation.UpdateString(localisationkeyProperty.stringValue, Localisation.GetCurrentLanguage(), editorTextProperty.stringValue);

                                string[] keys = Localisation.GetStringKeys();
                                for (int i = 0; i < keys.Length; i++)
                                {
                                    if (keys[i] == localisationkeyProperty.stringValue)
                                    {
                                        currentKey = i;
                                        break;
                                    }
                                }
                            }
                        }

                        //Draw displayed text (can be edited to update localisation file)
                        {
                            int   numLines = StringUtils.GetNumberOfLines(editorTextProperty.stringValue);
                            float height   = (EditorGUIUtility.singleLineHeight - 2.0f) * numLines + 4.0f;

                            Rect textPosition = new Rect(position.x, position.y + editorHeightProp.floatValue, position.width, height);
                            editorHeightProp.floatValue += height;

                            EditorGUI.BeginChangeCheck();
                            editorTextProperty.stringValue = EditorGUI.TextArea(textPosition, editorTextProperty.stringValue);
                            if (EditorGUI.EndChangeCheck() && currentKey != 0)
                            {
                                Localisation.UpdateString(localisationkeyProperty.stringValue, Localisation.GetCurrentLanguage(), editorTextProperty.stringValue);
                            }
                        }

                        EditorGUI.indentLevel = origIndent;
                    }

                    EditorGUI.EndProperty();
                }
示例#26
0
                private void RenderTable()
                {
                    _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, false, false);
                    {
                        float          defaultItemHeight = GetItemHeight();
                        SystemLanguage currentLanguage   = Localisation.GetCurrentLanguage();
                        float          secondLangWidth   = position.width - _editorPrefs._keyWidth - _editorPrefs._firstLanguageWidth;

                        //On layout, check what part of table is currently being viewed
                        if (Event.current.type == EventType.Layout || _keysDirty)
                        {
                            GetViewableRange(_scrollPosition.y, GetTableAreaHeight(), defaultItemHeight, out _viewStartIndex, out _viewEndIndex, out _contentStart, out _contentHeight);
                        }

                        EditorGUILayout.BeginVertical(GUILayout.Height(_contentHeight));
                        {
                            //Blank space until start of content
                            GUILayout.Label(GUIContent.none, GUILayout.Height(_contentStart));

                            //Then render viewable range
                            for (int i = _viewStartIndex; i < _viewEndIndex; i++)
                            {
                                bool selected = IsSelected(_keys[i]);

                                Color origBackgroundColor = GUI.backgroundColor;
                                Color origContentColor    = GUI.contentColor;

                                //Work out item height
                                float itemHeight;
                                {
                                    if (selected)
                                    {
                                        //Work out highest text size
                                        string textA       = Localisation.GetRawString(_keys[i], Localisation.GetCurrentLanguage());
                                        float  textAHeight = _selectedTextStyle.CalcHeight(new GUIContent(textA), _editorPrefs._firstLanguageWidth);

                                        string textB       = Localisation.GetRawString(_keys[i], _editorPrefs._secondLanguage);
                                        float  textBHeight = _selectedTextStyle.CalcHeight(new GUIContent(textB), secondLangWidth);

                                        float textHeight = Mathf.Max(textAHeight, textBHeight);

                                        itemHeight = Mathf.Max(defaultItemHeight, textHeight);
                                    }
                                    else
                                    {
                                        itemHeight = defaultItemHeight;
                                    }
                                }

                                //Render item
                                GUI.backgroundColor = selected ? kSelectedTextLineBackgroundColor : i % 2 == 0 ? kTextLineBackgroundColorA : kTextLineBackgroundColorB;
                                EditorGUILayout.BeginHorizontal(_tableStyle, GUILayout.Height(itemHeight));
                                {
                                    GUI.backgroundColor = origBackgroundColor;
                                    GUI.contentColor    = selected ? kSelectedTextColor : Color.white;

                                    //Render Key
                                    EditorGUILayout.BeginVertical();
                                    {
                                        if (_editingKeyName == _keys[i])
                                        {
                                            EditorGUI.BeginChangeCheck();
                                            string key = EditorGUILayout.DelayedTextField(_keys[i], _editKeyStyle, GUILayout.Width(_editorPrefs._keyWidth), GUILayout.Height(itemHeight));
                                            if (EditorGUI.EndChangeCheck())
                                            {
                                                _editingKeyName = null;
                                                Localisation.ChangeKey(_keys[i], key);
                                                UpdateKeys();
                                            }
                                        }
                                        else
                                        {
                                            if (GUILayout.Button(_keys[i], selected ? _selectedKeyStyle : _keyStyle, GUILayout.Width(_editorPrefs._keyWidth), GUILayout.Height(itemHeight)))
                                            {
                                                OnClickItem(i, SystemLanguage.Unknown);
                                            }
                                        }
                                    }
                                    EditorGUILayout.EndVertical();

                                    //Render Text
                                    {
                                        GUI.backgroundColor = i % 2 == 0 ? kTextBackgroundColorA : kTextBackgroundColorB;

                                        //Render First Language
                                        string text = Localisation.GetRawString(_keys[i], currentLanguage);

                                        if (GUILayout.Button(selected ? text : StringUtils.GetFirstLine(text), selected ? _selectedTextStyle : _textStyle, GUILayout.Width(_editorPrefs._firstLanguageWidth), GUILayout.Height(itemHeight)))
                                        {
                                            OnClickItem(i, currentLanguage);
                                        }

                                        //Render Second Language
                                        EditorGUILayout.BeginVertical(GUILayout.Width(secondLangWidth));
                                        {
                                            string stext = Localisation.GetRawString(_keys[i], _editorPrefs._secondLanguage);

                                            if (GUILayout.Button(selected ? stext : StringUtils.GetFirstLine(stext), selected ? _selectedTextStyle : _textStyle, GUILayout.Width(secondLangWidth), GUILayout.Height(itemHeight)))
                                            {
                                                OnClickItem(i, _editorPrefs._secondLanguage);
                                            }
                                        }
                                        EditorGUILayout.EndVertical();
                                    }
                                }
                                EditorGUILayout.EndHorizontal();

                                GUI.backgroundColor = origBackgroundColor;
                                GUI.contentColor    = origContentColor;
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndScrollView();
                }
示例#27
0
 public void UpdateVariables(params KeyValuePair <string, string>[] variables)
 {
     _cachedLanguage = Localisation.GetCurrentLanguage();
     _cachedText     = Localisation.GetString(_localisationKey, variables);
 }
示例#28
0
 public string GetLocalisedString()
 {
     return(GetLocalisedString(Localisation.GetCurrentLanguage()));
 }
示例#29
0
				public static object PropertyField(object obj, GUIContent label, ref bool dataChanged, GUIStyle style, params GUILayoutOption[] options)
				{
					LocalisedStringRef localisedString = (LocalisedStringRef)obj;
					
					bool editorCollapsed = !EditorGUILayout.Foldout(!localisedString._editorCollapsed, label);

					if (editorCollapsed != localisedString._editorCollapsed)
					{
						localisedString._editorCollapsed = editorCollapsed;
						dataChanged = true;
					}

					if (!editorCollapsed)
					{
						int origIndent = EditorGUI.indentLevel;
						EditorGUI.indentLevel++;
						
						//Draw list of possible keys
						int currentKeyIndex = 0;
						{
							string[] keys = Localisation.GetStringKeys();
							string currentKey = localisedString.GetLocalisationKey();

							for (int i = 0; i < keys.Length; i++)
							{
								if (keys[i] == currentKey)
								{
									currentKeyIndex = i;
									break;
								}
							}

							EditorGUI.BeginChangeCheck();
							currentKeyIndex = EditorGUILayout.Popup("Localisation Key", currentKeyIndex, keys);

							//If key has changed
							if (EditorGUI.EndChangeCheck())
							{
								if (currentKeyIndex == 0)
								{
									localisedString = new LocalisedStringRef();
								}
								else
								{
									localisedString = new LocalisedStringRef(keys[currentKeyIndex]);
								}

								dataChanged = true;
							}
						}

						//Draw buttons for adding new key
						if (currentKeyIndex == 0)
						{
							string[] folders = Localisation.GetStringFolders();
							int currentFolderIndex = 0;
							string keyWithoutFolder;
							Localisation.GetFolderIndex(localisedString.GetLocalisationKey(), out currentFolderIndex, out keyWithoutFolder);

							EditorGUILayout.BeginHorizontal();
							{
								EditorGUILayout.LabelField(new GUIContent("New Key"), GUILayout.Width(EditorUtils.GetLabelWidth()));

								string editorParentName = localisedString.GetAutoNameParentName();

								EditorGUI.BeginChangeCheck();
								int newFolderIndex = EditorGUILayout.Popup(currentFolderIndex, folders);
								string currentFolder = newFolderIndex == 0 ? "" : folders[newFolderIndex];
								if (EditorGUI.EndChangeCheck())
								{
									if (newFolderIndex != 0)
									{
										localisedString = new LocalisedStringRef(currentFolder + "/" + keyWithoutFolder);
										localisedString.SetAutoNameParentName(editorParentName);
										dataChanged = true;
									}
								}

								EditorGUILayout.LabelField(new GUIContent("/"), GUILayout.Width(44));

								EditorGUI.BeginChangeCheck();
								keyWithoutFolder = EditorGUILayout.TextField(keyWithoutFolder);
								if (EditorGUI.EndChangeCheck())
								{
									localisedString = new LocalisedStringRef(currentFolder + "/" + keyWithoutFolder);
									localisedString.SetAutoNameParentName(editorParentName);
									dataChanged = true;
								}							

								if (GUILayout.Button("Auto", GUILayout.Width(36)))
								{
									string newKey = localisedString.GetAutoKey();
									localisedString = new LocalisedStringRef(newKey);
									localisedString.SetAutoNameParentName(editorParentName);
									dataChanged = true;
								}

								if (GUILayout.Button("Add", GUILayout.Width(32)) && !string.IsNullOrEmpty(localisedString.GetLocalisationKey()))
								{
									if (!Localisation.IsKeyInTable(localisedString.GetLocalisationKey()))
									{
										Localisation.UpdateString(localisedString.GetLocalisationKey(), Localisation.GetCurrentLanguage(), string.Empty);
										LocalisationEditorWindow.EditString(localisedString.GetLocalisationKey());
									}
									dataChanged = true;
								}
							}
							EditorGUILayout.EndHorizontal();
						}

						//Draw actual localised text (can be edited to update localisation file)
						{
							string currentKey = localisedString.GetLocalisationKey();

							//Only display if have a valid key
							if (!string.IsNullOrEmpty(currentKey) && Localisation.IsKeyInTable(currentKey))
							{
								EditorGUI.BeginChangeCheck();
								string text;
								if (style != null)
									text = EditorGUILayout.TextArea(Localisation.GetRawString(currentKey), style);
								else
									text = EditorGUILayout.TextArea(Localisation.GetRawString(currentKey));
								if (EditorGUI.EndChangeCheck())
								{
									Localisation.UpdateString(currentKey, Localisation.GetCurrentLanguage(), text);
								}
							}
						}

						EditorGUI.indentLevel = origIndent;
					}

					return localisedString;
				}
示例#30
0
 private void SetTextMeshSettingsForLanguage()
 {
     SetTextMeshSettingsForLanguage(Localisation.GetCurrentLanguage());
 }