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

参数

threadCompletedCallback Callback invoked when the index is ready to be used.
removedDocuments Documents to be removed from current index (if any).
saveBytes Indicates if the system should return the binary stream of the index as a byte array.

描述

Finalizes the current index, sorting and compiling of all the indexes.

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

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