docs.unity3d.com
    Show / Hide Table of Contents

    Registering a Search Provider

    To add a new Search Provider, create a function and tag it with the [SearchItemProvider] attribute, as in the following example:

    [SearchItemProvider]
    internal static SearchProvider CreateProvider()
    {
        return new SearchProvider(type, displayName)
        {
            filterId = "me:",
            fetchItems = (context, items, provider) =>
            {
                var itemNames = new List<string>();
                var shortcuts = new List<string>();
                GetMenuInfo(itemNames, shortcuts);
    
                items.AddRange(itemNames.Where(menuName =>
                        SearchProvider.MatchSearchGroups(context.searchText, menuName))
                    .Select(menuName => provider.CreateItem(menuName,
                                                Path.GetFileName(menuName), menuName)));
            },
    
            fetchThumbnail = (item, context) => Icons.shortcut
        };
    }
    
    • The function must return a new [SearchProvider] instance.
    • The SearchProvider instance must have the following:
      • A unique type. For example, Asset, Menu, or Scene.
      • A displayName to use in the Filters pane.
    • The optional filterId provides a search token for text-based filtering. For example, p: is the filter ID for Asset searches.

    Registering a Search Provider shortcut

    To register a shortcut for a new provider use:

    [UsedImplicitly, Shortcut("Help/Quick Search/Assets")]
    private static void PopQuickSearch()
    {
        // Open Quick Search with only the "Asset" provider enabled.
        QuickSearchTool.OpenWithContextualProvider("asset");
    }
    

    You can map shortcuts to keys or key combinations using the shortcuts manager.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023