public override void OnInspectorGUI() { var cultures = Cultures.GetCultures().ToList(); var cultureDisplayName = cultures.Where(c => c.Name == languageNameProperty.stringValue) .Select(c => c.DisplayName) .DefaultIfEmpty("Development") .FirstOrDefault(); EditorGUILayout.LabelField("Language", cultureDisplayName); EditorGUILayout.Space(); if (serializedObject.isEditingMultipleObjects) { EditorGUILayout.HelpBox($"Select a single {nameof(Localization).ToLowerInvariant()} to view its contents.", MessageType.None); } else { var target = this.target as Localization; DrawLocalizationContents(target); } if (serializedObject.hasModifiedProperties) { serializedObject.ApplyModifiedProperties(); } }
private void LoadTextLanguagesIntoDropdowns() { if (textLanguagesDropdown || textLanguagesTMPDropdown) { var textLanguageList = new List <string>(); if (ProjectSettings.TextProjectLanguages.Count > 0) { foreach (var language in ProjectSettings.TextProjectLanguages) { var culture = Cultures.GetCulture(language); textLanguageList.Add(culture.NativeName); } } else { // If no project settings have been defined, show all available cultures foreach (var culture in Cultures.GetCultures()) { textLanguageList.Add(culture.NativeName); } } PopulateLanguagesListToDropdown(textLanguageList, textLanguagesTMPDropdown, textLanguagesDropdown, ref textLanguageSelected, PreferencesSetting.TextLanguage); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // If this property is not a string, show an error label. (We // can't call EditorGUI.PropertyField, because that would cause // an infinite recursion - Unity would invoke this property // drawer again.) if (property.propertyType != SerializedPropertyType.String) { EditorGUI.HelpBox(position, $"{property.name} is not a string.", MessageType.Error); return; } // Display this property as a dropdown that lets you select a // language. var allCultures = Cultures.GetCultures().ToList(); var indices = Enumerable.Range(0, allCultures.Count()); var culturesToIndicies = allCultures.Zip(indices, (culture, index) => new { culture, index }).ToDictionary(pair => pair.culture.Name, pair => pair.index); var value = property.stringValue; int currentCultureIndex; if (culturesToIndicies.ContainsKey(value)) { currentCultureIndex = culturesToIndicies[value]; } else { // The property doesn't contain a valid culture name. Show // an 'empty' value, which will be replaced when the user // selects a valid value from the dropdown. currentCultureIndex = -1; } var allCultureDisplayNames = allCultures.Select(c => c.DisplayName).Select(n => new GUIContent(n)).ToArray(); using (var changeCheck = new EditorGUI.ChangeCheckScope()) { var selectedIndex = EditorGUI.Popup(position, label, currentCultureIndex, allCultureDisplayNames); if (changeCheck.changed) { property.stringValue = allCultures[selectedIndex].Name; } } }
public override void OnInspectorGUI() { var cultures = Cultures.GetCultures().ToList(); var cultureDisplayNames = cultures.Select(c => c.DisplayName); var selectedIndex = cultures.FindIndex(c => c.Name == languageNameProperty.stringValue); if (languageNameProperty.hasMultipleDifferentValues) { selectedIndex = -1; } using (new EditorGUI.DisabledScope(selectedIndex == -1)) // disable popup if multiple values present using (var change = new EditorGUI.ChangeCheckScope()) { selectedIndex = EditorGUILayout.Popup("Language", selectedIndex, cultureDisplayNames.ToArray()); if (change.changed) { languageNameProperty.stringValue = cultures[selectedIndex].Name; } } EditorGUILayout.PropertyField(assetSourceFolderProperty); EditorGUILayout.Space(); if (serializedObject.isEditingMultipleObjects) { EditorGUILayout.HelpBox($"Select a single {nameof(Localization).ToLowerInvariant()} to view its contents.", MessageType.None); } else { var target = this.target as Localization; var hasAssets = assetSourceFolderProperty.objectReferenceValue != null; DrawLocalizationContents(target, hasAssets); } if (serializedObject.hasModifiedProperties) { serializedObject.ApplyModifiedProperties(); } }
private void LoadAudioLanguagesIntoDropdowns() { if (audioLanguagesDropdown || audioLanguagesTMPDropdown) { var audioLanguagesList = new List <string>(); if (ProjectSettings.AudioProjectLanguages.Count == 0) { // If no project settings have been defined, show all available cultures foreach (var culture in Cultures.GetCultures()) { audioLanguagesList.Add(culture.Name); } } else { foreach (var language in ProjectSettings.AudioProjectLanguages) { audioLanguagesList.Add(language); } } PopulateLanguagesListToDropdown(audioLanguagesList, audioLanguagesTMPDropdown, audioLanguagesDropdown, ref audioLanguageSelected, PreferencesSetting.AudioLanguage); } }
private void ApplyChangedValueToPreferences(int value, TMP_Dropdown tmpDropdown, Dropdown dropdown, PreferencesSetting setting) { string language = default; if (dropdown) { language = Cultures.GetCultures().First(element => element.NativeName == dropdown.options[value].text).Name; } if (tmpDropdown) { language = Cultures.GetCultures().First(element => element.NativeName == tmpDropdown.options[value].text).Name; } switch (setting) { case PreferencesSetting.TextLanguage: TextLanguage = language; break; case PreferencesSetting.AudioLanguage: AudioLanguage = language; break; } }