Version: 2022.1
언어: 한국어
커스텀 검색 공급자 만들기
검색 공급자 등록

SearchProvider 클래스

SearchProvider 클래스는 특정 유형의 아이템에 대한 검색을 실행하고 썸네일, 설명, 하위 필터를 관리합니다.

다음과 같은 기본 API를 갖추고 있습니다.

public class SearchProvider
{
    public SearchProvider(string id, string displayName = null);

    // Creates an Item bound to this provider.
    public SearchItem CreateItem(string id, string label = null, string description = null, Texture2D thumbnail = null);

    // Utility functions to check whether the search text matches a string.
    public static bool MatchSearchGroups(string searchContext, string content);
    public static bool MatchSearchGroups(string searchContext, string content,
                                        out int startIndex, out int endIndex);

    // The provider's unique ID.
    public NameId name;
    // Text token to "filter" a provider (for example, "me:", "p:", and "s:").
    public string filterId;
    // This provider is only active when a search explicitly specifies it with
    // its filterId.
    public bool isExplicitProvider;
    // Handler to fetch and format the label of a search item.
    public FetchStringHandler fetchLabel;
    // Handler to provide an async description for an item. Called just before
    // Search displays the item.
    // Allows a plug-in provider to fetch long descriptions only when
    // Search needs them.
    public FetchStringHandler fetchDescription;
    // Handler to provider an async thumbnail for an item. Called just before
    // Search displays the item.
    // Allows a plug-in provider to fetch/generate previews only when
    // Search needs them.
    public PreviewHandler fetchThumbnail;
    // Handler to support drag interactions. It is up to the SearchProvider
    // to properly set up the DragAndDrop manager.
    public StartDragHandler startDrag;
    // Called when the selection changes and Search can track it.
    public TrackSelectionHandler trackSelection;
    // MANDATORY: Handler to get items for a search context.
    public GetItemsHandler fetchItems;
    // A Search Provider can return a list of words that help the user complete
    // their search query.
    public GetKeywordsHandler fetchKeywords;
    // List of sub-filters that are visible in the FilterWindow for a
    // SearchProvider (see AssetProvider for an example).
    public List<NameId> subCategories;
    // Called when the Search window opens. Allows the Provider to perform
    // some caching.
    public Action onEnable;
    // Called when the Search window closes. Allows the Provider to release
    // cached resources.
    public Action onDisable;
    // Int to sort the Provider. Affects the order of search results and the
    // order in which providers are shown in the FilterWindow.
    public int priority;
    // Called when Search opens in "contextual mode". If you return true
    // it means the provider is enabled for this search context.
    public IsEnabledForContextualSearch isEnabledForContextualSearch;
}

리소스 캐시와 릴리스

검색 창을 시작하면 리소스를 캐시하는 데 사용할 수 있는 onEnable이 호출됩니다.

검색 창을 닫으면 리소스를 릴리스하는 데 사용할 수 있는 onDisable이 호출됩니다.

초기화

검색 아이템 리스트는 가상 스크롤 알고리즘을 사용하기 때문에, 일부 SearchItem 필드(예: label, thumbnail , description)가 아직 제공되지 않은 경우 요청 시 페치됩니다.

아이템이 생성된 후 해당 필드를 채우려면 SearchProvider를 특정 핸들러(fetchLabel, fetchDescription, fetchThumbnail)로 초기화해야 합니다.

아이템 선택 트래킹

trackSelection에 콜백을 등록하면 마우스나 키보드를 사용하여 검색 결과에서 아이템을 선택할 때마다 검색을 수행하도록 할 수 있습니다. 예를 들어, 에셋 공급자는 trackSelection 콜백을 사용하여 검색에서 선택한 아이템 정보를 주고 받습니다.

드래그 앤 드롭 활성화

일부 검색 공급자는 씬으로 끌어다 놓을 수 있는 아이템을 반환합니다. 아이템이 드래그 앤 드롭을 지원하는 커스텀 공급자를 생성하는 경우, startDrag를 구현합니다.

예를 들어, 에셋 공급자는 올바른 드래그 앤 드롭 상호 작용을 허용하기 위해 관련 아이템 UID로 DragAndDrop 구조를 채웁니다.

공급자를 포함한 컨텍스트 검색

Alt Shift + C 단축키로 검색 창을 열면 컨텍스트 검색을 시작합니다. 즉, 포커스가 있는 창을 검색합니다.

컨텍스트 검색을 시작할 때 isEnabledForContextualSearch를 오버라이드하는 공급자를 다음 예제와 같이 활성화해야 하는지 확인합니다.

// Taken from Scene hierarchy provider:
// Makes the provider part of the contextual search if the Scene view or the
// Hierarchy window has focus.
isEnabledForContextualSearch = () =>
                QuickSearchTool.IsFocusedWindowTypeName("SceneView") ||
                QuickSearchTool.IsFocusedWindowTypeName("SceneHierarchyWindow");
커스텀 검색 공급자 만들기
검색 공급자 등록
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961