Version: 2023.1

SearchIndexer.skipEntryHandler

切换到手册
public Func<string,bool> skipEntryHandler ;

描述

Handler used to skip entries.

using UnityEditor;
using UnityEditor.Search;
using UnityEngine;

static class Example_SearchIndexer_skipEntryHandler
{
    [MenuItem("Examples/SearchIndexer/skipEntryHandler")]
    public static void Run()
    {
        var searchIndexer = new SearchIndexer
        {
            // The skip entry handler can be used to prevent some documents from being indexed.
            skipEntryHandler = SkipDocumentThatStartsWithAnUnderscore
        };

        searchIndexer.Start();
        {
            var di = searchIndexer.AddDocument("A/Valid/File/Path");
            Debug.Assert(di >= 0);

            // This document should get discarded.
            di = searchIndexer.AddDocument("_Not/Valid/File/Path");
            Debug.Assert(di == -1);
        }
        searchIndexer.Finish();

        Debug.Log($"{searchIndexer.documentCount} document were indexed");
    }

    private static bool SkipDocumentThatStartsWithAnUnderscore(string documentId)
    {
        return documentId[0] == '_';
    }
}
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961