Version: 2021.3
public Func<SearchItem,SearchContext,Vector2,FetchPreviewOptions,Texture2D> fetchPreview ;

描述

Similar to fetchThumbnail, fetchPreview usually returns a bigger preview. The Search UI will progressively show one preview each frame, preventing the UI from blocking if many previews need to be generated at the same time.

[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);
            }
        }
    };
}