- BeginArea
- BeginHorizontal
- BeginScrollView
- BeginVertical
- Box
- Button
- EndArea
- EndHorizontal
- EndScrollView
- EndVertical
- ExpandHeight
- ExpandWidth
- FlexibleSpace
- Height
- HorizontalScrollbar
- HorizontalSlider
- Label
- MaxHeight
- MaxWidth
- MinHeight
- MinWidth
- PasswordField
- RepeatButton
- SelectionGrid
- Space
- TextArea
- TextField
- Toggle
- Toolbar
- VerticalScrollbar
- VerticalSlider
- Width
- Window
GUILayout.Toggle 开关按钮
static function Toggle (value : bool, image : Texture, params options : GUILayoutOption[]) : bool
static function Toggle (value : bool, text : string, params options : GUILayoutOption[]) : bool
static function Toggle (value : bool, content : GUIContent, params options : GUILayoutOption[]) : bool
static function Toggle (value : bool, image : Texture, style : GUIStyle, params options : GUILayoutOption[]) : bool
static function Toggle (value : bool, text : string, style : GUIStyle, params options : GUILayoutOption[]) : bool
static function Toggle (value : bool, content : GUIContent, style : GUIStyle, params options : GUILayoutOption[]) : bool
Parameters参数
-
valueIs the button on or off?
这个按钮时打开还是关闭的? -
textText to display on the button.
显示在按钮上的文本。 -
imageTexture to display on the button.
显示在按钮上的纹理 -
contentText, image and tooltip for this button.
用于这个按钮的文本、图片和工具提示。 -
styleThe style to use. If left out, the button style from the current GUISkin is used.
使用的样式。如果不使用,该开关按钮使用当前的GUISkin皮肤 -
optionsAn optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style.
布局选项指定额外布局属性的一个可选列表。这里传递任意值都将覆盖由style定义的设置。
参考: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight
bool - The new value of the button.
返回布尔类型,该按钮的新值。
Description描述
Make an on/off toggle button.
创建一个开关按钮。类似于单选按钮。
Toggle button in the Game View.
在游戏视图中的开关按钮
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Texture aTexture;
private bool toggleTxt = false;
private bool toggleImg = false;
void OnGUI() {
if (!typeof(aTexture)) {
Debug.LogError("Please assign a texture in the inspector.");
return;
}
toggleTxt = GUILayout.Toggle(toggleTxt, "A Toggle text");
toggleImg = GUILayout.Toggle(toggleImg, aTexture);
}
}
// Draws 2 toggle controls, one with a text, the other with an image.
//绘制2个开关控件,一个带有文本,一个带有图像
var aTexture : Texture;
private var toggleTxt : boolean = false;
private var toggleImg : boolean = false;
function OnGUI () {
if(!aTexture) {
Debug.LogError("Please assign a texture in the inspector.");
return;
}
toggleTxt = GUILayout.Toggle(toggleTxt, "A Toggle text");
toggleImg = GUILayout.Toggle(toggleImg, aTexture);
}