Version: 2021.1
언어: 한국어

SearchProvider.isExplicitProvider

매뉴얼로 전환
public bool isExplicitProvider ;

설명

This search provider is only active when specified explicitly using the filterId.

using UnityEditor;
using UnityEditor.Search;
using UnityEngine;

static class SearchProvider_isExplicitProvider
{
    internal static string type = "example_uppercase_isExplicitProvider";
    internal static string displayName = "example_UpperCase_isExplicitProvider";

    [SearchItemProvider]
    internal static SearchProvider CreateProvider()
    {
        return new SearchProvider(type, displayName)
        {
            active = false,
            filterId = "+",
            priority = 99999, // put example provider at a low priority
            isExplicitProvider = true,
            fetchItems = (context, items, provider) =>
            {
                var expression = context.searchQuery;
                expression += " -> " + expression.ToUpper();

                items.Add(provider.CreateItem(context, context.searchQuery.ToUpper(), context.searchQuery.ToUpper(), expression, null, null));
                return null;
            }
        };
    }

    [MenuItem("Examples/SearchProvider/isExplicitProvider")]
    public static void Run()
    {
        SearchService.SetActive(type);
        var view = SearchService.ShowWindow();
        // If we don't specify the filterId for an explicit provider, there will be no results.
        view.SetSearchText("uppercase String");
        Debug.Log(view.results.Count); // 0;

        view.Close();
        view = SearchService.ShowWindow();

        // Use the filterId for an explicit provider
        view.SetSearchText("+uppercase String");
        // There should be only one result with that specific description
        Debug.Log(view.results.Count); // 1;
        Debug.Log(view.results[0].description); // "uppercase String -> UPPERCASE STRING";
    }
}

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961