版本: Unity 6 (6000.0)
语言English
  • C#

SearchIndexer.skipEntryHandler

建议修改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实会阅读用户提出的每项建议更改,并在适用时进行更新。

关闭

提交失败

由于某些原因,您的建议更改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

public Func<string,bool> skipEntryHandler;

描述

用于跳过条目的处理程序。

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] == '_';
    }
}