Version: 2022.1
言語: 日本語
USS セレクター
名前セレクター

Type selectors

USS type selectors match elements based on their element types. USS type selectors are analogous to CSS type selectors that match HTML tags. For example, Button {...} in USS matches any Button elements in the same way that p {...} in CSS matches any paragraph (<p>) tag.

構文

The following is the syntax for a type selector:

TypeName {...}

When you write type selectors, specify only the concrete object type. Don’t include the namespace in the type name.

例えば、このセレクターは有効です。

Button { ... }

This selector is invalid:

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 は以下のようになります。

余白と細い青い縁取りのあるボタンの例。
余白と細い青い縁取りのあるボタンの例。

The following type selector style rule matches the two Button elements:

Button {
  border-radius: 8px;
  width: 100px;
  }

スタイルを適用すると、UI は以下のようになります。

Example buttons with border radius and specific width.
Example buttons with border radius and specific width.

その他の参考資料

USS セレクター
名前セレクター