Version: 2022.1
언어: 한국어
public bool LoadBytes (byte[] bytes, Action<bool> finished);

파라미터

bytes Binary buffer containing the index representation.
finished Callback that triggers when the index is fully loaded. The callback parameters indicates if loading was succesful.

반환

bool Returns false if the index is of an unsupported version or if there was a problem initializing the reading thread.

설명

Loads the index asynchronously (in another thread) from a binary buffer.

using System.IO;
using UnityEditor;
using UnityEditor.Search;
using UnityEngine;

static class Example_SearchIndexer_LoadBytes
{
    const string tempIndexPath = "Temp/LoadBytes.db";

    [MenuItem("Examples/SearchIndexer/LoadBytes")]
    public static void Run()
    {
        var si = new SearchIndexer();
        si.Start();
        var di = si.AddDocument("document 1");
        si.AddNumber("test", 2, 0, di);
        si.Finish(() =>
        {
            File.WriteAllBytes(tempIndexPath, si.SaveBytes());
            ReloadIndex();
        });
    }

    private static void ReloadIndex()
    {
        var indexBytes = File.ReadAllBytes(tempIndexPath);
        var si = new SearchIndexer();

        // Load the search index from a binary stream.
        si.LoadBytes(indexBytes, (success) =>
        {
            Debug.Assert(success);
            Debug.Log($"Index loaded from {indexBytes} bytes");
        });
    }
}