private void OnEnable() { // Note that Enable is not called when opened as Preference item (via SettingsProvider api) // We implement it for old versions of Unity that just use a traditional EditorWindow for settings this.activePreferences = MulliganUserPreferences.LoadOrCreatePreferences(); this.languageRetriever = new LanguageRetriever(); }
private static void DrawUpdateLanguagesButton(LanguageRetriever retriever) { EditorGUI.BeginDisabledGroup(!retriever.IsDoneUpdating); var useDebugPresets = Event.current.shift; var buttonText = LocalizationManager.Instance.GetTranslation("updateLanguages"); if (useDebugPresets) { buttonText = string.Concat(buttonText, "*"); } if (GUILayout.Button(buttonText)) { retriever.UpdateLanguages(useDebugPresets); } EditorGUI.EndDisabledGroup(); }
public static SettingsProvider CreateMyCustomSettingsProvider() { // First parameter is the path in the Settings window. // Second parameter is the scope of this setting: it only appears in the Project Settings window. var provider = new SettingsProvider(Path, SettingsScope.User) { // By default the last token of the path is used as display name if no label is provided. label = LocalizationManager.Instance.GetTranslation("preferencesMenuItem"), activateHandler = (searchContext, rootElement) => { ActivePreferences = MulliganUserPreferences.LoadOrCreatePreferences(); LanguageRetriever = new LanguageRetriever(); }, // Create the SettingsProvider and initialize its drawing (IMGUI) function in place: guiHandler = DrawPreferences, // Populate the search keywords to enable smart search filtering and label highlighting: keywords = new HashSet <string>(new[] { "Diff", "Color" }) }; return(provider); }
/// <summary> /// Draw the Preferences using Unity GUI framework. /// </summary> /// <param name="preferences">Preferences to draw and update</param> public static void DrawPreferences(MulliganUserPreferences preferences, LanguageRetriever languageRetriever) { // I override LabelWidth (and MaxWidth) just to look more like Unity's native preferences EditorGUIUtility.labelWidth = LabelWidth; var prefsChanged = false; EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(MaxWidth)); var newLanguage = DrawLanguageDropdown(LocalizationManager.Instance.CurrentLanguage); if (newLanguage != LocalizationManager.Instance.CurrentLanguage) { preferences.CurrentLanguageKey = newLanguage.Key; LocalizationManager.Instance.ChangeLanguage(newLanguage.Key); } DrawUpdateLanguagesButton(languageRetriever); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); GUILayout.Label(LocalizationManager.Instance.GetTranslation("preferencesDiffLabel"), EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); preferences.InsertionTextColor = EditorGUILayout.ColorField( LocalizationManager.Instance.GetTranslation("preferencesInsertionText"), preferences.InsertionTextColor, GUILayout.MaxWidth(MaxWidth)); preferences.InsertionBackgroundColor = EditorGUILayout.ColorField( LocalizationManager.Instance.GetTranslation("preferencesInsertionBackground"), preferences.InsertionBackgroundColor, GUILayout.MaxWidth(MaxWidth)); EditorGUILayout.Space(); DrawSampleDiffLabel(true, preferences); EditorGUILayout.Space(); EditorGUILayout.Space(); preferences.DeletionTextColor = EditorGUILayout.ColorField( LocalizationManager.Instance.GetTranslation("preferencesDeletionText"), preferences.DeletionTextColor, GUILayout.MaxWidth(MaxWidth)); preferences.DeletionBackgroundColor = EditorGUILayout.ColorField( LocalizationManager.Instance.GetTranslation("preferencesDeletionBackground"), preferences.DeletionBackgroundColor, GUILayout.MaxWidth(MaxWidth)); EditorGUILayout.Space(); DrawSampleDiffLabel(false, preferences); if (EditorGUI.EndChangeCheck()) { prefsChanged = true; } if (GUILayout.Button(LocalizationManager.Instance.GetTranslation("preferencesReset"), GUILayout.Width(150))) { preferences.ResetColorsToDefault(EditorGUIUtility.isProSkin); prefsChanged = true; } if (prefsChanged) { preferences.SaveToEditorPrefs(); } }