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