context | 作为起始条件的搜索内容。 |
topic | 要搜索的话题。 |
saveFilters | 如果用户搜索提供者筛选器应保存至下一搜索会话,则为 True。 |
reuseExisting | 如果应为下一会话保存活动提供者,则为 True。 |
multiselect | 如果搜索支持多选,则为 True。 |
defaultWidth | 窗口的初始宽度。 |
defaultHeight | 窗口的初始高度。 |
dockable | 如果为 true,则创建一个可停靠的搜索窗口(激活某项时关闭)。如果为 false,则创建搜索窗口的向下展开(无边框、不可停靠且不可移动)版本。 |
ISearchView 返回搜索视图窗口实例。
创建新的搜索窗口。
using UnityEditor; using UnityEditor.Search; static class Example_SearchService_ShowWindow { [MenuItem("Examples/SearchService/ShowWindowEmpty")] public static void Run1() { SearchService.ShowWindow() .SetSearchText(string.Empty); } [MenuItem("Examples/SearchService/ShowWindowWithSearchText")] public static void Run2() { SearchService.ShowWindow(SearchService.CreateContext("m: Profiler")); } [MenuItem("Examples/SearchService/ShowWindowCustomTopic")] public static void Run3() { SearchService.ShowWindow(topic: "My Things") .SetSearchText(string.Empty); } [MenuItem("Examples/SearchService/ShowPopupWindow")] public static void Run4() { SearchService.ShowWindow(defaultWidth: 1300, defaultHeight: 700, dockable: false); } }
viewState | 用于打开搜索窗口的搜索视图状态。 |
ISearchView 返回搜索视图窗口实例。
创建新的搜索窗口。
using UnityEditor; using UnityEditor.Search; using UnityEngine.Search;
static class SearchWindows { [MenuItem("Search/Views/Simple Search Bar 1")] public static void SearchViewFlags1() => CreateWindow(SearchViewFlags.None); [MenuItem("Search/Views/Simple Search Bar 2")] public static void SearchViewFlags2() => CreateWindow(SearchViewFlags.EnableSearchQuery); [MenuItem("Search/Views/Simple Search Bar 3")] public static void SearchViewFlags3() => CreateWindow(SearchViewFlags.DisableInspectorPreview); [MenuItem("Search/Views/Simple Search Bar 4")] public static void SearchViewFlags4() => CreateWindow(SearchViewFlags.EnableSearchQuery | SearchViewFlags.DisableInspectorPreview);
static void CreateWindow(SearchViewFlags flags) { var searchContext = SearchService.CreateContext(string.Empty); var viewArgs = new SearchViewState(searchContext, SearchViewFlags.CompactView | flags) { title = flags.ToString() }; SearchService.ShowWindow(viewArgs); } }