Unity 6.3
0 онлайн 83 гостей 3 в системе
Вход

ObjectIndexer.IndexPropertyComponents

Declaration

public void IndexPropertyComponents(int documentIndex, string name, string value);

Параметры

Параметр Описание
documentIndex Код документа для индексированного свойства.
имя Ключ, используемый для получения значения.
значение Значение, добавляемое в индекс.

Описание

Индексирует несколько вариантов значения свойства.

В примере, индексирование "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
}