private void OnAddLanguage(object data)
                {
                    SystemLanguage language = (SystemLanguage)data;

                    LocalisedTextMeshPro localisedUITextMesh = (LocalisedTextMeshPro)target;

                    Undo.RecordObject(localisedUITextMesh, "Added language override");

                    //Copy settings from text mesh
                    TextMeshProSettings settings = TextMeshProSettings.FromTextMesh(localisedUITextMesh.TextMesh);

                    LocalisedTextMeshPro.LanguageSettingsOverride languageSettingsOverride = new LocalisedTextMeshPro.LanguageSettingsOverride()
                    {
                        _language = language,
                        _settings = settings,
                    };

                    //If this is the first language settings also save current settings to default
                    if (localisedUITextMesh._languageSettingsOverrides == null || localisedUITextMesh._languageSettingsOverrides.Length == 0)
                    {
                        localisedUITextMesh._defaultSettings           = settings;
                        localisedUITextMesh._languageSettingsOverrides = new LocalisedTextMeshPro.LanguageSettingsOverride[] { languageSettingsOverride };
                    }
                    //Otherwise add new settings to overrides
                    else
                    {
                        ArrayUtils.Add(ref localisedUITextMesh._languageSettingsOverrides, languageSettingsOverride);
                    }

                    //Then switch to editing this new language
                    SwitchToEditingLanguage(language);
                }
Пример #2
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
                }