版本: Unity 6 (6000.0)
语言英语
  • C#

ISearchView.SetSelection

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交内容,但我们确实阅读了用户提出的每个建议更改,并在适用情况下进行更新。

关闭

提交失败

由于某种原因,您的建议更改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

声明

public void SetSelection(params int[] selection);

参数

selection 要选择的项目索引数组。

描述

使用新的选择更新搜索视图。

.

using UnityEditor;
using UnityEditor.Search;

static class Example_ISearchView_SetSelection
{
    static ISearchView s_View;
    [MenuItem("Examples/ISearchView/SetSelection")]
    public static void Run()
    {
        s_View = SearchService.ShowContextual("asset");
        s_View.SetSearchText("t:MonoScript");

        // Calling SetSelection when no results are available has no effect.
        // Wait until some results are available.
        EditorApplication.delayCall += DisplayResultsWhenReady;
    }

    public static void DisplayResultsWhenReady()
    {
        // Wait until results are ready to process.
        if (s_View.results.pending || s_View.results.Count == 0)
        {
            EditorApplication.delayCall += DisplayResultsWhenReady;
            return;
        }

        // Use SetSelection to specify which items should be selected.
        s_View.SetSelection(0, 2, 4);
    }
}