USS データ型は、キーワードや単位など USS プロパティと関数が受け入れる典型的な値を定義します。
USS プロパティは、W3C CSS ドキュメントと同じ文法構文を使用します。
auto
、baseline
<
と >
) の間に表記します。例: <length>
、<color>
<
と >
) の間に表記します。例: <'width'>
プロパティー値に複数のオプションがある場合は、以下が適用されます。
|
) separates two or more options. One of them must occur.|
|`) separate two or more options. One or more of them must occur in any order.&&
) は、2 つ以上のオプションを区切ります。すべてのオプションが発生します。[
]
) はグループ化を意味します。すべての型、キーワード、または山括弧 <> で囲まれたグループの後にモディファイアが記載される場合があります。以下の表に、使用可能なモディファイアのリストです。
修飾子 | 直前の型、キーワード、またはグループ |
---|---|
アスタリスク (* ) |
0 回以上発生 |
プラス記号 (+ ) |
1 回以上発生 |
疑問詞 (? ) |
オプション |
中括弧内の 1 組の数字 ({A,B} ) |
少なくとも A 回、最多で B 回発生します。 |
UI Toolkit は長さの単位としてピクセル (px
) とパーセンテージ (%
) をサポートします。ピクセル値は絶対値ですが、パーセンテージは、要素の親に相対的です。
例:
width:200px;
は、幅が 200 ピクセルであることを表します。width:50%;
は、幅が親要素の半分であることを表しています。測定単位を指定することは重要です。単位を指定しない場合、UI Toolkit はプロパティ値がピクセルで表されていると想定します。
ノート: 0
は、測定単位を必要としない特別な値です。
数値は、浮動小数点数または整数リテラルで表されます。例えば、flex:1.0
です。
一部のビルトインプロパティでは、特定のキーワードがサポートされています。キーワードには、番号の代わりに position:absolute
のようなわかりやすい名前があります。
すべてのプロパティは、プロパティのデフォルト値を要素にリセットするグローバルキーワード initial
に対応します。
以下の例では、すべてのラベルの色を赤に設定していますが、color
の initial
キーワードは label1
の色をデフォルト値に戻します。
/* Set the color of all the labels to red. */
Label {
color: red;
}
/* label1 is the name of a specific label. */
# label1{
color: initial;
}
UI Toolkit は、以下のリテラルの色の値と関数をサポートします。
#FFFF00
(rgba はチャンネルごとに 1 バイト)、#0F0
(rgb)rgb(255, 255, 0)
rgba(255, 255, 0, 1.0)
フォントやテクスチャなどのプロジェクトアセットを、USS ファイルから参照することができます。例えば、テクスチャを参照して、要素の背景画像として使用できます。
アセットを参照するには、url()
関数または resource()
関数を使用します。
resource()
: Resources
フォルダーのアセットを表します。ほとんどの場合、url()
関数を使用します。ただし、resource()
関数は、画面の密度に応じて異なるバージョンの画像アセットを自動的にロードすることをサポートしています。
url()
関数でアセットを参照する際、指定するパスは相対パスでも絶対パスでも構いません。
パスは、ファイルの拡張子を含む必要があります。
例えば、プロジェクトに、すべてのスタイルシートを含む USS
フォルダーと、すべての画像アセットを含む Resources
フォルダーがあるとします。
Assets
└─ Editor
└─ Resources
└─ USS
thumb.png
という名前の画像を参照するには、以下のいずれかのパスを使用します。
相対パス | 絶対パス |
---|---|
url("../Resources/thumb.png") |
url("/Assets/Editor/Resources/thumb.png") url("project:/Assets/Editor/Resources/thumb.png") url("project:///Assets/Editor/Resources/thumb.png")
|
resource()
関数は、Unity のリソースフォルダー (Resources
と Editor Default Resources
) にあるアセットを参照できます。アセットの参照は名前で行います。
Editor Default Resources Resources
フォルダーにある場合は、ファイルの拡張子が必要です。Resources
フォルダーにある場合は、ファイルの拡張子は不要です。例:
ファイルへのパス | 参照構文 |
---|---|
Assets/Resources/Images/my-image.png |
resource("Images/my-image") |
Assets/Editor Default Resources/Images/my-image.png |
resource("Images/default-image.png") |
異なるスクリーン密度 (DPI) の画面をサポートするには、以下を行います。
@2x
というサフィックスが付いていることを確認してください。例えば、myimage.png
の高 DPI バージョンは、myimage@2x.png
としてください。Unity がアセットをロードするとき、現在のスクリーン DPI に合ったバージョンを自動的に選択します。
例えば、USS の resource("myimage")
を使用すると、Unity は Resources/myimage.png
または Resources/myimage@2x.png
のいずれかをロードします。
引用符を使用して文字列の値を指定します。例えば --my-property: "foo"
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.