docs.unity3d.com
    Show / Hide Table of Contents

    Struct UQueryBuilder<T>

    Utility Object that contructs a set of selection rules to be ran on a root visual element.

    Namespace: UnityEngine.UIElements
    Syntax
    public struct UQueryBuilder<T> : IEquatable<UQueryBuilder<T>> where T : VisualElement
    Type Parameters
    Name Description
    T

    Constructors

    UQueryBuilder(VisualElement)

    Initializes a QueryBuilder.

    Declaration
    public UQueryBuilder(VisualElement visualElement)
    Parameters
    Type Name Description
    VisualElement visualElement

    The root element on which to condfuct the search query.

    Methods

    Active()

    Selects all elements that are active.

    Declaration
    public UQueryBuilder<T> Active()
    Returns
    Type Description
    UQueryBuilder<T>

    A QueryBuilder with the selection rules.

    AtIndex(Int32)

    Convenience overload, shorthand for Build().AtIndex().

    Declaration
    public T AtIndex(int index)
    Parameters
    Type Name Description
    Int32 index
    Returns
    Type Description
    T
    See Also
    AtIndex(Int32)

    Build()

    Compiles the selection rules into a QueryState object.

    Declaration
    public UQueryState<T> Build()
    Returns
    Type Description
    UQueryState<T>

    Checked()

    Selects all elements that are checked.

    Declaration
    public UQueryBuilder<T> Checked()
    Returns
    Type Description
    UQueryBuilder<T>

    Children<T2>(String, String)

    Selects all direct child elements of elements matching the previous rules.

    Declaration
    public UQueryBuilder<T2> Children<T2>(string name = null, string className = null)
        where T2 : VisualElement
    Parameters
    Type Name Description
    String name
    String className
    Returns
    Type Description
    UQueryBuilder<T2>
    Type Parameters
    Name Description
    T2

    Children<T2>(String, String[])

    Selects all direct child elements of elements matching the previous rules.

    Declaration
    public UQueryBuilder<T2> Children<T2>(string name = null, params string[] classes)
        where T2 : VisualElement
    Parameters
    Type Name Description
    String name
    String[] classes
    Returns
    Type Description
    UQueryBuilder<T2>
    Type Parameters
    Name Description
    T2

    Class(String)

    Selects all elements with the specified class in the class list, as specified with the class attribute in a UXML file or added with AddToClassList(String) method.

    Declaration
    public UQueryBuilder<T> Class(string classname)
    Parameters
    Type Name Description
    String classname

    The class to use in the query.

    Returns
    Type Description
    UQueryBuilder<T>
    Remarks

    This method can be called multiple times in order to select elements with multiple classes. To select elements by their C# type, use OfType<T2>(String, String[]).

    Descendents<T2>(String, String)

    Selects all elements that are descendants of currently matching ancestors.

    Declaration
    public UQueryBuilder<T2> Descendents<T2>(string name = null, string classname = null)
        where T2 : VisualElement
    Parameters
    Type Name Description
    String name
    String classname
    Returns
    Type Description
    UQueryBuilder<T2>
    Type Parameters
    Name Description
    T2

    Descendents<T2>(String, String[])

    Selects all elements that are descendants of currently matching ancestors.

    Declaration
    public UQueryBuilder<T2> Descendents<T2>(string name = null, params string[] classNames)
        where T2 : VisualElement
    Parameters
    Type Name Description
    String name
    String[] classNames
    Returns
    Type Description
    UQueryBuilder<T2>
    Type Parameters
    Name Description
    T2

    Enabled()

    Selects all elements that are enabled.

    Declaration
    public UQueryBuilder<T> Enabled()
    Returns
    Type Description
    UQueryBuilder<T>

    Equals(Object)

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj
    Returns
    Type Description
    Boolean

    Equals(UQueryBuilder<T>)

    Declaration
    public bool Equals(UQueryBuilder<T> other)
    Parameters
    Type Name Description
    UQueryBuilder<T> other
    Returns
    Type Description
    Boolean

    First()

    Convenience overload, shorthand for Build().First().

    Declaration
    public T First()
    Returns
    Type Description
    T

    The first element matching all the criteria, or null if none was found.

    See Also
    First()

    Focused()

    Selects all elements that are enabled.

    Declaration
    public UQueryBuilder<T> Focused()
    Returns
    Type Description
    UQueryBuilder<T>

    ForEach(Action<T>)

    Convenience overload, shorthand for Build().ForEach().

    Declaration
    public void ForEach(Action<T> funcCall)
    Parameters
    Type Name Description
    Action<T> funcCall

    The function to be invoked with each matching element.

    ForEach<T2>(Func<T, T2>)

    Convenience overload, shorthand for Build().ForEach().

    Declaration
    public List<T2> ForEach<T2>(Func<T, T2> funcCall)
    Parameters
    Type Name Description
    Func<T, T2> funcCall

    The function to be invoked with each matching element.

    Returns
    Type Description
    List<T2>
    Type Parameters
    Name Description
    T2

    ForEach<T2>(List<T2>, Func<T, T2>)

    Convenience overload, shorthand for Build().ForEach().

    Declaration
    public void ForEach<T2>(List<T2> result, Func<T, T2> funcCall)
    Parameters
    Type Name Description
    List<T2> result

    Each return value will be added to this list.

    Func<T, T2> funcCall

    The function to be invoked with each matching element.

    Type Parameters
    Name Description
    T2

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    Hovered()

    Selects all elements that are hovered.

    Declaration
    public UQueryBuilder<T> Hovered()
    Returns
    Type Description
    UQueryBuilder<T>

    Last()

    Convenience overload, shorthand for Build().Last().

    Declaration
    public T Last()
    Returns
    Type Description
    T

    The last element matching all the criteria, or null if none was found.

    Name(String)

    Selects element with this name.

    Declaration
    public UQueryBuilder<T> Name(string id)
    Parameters
    Type Name Description
    String id
    Returns
    Type Description
    UQueryBuilder<T>

    NotActive()

    Selects all elements that are not active.

    Declaration
    public UQueryBuilder<T> NotActive()
    Returns
    Type Description
    UQueryBuilder<T>

    NotChecked()

    Selects all elements that npot checked.

    Declaration
    public UQueryBuilder<T> NotChecked()
    Returns
    Type Description
    UQueryBuilder<T>

    NotEnabled()

    Selects all elements that are not enabled.

    Declaration
    public UQueryBuilder<T> NotEnabled()
    Returns
    Type Description
    UQueryBuilder<T>

    NotFocused()

    Selects all elements that don't currently own the focus.

    Declaration
    public UQueryBuilder<T> NotFocused()
    Returns
    Type Description
    UQueryBuilder<T>

    NotHovered()

    Selects all elements that are not hovered.

    Declaration
    public UQueryBuilder<T> NotHovered()
    Returns
    Type Description
    UQueryBuilder<T>

    NotSelected()

    Selects all elements that are not selected.

    Declaration
    public UQueryBuilder<T> NotSelected()
    Returns
    Type Description
    UQueryBuilder<T>

    NotVisible()

    Selects all elements that are not visible.

    Declaration
    public UQueryBuilder<T> NotVisible()
    Returns
    Type Description
    UQueryBuilder<T>

    OfType<T2>(String, String)

    Selects all elements of the specified Type (eg: Label, Button, ScrollView, etc).

    Declaration
    public UQueryBuilder<T2> OfType<T2>(string name = null, string className = null)
        where T2 : VisualElement
    Parameters
    Type Name Description
    String name

    If specified, will select elements with this name.

    String className

    If specified, will select elements with the given class (not to be confused with Type).

    Returns
    Type Description
    UQueryBuilder<T2>

    QueryBuilder configured with the associated selection rules.

    Type Parameters
    Name Description
    T2

    OfType<T2>(String, String[])

    Selects all elements of the specified Type (eg: Label, Button, ScrollView, etc).

    Declaration
    public UQueryBuilder<T2> OfType<T2>(string name = null, params string[] classes)
        where T2 : VisualElement
    Parameters
    Type Name Description
    String name

    If specified, will select elements with this name.

    String[] classes

    If specified, will select elements with the given class (not to be confused with Type).

    Returns
    Type Description
    UQueryBuilder<T2>

    QueryBuilder configured with the associated selection rules.

    Type Parameters
    Name Description
    T2

    Selected()

    Selects all elements that are not selected.

    Declaration
    public UQueryBuilder<T> Selected()
    Returns
    Type Description
    UQueryBuilder<T>

    ToList()

    Convenience method. shorthand for Build().ToList.

    Declaration
    public List<T> ToList()
    Returns
    Type Description
    List<T>

    A list containing elements satisfying selection rules.

    ToList(List<T>)

    Convenience method. Shorthand gor Build().ToList().

    Declaration
    public void ToList(List<T> results)
    Parameters
    Type Name Description
    List<T> results

    Adds all elements satisfying selection rules to the list.

    Visible()

    Selects all elements that are not visible.

    Declaration
    public UQueryBuilder<T> Visible()
    Returns
    Type Description
    UQueryBuilder<T>

    Where(Func<T, Boolean>)

    Selects all elements satifying the predicate.

    Declaration
    public UQueryBuilder<T> Where(Func<T, bool> selectorPredicate)
    Parameters
    Type Name Description
    Func<T, Boolean> selectorPredicate

    Predicate that must return true for selected elements.

    Returns
    Type Description
    UQueryBuilder<T>

    QueryBuilder configured with the associated selection rules.

    Operators

    Equality(UQueryBuilder<T>, UQueryBuilder<T>)

    Declaration
    public static bool operator ==(UQueryBuilder<T> builder1, UQueryBuilder<T> builder2)
    Parameters
    Type Name Description
    UQueryBuilder<T> builder1
    UQueryBuilder<T> builder2
    Returns
    Type Description
    Boolean

    Implicit(UQueryBuilder<T> to T)

    Declaration
    public static implicit operator T(UQueryBuilder<T> s)
    Parameters
    Type Name Description
    UQueryBuilder<T> s
    Returns
    Type Description
    T

    Inequality(UQueryBuilder<T>, UQueryBuilder<T>)

    Declaration
    public static bool operator !=(UQueryBuilder<T> builder1, UQueryBuilder<T> builder2)
    Parameters
    Type Name Description
    UQueryBuilder<T> builder1
    UQueryBuilder<T> builder2
    Returns
    Type Description
    Boolean
    In This Article
    • Constructors
      • UQueryBuilder(VisualElement)
    • Methods
      • Active()
      • AtIndex(Int32)
      • Build()
      • Checked()
      • Children<T2>(String, String)
      • Children<T2>(String, String[])
      • Class(String)
      • Descendents<T2>(String, String)
      • Descendents<T2>(String, String[])
      • Enabled()
      • Equals(Object)
      • Equals(UQueryBuilder<T>)
      • First()
      • Focused()
      • ForEach(Action<T>)
      • ForEach<T2>(Func<T, T2>)
      • ForEach<T2>(List<T2>, Func<T, T2>)
      • GetHashCode()
      • Hovered()
      • Last()
      • Name(String)
      • NotActive()
      • NotChecked()
      • NotEnabled()
      • NotFocused()
      • NotHovered()
      • NotSelected()
      • NotVisible()
      • OfType<T2>(String, String)
      • OfType<T2>(String, String[])
      • Selected()
      • ToList()
      • ToList(List<T>)
      • Visible()
      • Where(Func<T, Boolean>)
    • Operators
      • Equality(UQueryBuilder<T>, UQueryBuilder<T>)
      • Implicit(UQueryBuilder<T> to T)
      • Inequality(UQueryBuilder<T>, UQueryBuilder<T>)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023