Version: 2023.2
언어: 한국어
Type selectors
Class selectors

Name selectors

USS name selectors match elements based on the name of an element. USS Name selectors are analogous to CSS ID selectors that match elements with a specific id attribute.

To set the name of an element:

  • In C# script, use VisualElement.name.
  • In UXML, use the name attribute. For example: <VisualElement name="my-nameName">.

To avoid unexpected matches, make element names unique within a panel.

구문

이름 선택자는 앞에 숫자 기호(#)가 붙은 요소의 할당된 이름으로 구성됩니다.

#ElementName { ... }

Note: Only use the number sign (#) when you write the selector in a USS file. Don’t use it when you assign the name to an element in a UXML or C# file. An element name that includes the number sign is invalid. For example <Button name="#OK" /> is invalid.

예제

To demonstrate how simple selectors match elements, here is an example UI Document.

<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>

With no styles applied, the UI looks like the following:

Example buttons with margins and thin blue borders.
Example buttons with margins and thin blue borders.

The following name selector style rule matches the second Button element.

# Cancel {
    border-width: 2px;
    border-color: DarkRed;
    background-color: pink;
}

The UI looks like the following when you apply the style:

The Cancel button has a dark red border and a pink background.
The Cancel button has a dark red border and a pink background.

추가 리소스

Type selectors
Class selectors
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961