public static bool ShowGUI(Rect position, SerializedProperty property, GUIContent label, LanguageSource source) { EditorGUI.BeginChangeCheck(); var Terms = (source == null ? LocalizationManager.GetTermsList() : source.GetTermsList()); Terms.Sort(System.StringComparer.OrdinalIgnoreCase); Terms.Add(""); Terms.Add("<inferred from text>"); Terms.Add("<none>"); var index = (property.stringValue == "-" || property.stringValue == "" ? Terms.Count - 1 : (property.stringValue == " " ? Terms.Count - 2 : Terms.IndexOf(property.stringValue))); var newIndex = EditorGUI.Popup(position, label.text, index, Terms.ToArray()); if (EditorGUI.EndChangeCheck()) { property.stringValue = (newIndex < 0 || newIndex == Terms.Count - 1) ? string.Empty : Terms[newIndex]; if (newIndex == Terms.Count - 1) { property.stringValue = "-"; } else if (newIndex < 0 || newIndex == Terms.Count - 2) { property.stringValue = string.Empty; } else { property.stringValue = Terms[newIndex]; } return(true); } return(false); }
public static bool ShowGUI(Rect position, SerializedProperty property, GUIContent label, LanguageSource source, string filter = "") { label = EditorGUI.BeginProperty(position, label, property); EditorGUI.BeginChangeCheck(); var Terms = (source == null ? LocalizationManager.GetTermsList() : source.GetTermsList()); if (string.IsNullOrEmpty(filter) == false) { Terms = Filter(Terms, filter); } Terms.Sort(System.StringComparer.OrdinalIgnoreCase); Terms.Add(""); Terms.Add("<inferred from text>"); Terms.Add("<none>"); var index = (property.stringValue == "-" || property.stringValue == "" ? Terms.Count - 1 : (property.stringValue == " " ? Terms.Count - 2 : Terms.IndexOf(property.stringValue))); var newIndex = EditorGUI.Popup(position, label, index, DisplayOptions(Terms)); if (EditorGUI.EndChangeCheck()) { property.stringValue = (newIndex < 0 || newIndex == Terms.Count - 1) ? string.Empty : Terms[newIndex]; if (newIndex == Terms.Count - 1) { property.stringValue = "-"; } else if (newIndex < 0 || newIndex == Terms.Count - 2) { property.stringValue = string.Empty; } else { property.stringValue = Terms[newIndex]; } EditorGUI.EndProperty(); return(true); } EditorGUI.EndProperty(); return(false); }
static void UpdateTermsCache(LanguageSource source, string filter, ref GUIContent[] terms_Contexts, ref int framesBeforeUpdating, ref string prevFilter) { framesBeforeUpdating--; if (terms_Contexts != null && framesBeforeUpdating > 0 && filter == prevFilter) { return; } framesBeforeUpdating = 60; prevFilter = filter; var Terms = (source == null ? LocalizationManager.GetTermsList() : source.GetTermsList()); if (string.IsNullOrEmpty(filter) == false) { Terms = Filter(Terms, filter); } Terms.Sort(System.StringComparer.OrdinalIgnoreCase); Terms.Add(""); Terms.Add("<inferred from text>"); Terms.Add("<none>"); terms_Contexts = DisplayOptions(Terms); }