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

SearchSelection.Count

提出更改建议

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交内容,但我们将阅读来自我们用户的每一条建议性更改,并在适用时进行更新。

关闭

提交失败

由于某种原因,您建议的更改无法提交。请在几分钟后重试。感谢您抽出宝贵时间帮助我们提高 Unity 文档的质量。

关闭

取消

public int Count;

描述

已选择项的数量。

using UnityEngine;
using UnityEditor;
using UnityEditor.Search;

static class Example_ISearchView_AddSelection
{
    static ISearchView s_View;

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

        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 AddSelection to append to the current selection.
        s_View.AddSelection(0);
        s_View.AddSelection(2);
        s_View.AddSelection(4);

        // Validate what is actually selected:
        var selection = s_View.selection;
        Debug.Log(selection.Count); // 3
        Debug.Log(selection.MinIndex()); // 0
        Debug.Log(selection.MaxIndex()); // 4
    }
}