context | 当前搜索上下文。 |
options | 定义查询执行方式的选项。 |
List<SearchItem> 与搜索查询匹配的搜索项列表。
启动搜索并返回与搜索上下文匹配的所有搜索项。其他项目可以使用异步搜索稍后找到。
Unity 建议使用 SearchService.Request 执行搜索查询。GetItems
通常需要设置更多上下文才能获得良好的结果。以下是一个使用 GetItems
的简单示例。
using System.Collections.Generic; using UnityEditor; using UnityEditor.Search; using UnityEngine; static class Example_SearchService_GetItems { [MenuItem("Examples/SearchService/GetItems")] public static void Run() { // Create a container to hold found items. var results = new List<SearchItem>(); // Create the search context that will be used to execute the query. using (var searchContext = SearchService.CreateContext("scene", "is:leaf")) { // Initiate the query and get the results. // Note: it is recommended to use SearchService.Request if you wish to fetch the items asynchronously. results = SearchService.GetItems(searchContext, SearchFlags.WantsMore | SearchFlags.Synchronous); // Print results foreach (var searchItem in results) Debug.Log(searchItem.GetDescription(searchContext)); } } }