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

SearchIndexer.Finish

建议更改

成功!

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

关闭

提交失败

由于某些原因,您建议的更改无法提交。请在几分钟内重新尝试。感谢您花时间帮助我们改进 Unity 文档的质量。

关闭

取消

声明

public void Finish();

声明

public void Finish(string[] removedDocuments);

声明

public void Finish(Unity.Android.Gradle.Manifest.Action threadCompletedCallback);

声明

public void Finish(Unity.Android.Gradle.Manifest.Action threadCompletedCallback, string[] removedDocuments);

声明

public void Finish(Action<byte[]> threadCompletedCallback, string[] removedDocuments);

声明

public void Finish(Action<byte[]> threadCompletedCallback, string[] removedDocuments, bool saveBytes);

参数

threadCompletedCallback 索引准备好使用时调用的回调。
removedDocuments 需要从当前索引中移除的文档(如果存在)。
saveBytes 指示系统是否应将索引的二进制流作为字节数组返回。

描述

完成当前索引、对所有索引进行排序并对其进行编译。

using System.Linq;
using UnityEditor;
using UnityEditor.Search;
using UnityEngine;

/// <summary>
/// SearchIndexer.Finish is always a threaded operation, meaning that all indexes
/// will be computed in a thread and Search will callback when the index is ready
/// to be used.
/// </summary>
static class Example_SearchIndexer_Finish
{
    [MenuItem("Examples/SearchIndexer/Finish")]
    public static void Run()
    {
        // Create an indexer and wait for indexing to complete in the current thread.
        var si = new SearchIndexer();
        si.Start();
        si.AddProperty("wait", "yes", si.AddDocument("Wait"));
        si.Finish();
        while (!si.IsReady())
            ;
        Debug.Assert(si.IsReady());

        // Reset the indexer and receive a callback when the indexing is completed.
        si.Start(clear: true);
        si.AddProperty("wait", "callback", si.AddDocument("Callback"));
        si.Finish(() => Debug.Log("Indexing is ready."));
        while (!si.IsReady())
            ;

        // Reset the indexer and receive a callback when the indexing is completed and backup the index.
        // With that override you can also indicate if you want any documents to be deleted
        si.Start(clear: false);
        si.AddProperty("wait", "callback", si.AddDocument("CallbackBytes"));
        si.AddProperty("wait", "callback", si.AddDocument("DeleteMe"));
        si.Finish((bytes) => Debug.Log($"Indexing is ready and its size is {bytes.Length}."), new string[] { "Callback", "DeleteMe" });
    }
}