Version: 2021.1
언어: 한국어
public bool active ;

설명

Indicates if the search provider is active or not. Inactive search providers are ignored by the search service. The active state can be toggled in the search settings.

using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEditor.Search;
using UnityEngine;

static class SearchProvider_active
{
    static string typeColors = "example_colors_active";
    static string displayNameColors = "example_Colors_active";
    static string typeFruits = "example_fruits_active";
    static string displayNameFruits = "example_Fruits_active";

    static List<string> colors = new List<string> { "orange", "red", "green", "blue" };
    static List<string> fruits = new List<string> { "orange", "apple", "banana", "strawberry" };

    [SearchItemProvider]
    internal static SearchProvider CreateProviderColors()
    {
        return new SearchProvider(typeColors, displayNameColors)
        {
            active = false,
            filterId = "c:",
            priority = 99999, // put example provider at a low priority
            isExplicitProvider = false,
            fetchItems = (context, items, provider) =>
            {
                var expression = context.searchQuery;
                if (colors.Contains(expression))
                {
                    var id = expression + "(color)";
                    items.Add(provider.CreateItem(context, id, id, id, null, null));
                }
                return null;
            }
        };
    }

    [SearchItemProvider]
    internal static SearchProvider CreateProviderFruits()
    {
        return new SearchProvider(typeFruits, displayNameFruits)
        {
            active = false,
            filterId = "f:",
            priority = 99999, // put example provider at a low priority
            isExplicitProvider = false,
            fetchItems = (context, items, provider) =>
            {
                var expression = context.searchQuery;
                if (fruits.Contains(expression))
                {
                    var id = expression + "(fruit)";
                    items.Add(provider.CreateItem(context, id, id, id, null, null));
                }
                return null;
            }
        };
    }

    [MenuItem("Examples/SearchProvider/active")]
    public static void Run()
    {
        var colorProvider = SearchService.GetProvider(typeColors);
        colorProvider.active = false;

        var context = SearchService.CreateContext("orange");

        // The providers used in the context should not contain the inactive provider
        var sb = new StringBuilder();
        foreach (var provider in context.providers)
            sb.AppendLine(provider.name);
        Debug.Log(sb.ToString());
    }
}

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