You can use UQuery to retrieve elements from a visual tree. UQuery is based on JQuery or Linq, and is designed to limit dynamic memory allocation as much as possible. This allows for optimal performance on mobile platforms.
To use UQuery to retrieve elements, use the UQueryExtensions.Q
or initialize a QueryBuilder
with UQueryExtensions.Query
.
例如,以下 UQuery 从根开始查找名为 foo
的第一个 Button
:
root.Query<Button>("foo").First();
以下 UQuery 在同一个组中名为 foo
的每个 Button
上进行迭代:
root.Query("foo").Children<Button>().ForEach(//执行操作);
Consider the following when you use UQuery:
QueryState
struct (returned by the element.Query()
method) and enumerate it to avoid creating lists. You can also construct a query once and execute it on different elements.VisualElement
variables inside closures.