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圖形用戶界面。一個(gè)獨(dú)立的圖形用戶界面樣式定義了一個(gè)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.
如果你想要添加樣式給多于一個(gè)控件,請(qǐng)使用圖形用戶界面皮膚來(lái)代替圖形用戶界面樣式,獲取更多關(guān)于Unity圖形用戶界面的信息,請(qǐng)參閱圖形用戶界面腳本指南。
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
當(dāng)控件處于默認(rèn)狀態(tài)時(shí)的背景圖像和文本顏色
-
Hover 鼠標(biāo)懸停
Background image & Text Color when the mouse is positioned over the Control
當(dāng)鼠標(biāo)位置處于此控件之上時(shí)的背景圖像和文本顏色
-
Active 激活狀態(tài)
Background image & Text Color when the mouse is actively clicking the Control
當(dāng)鼠標(biāo)點(diǎn)擊這個(gè)控件時(shí)的背景圖像和文本顏色
-
Focused 獲取焦點(diǎn)
Background image & Text Color when the Control has keyboard focus
當(dāng)控件獲取鍵盤焦點(diǎn)時(shí)的背景圖像和文本顏色
-
On Normal 可用狀態(tài)
Background image & Text Color of the Control in enabled state
當(dāng)控件處于可用狀態(tài)時(shí)的背景圖像和文本顏色
-
On Hover 可用懸停
Background image & Text Color when the mouse is positioned over the enabled Control
當(dāng)控件處于可用狀態(tài)且鼠標(biāo)位于此控件之上時(shí)的背景圖像和文本顏色。
-
On Active 可用激活
Properties when the mouse is actively clicking the enabled Control
當(dāng)控件可用且鼠標(biāo)點(diǎn)擊時(shí)的屬性
-
On Focused 可用并獲取焦點(diǎn)
Background image & Text Color when the enabled Control has keyboard focus
當(dāng)控件可用且獲取鍵盤焦點(diǎn)時(shí)的背景圖像和文本顏色
Border 邊框
Number of pixels on each side of the Background image that are not affected by the scale of the Control' shape
控件區(qū)域的背景圖像中每個(gè)邊不受縮放影響的像素?cái)?shù)值。
-
Padding 填充
Space in pixels from each edge of the Control to the start of its contents.
控件的內(nèi)容起始位置與各個(gè)邊緣之間的空白像素空間。
-
Margin 邊界
The margins between elements rendered in this style and any other GUI Controls.
在這個(gè)使用這個(gè)樣式渲染的元素中和其他圖形用戶界面控件之間的邊界
-
Overflow 溢出
Extra space to be added to the background image.
添加到背景圖片的額外空間。
-
Font 字體
The Font used for all text in this style
這個(gè)樣式中的所有文本都將使用這個(gè)字體
-
Image Position 圖像位置
The way the background image and text are combined.
背景圖像和文本的組合方式
-
Alignment 對(duì)齊
Standard text alignment options. 標(biāo)準(zhǔn)文本定位選項(xiàng)
Word Wrap 自動(dòng)換行
If enabled, text that reaches the boundaries of the Control will wrap around to the next line
如果啟用,文本打到控件邊緣時(shí)會(huì)自動(dòng)轉(zhuǎn)到下一行顯示。
Text Clipping 文本裁剪
If Word Wrap is enabled, choose how to handle text that exceeds the boundaries of the Control
如果自動(dòng)換行啟用,選擇對(duì)超出控件的文本怎樣處理。
Overflow 溢出
Any text that exceeds the Control boundaries will continue beyond the boundaries
文本超出控件邊界時(shí)將會(huì)越界顯示
Clip 裁切
Any text that exceeds the Control boundaries will be hidden
當(dāng)文本超出控件邊緣時(shí)將會(huì)隱藏
-
Content Offset 內(nèi)容偏移
Number of pixels along X and Y axes that the Content will be displaced in addition to all other properties
properties 內(nèi)容沿X軸和Y軸的內(nèi)容偏移像素量
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
控件的寬度,將會(huì)覆蓋所提供的Rect()值
Fixed Height 固定高度
Number of pixels for the height of the Control, which will override any provided Rect() value
控件的高度,將會(huì)覆蓋所提供的Rect()值
-
Stretch Width 拉伸寬度
If enabled, Controls using this style can be stretched horizontally for a better layout.
如果啟用,控件使用這個(gè)樣式會(huì)擁有更好的水平方向伸展
-
Stretch Height 拉伸高度
If enabled, Controls using this style can be stretched vertically for a better layout.
如果啟用,控件使用這個(gè)樣式會(huì)擁有更好的垂直方向伸展
Details 詳細(xì)
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.
圖形用戶界面樣式通過(guò)腳本聲明然后在每個(gè)實(shí)例的基礎(chǔ)上進(jìn)行修改,如果你想要使用一個(gè)或少量的自定義樣式的控件。你可以在腳本中聲明這個(gè)自定義樣式然后以參數(shù)的形式傳遞給控件方法,這將會(huì)使這些控件顯示你所定義的樣式。
First, you must declare a GUI Style from within a script.
首先,你必須用腳本聲明一個(gè)圖形用戶界面樣式
/* Declare a GUI Style */
/*聲明一個(gè)圖形用戶界面樣式*/
var customGuiStyle : GUIStyle;
...
When you attach this script to a GameObject, you will see the custom Style available to modify in the Inspector.
當(dāng)你將這個(gè)腳本附加到游戲?qū)ο,你將?huì)發(fā)現(xiàn)你可以在監(jiān)視窗中修改它。
A Style declared in a script can be modified in each instance of the script
一個(gè)通過(guò)腳本聲明的樣式可以在監(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)在,當(dāng)你想讓一個(gè)指定的控件使用此樣式,你可以傳遞樣式的名字給控件方法的最后一個(gè)參數(shù)。
...
function OnGUI () {
// Provide the name of the Style as the final argument to use it
//將樣式的名字傳遞到最后一個(gè)參數(shù)來(lái)使用它
GUILayout.Button ("I am a custom-styled Button", customGuiStyle);
// If you do not want to apply the Style, do not provide the name
//如果你不想應(yīng)用這個(gè)樣式就不要傳遞樣式名。
GUILayout.Button ("I am a normal UnityGUI Button without custom style");
}
Two Buttons, one with Style, as created by the code example
兩個(gè)按鈕,一個(gè)帶有上例中所創(chuàng)建的樣式。
For more information about using UnityGUI, please read the GUI Scripting Guide.
如需更多關(guān)于使用Unigy圖形用戶界面的信息,請(qǐng)參閱圖形用戶界面指南。