GUI Styles are a collection of custom attributes for use with IMGUI. A single GUI Style defines the appearance of a single IMGUI Control.
If you want to add style to more than one control, use a GUI Skin instead of a GUI Style. For more information about IMGUI, please read the GUI Scripting Guide.
ノート: このページでは、IMGUI システムの一部を紹介します。IMGUI は、スクリプティングのみ による UI システムです。Unity は、完全にゲームオブジェクトベースの UI システムを備えており、こちらを好むユーザーもいます。ゲームオブジェクトベースの UI システムでは、ユーザーインターフェースの要素を可視のオブジェクトとしてシーンビューで設計したり、編集したりすることができます。詳細は UI システムマニュアル を参照してください。
プロパティ | 機能 |
---|---|
Name | この特定のスタイルを参照するためのテキスト文字列。 |
Normal | デフォルト状態のコントロールの背景画像とテキスト色。 |
Hover | コントロールにマウスカーソルを合わせたときの背景画像とテキスト色。 |
Active | コントロールをクリックしたときの背景画像とテキスト色。 |
Focused | コントロールにキーボードフォーカスを合わせたときの背景画像とテキスト色。 |
On Normal | コントロールが有効な状態にあるときの背景画像とテキスト色。 |
On Hover | 有効なコントロールにマウスカーソルを合わせたときの背景画像とテキスト色。 |
On Active | 有効なコントロールをクリックしたときのプロパティ。 |
On Focused | 有効なコントロールにキーボードフォーカスを合わせたときの背景画像とテキスト色。 |
Border | コントロールの形状のスケールによって影響されない 背景 画像の各辺のピクセル数。 |
Padding | コントロールの各端からコンテンツの開始点までのスペース (単位ピクセル)。 |
Margin | このスタイルでレンダリングされる要素とその他の GUI コントロールとの間の余白。 |
Overflow | 背景画像に追加される余分のスペース。 |
Font | このスタイルですべてのテキストに使用されるフォント。 |
Image Position | 背景画像とテキストの結合のされ方。 |
Alignment | 標準のテキスト整列オプション。 |
Word Wrap | 有効にすると、コントロールの境界に達したテキストが次の行に折り返されます。 |
Text Clipping | Word Wrap が有効の場合、 コントロールの境界を超えたテキストの処理方法を選択します。 |
Overflow | コントロールの境界を超えたテキストは境界を超えても表示されます。 |
Clip | コントロールの境界を超えたテキストは非表示になります。 |
Content Offset | その他のプロパティに加え、X 軸と Y 軸に沿ってコンテンツが移動されるピクセル数。 |
X | 左/右のオフセット。 |
Y | 上/下のオフセット。 |
Fixed Width | コントロールの幅のピクセル数で、与えられたいかなる Rect() 値も無効にします。 |
Fixed Height | コントロールの高さのピクセル数で、与えられたいかなる Rect() 値も無効にします。 |
Stretch Width | 有効にすると、このスタイルを使用するコントロールが水平に引き伸ばされ、レイアウトが改善されます。 |
Stretch Height | 有効にすると、このスタイルを使用するコントロールが垂直に引き伸ばされ、レイアウトが改善されます。 |
GUIStyle は、スクリプトから宣言され、インスタンスごとに修正されます。カスタムスタイルで 1 つまたは 2–3 のコントロールを使用したい場合、スクリプトでこのスタイルを宣言し、Control 関数の引数としてそのスタイルを渡します。このようにすると、定義したスタイルでコントロールを表示できます。
まず、スクリプトで GUI スタイルを宣言する必要があります。
/* Declare a GUI Style */
var customGuiStyle : GUIStyle;
...
ゲームオブジェクトにこのスクリプトをアタッチすると、Inspector に修正可能なカスタムスタイルが表示されます。
このスタイルを特定のコントロールに対して使用させたい場合に、関数の最後の引数に、スタイルの名前を渡します。
...
function OnGUI () {
// Provide the name of the Style as the final argument to use it
GUILayout.Button ("I am a custom-styled Button", customGuiStyle);
// If you do not want to apply the Style, do not provide the name
GUILayout.Button ("I am a normal IMGUI Button without custom style");
}
For more information about using IMGUI, please read the GUI Scripting Guide.
GUIStyle
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.