private static void DrawSearchResult() { GUtilities.EnsureArrayLength <bool>(ref expandedFlags, SearchResult.Count); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); if (string.IsNullOrEmpty(searchText)) { DrawSearchSuggestions(); } else { EditorGUI.indentLevel += 1; List <GHelpEntry> entries = GHelpDatabase.Instance.Entries; int resultCount = searchText.Equals("?") ? SearchResult.Count : Mathf.Min(10, SearchResult.Count); for (int i = 0; i < resultCount; ++i) { if (HitCount[i] == 0) { break; } int index = SearchResult[i]; GHelpEntry e = entries[index]; string label = string.Format("[{0}] {1}", e.Id.ToString("000"), e.Question); expandedFlags[i] = EditorGUILayout.Foldout(expandedFlags[i], label); if (expandedFlags[i]) { EditorGUI.indentLevel += 1; EditorGUILayout.LabelField(e.Answer, RichTextStyle); if (e.Links.Count > 0) { EditorGUILayout.LabelField("Link" + (e.Links.Count >= 2 ? "s" : "")); for (int j = 0; j < e.Links.Count; ++j) { if (LinkButton("- " + e.Links[j].DisplayText, e.Links[j].Link)) { if (e.Links[j].Link.StartsWith("~")) { searchText = e.Links[j].Link.Substring(1); EditorGUI.FocusTextInControl(null); OnSearchTextChanged(); Event.current.Use(); return; } else { Application.OpenURL(e.Links[j].Link); } } } } EditorGUI.indentLevel -= 1; EditorGUILayout.Space(); } } EditorGUI.indentLevel -= 1; } EditorGUILayout.EndScrollView(); }
private static void Search() { SearchResult.Clear(); HitCount.Clear(); if (searchText.Equals("?")) { for (int i = 0; i < GHelpDatabase.Instance.Entries.Count; ++i) { SearchResult.Add(i); HitCount.Add(1); expandedFlags = new bool[SearchResult.Count]; } return; } string text = searchText; if (text.Length < 3) { return; } string[] split = text.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); if (split.Length == 0) { return; } for (int i = 0; i < split.Length; ++i) { split[i] = split[i].ToLower(); } List <GHelpEntry> entries = GHelpDatabase.Instance.Entries; for (int i = 0; i < entries.Count; ++i) { float count = 0; GHelpEntry e = entries[i]; for (int j = 0; j < split.Length; ++j) { count += e.Question.ToLower().Contains(split[j]) ? 1 : 0; count += e.Answer.ToLower().Contains(split[j]) ? 0.5f : 0; } SearchResult.Add(i); HitCount.Add(count); } SearchResult.Sort((i0, i1) => - HitCount[i0].CompareTo(HitCount[i1])); HitCount.Sort((i0, i1) => - i0.CompareTo(i1)); expandedFlags = new bool[SearchResult.Count]; }
public override void OnInspectorGUI() { DrawStatistic(); string prefPrefix = "helpdb" + instance.GetInstanceID(); List <GHelpEntry> entries = instance.Entries; int startIndex = 0; if (onlyShowLastTenItems) { startIndex = Mathf.Max(0, entries.Count - 10); } for (int i = startIndex; i < entries.Count; ++i) { GHelpEntry e = entries[i]; e.Id = i + 1; string label = string.IsNullOrEmpty(e.Question) ? "[" + e.Id.ToString("000") + "]" : GEditorCommon.Ellipsis(string.Format("[{0}] {1}", e.Id.ToString("000"), e.Question), 100); bool expanded = GEditorCommon.Foldout(label, prefPrefix + i, false); if (expanded) { EditorGUI.indentLevel += 1; EditorGUILayout.LabelField("Id: " + e.Id.ToString("000")); EditorGUILayout.PrefixLabel("Category"); e.Category = (GCategory)EditorGUILayout.EnumPopup(e.Category); EditorGUILayout.PrefixLabel("Question"); e.Question = EditorGUILayout.TextField(e.Question); EditorGUILayout.PrefixLabel("Answer"); e.Answer = EditorGUILayout.TextArea(e.Answer, TextAreaStyle, GUILayout.Height(EditorGUIUtility.singleLineHeight * 5)); for (int j = 0; j < e.Links.Count; ++j) { EditorGUILayout.PrefixLabel("Link " + j + " (Text>URL)"); GHelpLink link = e.Links[j]; EditorGUILayout.BeginHorizontal(); link.DisplayText = EditorGUILayout.TextField(link.DisplayText); link.Link = EditorGUILayout.TextField(link.Link); EditorGUILayout.EndHorizontal(); e.Links[j] = link; } EditorGUI.indentLevel -= 1; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("L+", GUILayout.Width(30))) { e.Links.Add(new GHelpLink()); } GUI.enabled = e.Links.Count > 0; if (GUILayout.Button("L-", GUILayout.Width(30))) { e.Links.RemoveAt(e.Links.Count - 1); } GUI.enabled = true; if (GUILayout.Button("Delete Entry")) { if (EditorUtility.DisplayDialog( "Confirm", "Delete this entry?", "OK", "Cancel")) { entries.RemoveAt(i); Event.current.Use(); continue; } } if (GUILayout.Button("Duplicate")) { GHelpEntry newEntry = entries[i]; newEntry.Links = new List <GHelpLink>(entries[i].Links); entries.Add(newEntry); string prefKey = GEditorCommon.GetProjectRelatedEditorPrefsKey("foldout", prefPrefix + (entries.Count - 1)); EditorPrefs.SetBool(prefKey, true); Event.current.Use(); continue; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } entries[i] = e; } if (GEditorCommon.RightAnchoredButton("Add")) { entries.Add(new GHelpEntry()); } EditorUtility.SetDirty(instance); }