| documentIndex | 已编入索引的属性的文档句柄。 | 
| name | 用于检索值的键。 | 
| value | 要添加到索引的值。 | 
为属性值的多个变化编制索引。
在示例中,为“AudioClipComponent”编制索引,将按多种方式拆分单词,并编制索引变化,例如“Audio”、“Clip”、“Component”、“ACC”等。
用户将能够使用mytype:clip搜索属性,而无需使用audio开头。
using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEditor.Search; using UnityEngine; static class Example_ObjectIndexer_IndexPropertyComponents { [CustomObjectIndexer(typeof(MonoScript), version = 1)] internal static void IndexMonoScriptClassType(CustomObjectIndexerTarget context, ObjectIndexer indexer) { if (!(context.target is MonoScript script)) return; var klass = script.GetClass(); if (klass == null) return; indexer.IndexPropertyComponents(context.documentIndex, "class", klass.Name); } [MenuItem("Examples/ObjectIndexer/IndexPropertyComponents")] public static void Run() { void PrintResults(IEnumerable<SearchItem> items) => Debug.Log(string.Join(", ", items.Select(r => r.id))); var context = SearchService.CreateContext("asset", "a:examples class:property"); context.asyncItemReceived += (context, items) => PrintResults(items); PrintResults(SearchService.GetItems(context)); } }
此示例假设您使用类似于此索引对 MonoScript 进行了编制索引
{
    "name": "examples",
    "type": "asset",
    "roots": [],
    "includes": [
        ".cs"
    ],
    "excludes": [
        "Temp/",
        "External/"
    ],
    "options": {
        "disabled": false,
        "types": true,
        "properties": true,
        "extended": false,
        "dependencies": false
    },
    "baseScore": 100
}