stream | 要从中读取索引的流。 |
checkVersionOnly | 如果为 true,则验证索引的版本。 |
bool 如果索引版本不受支持,则返回 false。
读取流并从中填充索引。
using System.IO; using System.Linq; using UnityEditor; using UnityEditor.Search; using UnityEngine; static class Example_SearchIndexer_Read { [MenuItem("Examples/SearchIndexer/Read")] public static void Run() { var si = new SearchIndexer(); si.Start(); si.AddDocument("document 1"); si.AddDocument("document 2"); si.Finish(() => { File.WriteAllBytes("Temp/Read.index", si.SaveBytes()); // Stream the index from disk but only check if the stream is valid. using (var fileStream = new FileStream("Temp/Read.index", FileMode.Open, FileAccess.Read, FileShare.Read)) { var copyIndex = new SearchIndexer(); Debug.Assert(copyIndex.Read(fileStream, checkVersionOnly: true)); } // Completely stream the index from disk. using (var fileStream = new FileStream("Temp/Read.index", FileMode.Open, FileAccess.Read, FileShare.Read)) { var copyIndex = new SearchIndexer(); Debug.Assert(copyIndex.Read(fileStream, checkVersionOnly: false)); Debug.Assert(copyIndex.GetDocument(0).id == "document 1"); } }); } }