GUI
- backgroundColor
- BeginGroup
- BeginScrollView
- Box
- BringWindowToBack
- BringWindowToFront
- Button
- changed
- color
- contentColor
- depth
- DragWindow
- DrawTexture
- enabled
- EndGroup
- EndScrollView
- FocusControl
- FocusWindow
- GetNameOfFocusedControl
- GUI
- HorizontalScrollbar
- HorizontalSlider
- Label
- matrix
- PasswordField
- RepeatButton
- ScrollTo
- SelectionGrid
- SetNextControlName
- skin
- TextArea
- TextField
- Toggle
- Toolbar
- tooltip
- UnfocusWindow
- VerticalScrollbar
- VerticalSlider
- Window
GUI.Toggle 开关按钮
static function Toggle (position : Rect, value : bool, text : String) : bool
static function Toggle (position : Rect, value : bool, image : Texture) : bool
static function Toggle (position : Rect, value : bool, content : GUIContent) : bool
static function Toggle (position : Rect, value : bool, text : String, style : GUIStyle) : bool
static function Toggle (position : Rect, value : bool, image : Texture, style : GUIStyle) : bool
static function Toggle (position : Rect, value : bool, content : GUIContent, style : GUIStyle) : bool
Parameters参数
- positionRectangle on the screen to use for the button.
用于按钮在屏幕上的矩形位置。 - valueIs this 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 toggle style from the current GUISkin is used.
使用样式,如果不使用,开关按钮的样式应用当前的GUISkin皮肤。
bool - The new value of the button.
返回bool类型,按钮的新值。
Description描述
Make an on/off toggle button.
创建on/off开关按钮,也就是类似通常说的单选按钮。
另见: SetNextControlName, GetNameOfFocusedControl.
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 = GUI.Toggle(new Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
toggleImg = GUI.Toggle(new Rect(10, 50, 50, 50), toggleImg, aTexture);
}
}
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 = GUI.Toggle(Rect(10, 10, 100, 30), toggleTxt, "A Toggle text");
toggleImg = GUI.Toggle(Rect(10, 50, 50, 50), toggleImg, aTexture);
}
最后修改:2011年6月14日 Tuesday 14:41