GUI Styles are a collection of custom attributes for use with UnityGUI. A single GUI Style defines the appearance of a single UnityGUI Control.
圖形用戶界面樣式是一組自定義屬性用于Unity圖形用戶界面。一個獨立的圖形用戶界面樣式定義了一個Unity圖形用戶界面組件的樣式。

A GUI Style in the Inspector 監(jiān)視窗中的圖形用戶界面樣式
If you want to add style to more than one control, use a GUI Skin instead of a GUI Style. For more information about UnityGUI, please read the GUI Scripting Guide.
如果你想要添加樣式給多于一個控件,請使用圖形用戶界面皮膚來代替圖形用戶界面樣式,獲取更多關于Unity圖形用戶界面的信息,請參閱圖形用戶界面腳本指南。
Properties 屬性
-
Name 名稱
The text string that can be used to refer to this specific Style
這串文本可以用于找到指定的樣式
-
Normal 正常狀態(tài)
Background image & Text Color of the Control in default state
當控件處于默認狀態(tài)時的背景圖像和文本顏色
-
Hover 鼠標懸停
Background image & Text Color when the mouse is positioned over the Control
當鼠標位置處于此控件之上時的背景圖像和文本顏色
-
Active 激活狀態(tài)
Background image & Text Color when the mouse is actively clicking the Control
當鼠標點擊這個控件時的背景圖像和文本顏色
-
Focused 獲取焦點
Background image & Text Color when the Control has keyboard focus
當控件獲取鍵盤焦點時的背景圖像和文本顏色
-
On Normal 可用狀態(tài)
Background image & Text Color of the Control in enabled state
當控件處于可用狀態(tài)時的背景圖像和文本顏色
-
On Hover 可用懸停
Background image & Text Color when the mouse is positioned over the enabled Control
當控件處于可用狀態(tài)且鼠標位于此控件之上時的背景圖像和文本顏色。
-
On Active 可用激活
Properties when the mouse is actively clicking the enabled Control
當控件可用且鼠標點擊時的屬性
-
On Focused 可用并獲取焦點
Background image & Text Color when the enabled Control has keyboard focus
當控件可用且獲取鍵盤焦點時的背景圖像和文本顏色
Border 邊框
Number of pixels on each side of the Background image that are not affected by the scale of the Control' shape
控件區(qū)域的背景圖像中每個邊不受縮放影響的像素數(shù)值。
-
Padding 填充
Space in pixels from each edge of the Control to the start of its contents.
控件的內容起始位置與各個邊緣之間的空白像素空間。
-
Margin 邊界
The margins between elements rendered in this style and any other GUI Controls.
在這個使用這個樣式渲染的元素中和其他圖形用戶界面控件之間的邊界
-
Overflow 溢出
Extra space to be added to the background image.
添加到背景圖片的額外空間。
-
Font 字體
The Font used for all text in this style
這個樣式中的所有文本都將使用這個字體
-
Image Position 圖像位置
The way the background image and text are combined.
背景圖像和文本的組合方式
-
Alignment 對齊
Standard text alignment options. 標準文本定位選項
Word Wrap 自動換行
If enabled, text that reaches the boundaries of the Control will wrap around to the next line
如果啟用,文本打到控件邊緣時會自動轉到下一行顯示。
Text Clipping 文本裁剪
If Word Wrap is enabled, choose how to handle text that exceeds the boundaries of the Control
如果自動換行啟用,選擇對超出控件的文本怎樣處理。
Overflow 溢出
Any text that exceeds the Control boundaries will continue beyond the boundaries
文本超出控件邊界時將會越界顯示
Clip 裁切
Any text that exceeds the Control boundaries will be hidden
當文本超出控件邊緣時將會隱藏
-
Content Offset 內容偏移
Number of pixels along X and Y axes that the Content will be displaced in addition to all other properties
properties 內容沿X軸和Y軸的內容偏移像素量
X
Left/Right Offset 左右偏移
Y
Up/Down Offset 上下偏移
-
Fixed Width 固定寬度
Number of pixels for the width of the Control, which will override any provided Rect() value
控件的寬度,將會覆蓋所提供的Rect()值
Fixed Height 固定高度
Number of pixels for the height of the Control, which will override any provided Rect() value
控件的高度,將會覆蓋所提供的Rect()值
-
Stretch Width 拉伸寬度
If enabled, Controls using this style can be stretched horizontally for a better layout.
如果啟用,控件使用這個樣式會擁有更好的水平方向伸展
-
Stretch Height 拉伸高度
If enabled, Controls using this style can be stretched vertically for a better layout.
如果啟用,控件使用這個樣式會擁有更好的垂直方向伸展
Details 詳細
GUIStyles are declared from scripts and modified on a per-instance basis. If you want to use a single or few Controls with a custom Style, you can declare this custom Style in the script and provide the Style as an argument of the Control function. This will make these Controls appear with the Style that you define.
圖形用戶界面樣式通過腳本聲明然后在每個實例的基礎上進行修改,如果你想要使用一個或少量的自定義樣式的控件。你可以在腳本中聲明這個自定義樣式然后以參數(shù)的形式傳遞給控件方法,這將會使這些控件顯示你所定義的樣式。
First, you must declare a GUI Style from within a script.
首先,你必須用腳本聲明一個圖形用戶界面樣式
/* Declare a GUI Style */
/*聲明一個圖形用戶界面樣式*/
var customGuiStyle : GUIStyle;
...
When you attach this script to a GameObject, you will see the custom Style available to modify in the Inspector.
當你將這個腳本附加到游戲對象,你將會發(fā)現(xiàn)你可以在監(jiān)視窗中修改它。

A Style declared in a script can be modified in each instance of the script
一個通過腳本聲明的樣式可以在監(jiān)視窗中修改它的屬性。
Now, when you want to tell a particular Control to use this Style, you provide the name of the Style as the last argument in the Control function.
現(xiàn)在,當你想讓一個指定的控件使用此樣式,你可以傳遞樣式的名字給控件方法的最后一個參數(shù)。
...
function OnGUI () {
// Provide the name of the Style as the final argument to use it
//將樣式的名字傳遞到最后一個參數(shù)來使用它
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 UnityGUI Button without custom style");
}

Two Buttons, one with Style, as created by the code example
兩個按鈕,一個帶有上例中所創(chuàng)建的樣式。
For more information about using UnityGUI, please read the GUI Scripting Guide.
如需更多關于使用Unigy圖形用戶界面的信息,請參閱圖形用戶界面指南。