USS を使用する場合、UI コード内のビルトインの VisualElement
プロパティの値や カスタムプロパティの値を指定できます。
USS ファイルからそれらの値を読み込むことに加えて、ビルトインのプロパティ値は VisualElement
の C# プロパティを使用して C# で割り当てることができます。C# で割り当てられた値は、Unity スタイルシート (USS) から値をオーバーライドします。
カスタムプロパティ で USS を拡張することができます。カスタム USS プロパティには --
というプレフィックスが必要です。
ここでは、サポートされている型を列挙します。
UI Toolkit は長さの単位としてピクセル (px
) とパーセンテージ (%
) をサポートします。ピクセル値は絶対値ですが、パーセンテージは通常、要素の親に相対的です。
例:
width:200px;
は、幅が 200 ピクセルであることを表します。width:50%;
は、幅が親要素の半分であることを表しています。It is important to specify the unit of measurement. If you do not specify a unit of measurement, UI Toolkit assumes that the property value is expressed in pixels.
注意: 0
は、測定単位を必要としない特別な値です。
数値は、浮動小数点数または整数リテラルで表されます。例えば、flex:1.0
です。
一部のビルトインプロパティでは、特定のキーワードがサポートされています。キーワードは、数字ではなく説明的な名前を提供します。例えば、position:absolute
です。すべてのプロパティは、プロパティをデフォルト値にリセットする initial
グローバルキーワードをサポートします。キーワードのリストについては、サポートされているプロパティ を参照してください。
UI Toolkit は、以下のリテラルの色の値と関数をサポートします。
#FFFF00
(rgba はチャンネルごとに 1 バイト)、#0F0
(rgb)rgb(255, 255, 0)
rgba(255, 255, 0, 1.0)
blue
、transparent
resource()
や url()
関数を使ってアセットを参照することができます。例えば background-image: resource("Images/img.png")
を指定すると Images
ディレクトリの img.png
を背景画像として指定できます。参照されたアセットはインポート中に解決されます。
resource()
関数は Resources
フォルダーか Editor Default Resources
フォルダー下のファイルを受け取ります。以下の注意点があります。
Resources
フォルダー下にある場合は、ファイル拡張子を入れないでください。例えば background-image: resource("Images/my-image")
。Editor Default Resources
下にある場合は、ファイル拡張子を入れる必要があります。例えば background-image: resource("Images/default-image.png")
。さらに、テクスチャをロードするとき、resource()
は高 DPI/Retina 画面を処理するための便利な方法を提供します。同じファイル名と @2x
サフィックスを持つテクスチャが同じ場所に存在する場合、Unity は画面の DPI に応じて自動的にそれをロードします。
例えば、USS で resource("myimage")
を使用する場合、Unity は Resources/myimage.png か Resources/myimage@2x.png のいずれかをロードします。
url()
関数は、ファイルパスがプロジェクトルートへの相対パス、または USS ファイルを含むフォルダーのいずれかへの相対パスであると想定します。ファイル拡張子を含む必要があります。以下の例では、USS ファイルは Assets\Editor\USS にあり、 thumb.png 背景画像は Assets\Editor\Resources にあります。
url("../Resources/thumb.png");
url("/Assets/Editor/Resources/thumb.png");
url("project:/Assets/Editor/Resources/thumb.png");
url("project:///Assets/Editor/Resources/thumb.png");
例えば background-image: url("Images/my-image.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.