包含此页的版本:
不含此页的版本:
USS 类型选择器根据元素类型匹配元素。USS 类型选择器类似于匹配 HTML 标签的 CSS 类型选择器。例如Button {...}在 USS 中匹配任何 Button 元素的方式与p {...}在 CSS 中匹配任何段落 (<p>) 标签。
以下是类型选择器的语法:
TypeName { ... }
编写类型选择器时,请仅指定具体对象类型。不要在类型名称中包含命名空间。
例如,此选择器是有效的:
Button { ... }
此选择器无效:
UnityEngine.UIElements.Button { ... }
为了演示简单选择器如何匹配元素,下面是一个示例 UI 文档。
<UXML xmlns="UnityEngine.UIElements">
<VisualElement name="container1">
<VisualElement name="container2" class="yellow">
<Button name="OK" class="yellow" text="OK" />
<Button name="Cancel" text="Cancel" />
</VisualElement>
</VisualElement>
</UXML>
未应用任何样式的情况下,UI 如下所示:
以下类型选择器样式规则与Button元素:
Button {
border-radius: 8px;
width: 100px;
}
应用样式时,UI 如下所示: