Version: 2022.1
public Action<SearchItem,SearchContext> trackSelection ;

描述

Called when the selection changed and can be tracked.

[SearchItemProvider]
internal static SearchProvider CreateProvider()
{
    return new SearchProvider(id, name)
    {
        filterId = "tree:",
        priority = 99999, // put example provider at a low priority
        fetchItems = (context, items, provider) =>
        {
            // That provider searches for tree prefabs in the project
            var results = AssetDatabase.FindAssets("t:Prefab tree" + context.searchQuery);
            foreach (var guid in results)
            {
                items.Add(provider.CreateItem(context, AssetDatabase.GUIDToAssetPath(guid), null, null, null, null));
            }
            return null;
        },
        #pragma warning disable UNT0008 // Null propagation on Unity objects
        // Use fetch to load the asset asynchronously on display
        fetchThumbnail = (item, context) => AssetDatabase.GetCachedIcon(item.id) as Texture2D,
        fetchPreview = (item, context, size, options) => AssetDatabase.GetCachedIcon(item.id) as Texture2D,
        fetchLabel = (item, context) => AssetDatabase.LoadMainAssetAtPath(item.id)?.name,
        fetchDescription = (item, context) => AssetDatabase.LoadMainAssetAtPath(item.id)?.name,
        toObject = (item, type) => AssetDatabase.LoadMainAssetAtPath(item.id),
        #pragma warning restore UNT0008 // Null propagation on Unity objects
        // Shows handled actions in the preview inspector
        // Shows inspector view in the preview inspector (uses toObject)
        showDetailsOptions = ShowDetailsOptions.Inspector | ShowDetailsOptions.Actions,
        trackSelection = (item, context) =>
        {
            var obj = AssetDatabase.LoadMainAssetAtPath(item.id);
            if (obj != null)
                EditorGUIUtility.PingObject(obj.GetInstanceID());
        },
        startDrag = (item, context) =>
        {
            var obj = AssetDatabase.LoadMainAssetAtPath(item.id);
            if (obj != null)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.objectReferences = new Object[] { obj };
                DragAndDrop.StartDrag(item.label);
            }
        }
    };
}