public static bool Toggle (bool value, params GUILayoutOption[] options);
public static bool Toggle (string label, bool value, params GUILayoutOption[] options);
public static bool Toggle (GUIContent label, bool value, params GUILayoutOption[] options);
public static bool Toggle (bool value, GUIStyle style, params GUILayoutOption[] options);
public static bool Toggle (string label, bool value, GUIStyle style, params GUILayoutOption[] options);
public static bool Toggle (GUIContent label, bool value, GUIStyle style, params GUILayoutOption[] options);

Parameters

label(可选)开关前的标签。
value开关的显示状态。
style可选 GUIStyle
options一个可选的布局选项列表,用于指定额外的 布局属性。此处传递的任何值都将覆盖 style 定义的设置。


另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight

Returns

bool 开关的选中状态。

Description

创建一个开关。


Show a button if the toggle control is selected.

using UnityEngine;
using UnityEditor;

public class EditorGUILayoutToggle : UnityEditor.EditorWindow { bool showBtn = true;

[MenuItem("Examples/Editor GUILayout Toggle Usage")] static void Init() { EditorGUILayoutToggle window = (EditorGUILayoutToggle)EditorWindow.GetWindow(typeof(EditorGUILayoutToggle), true, "My Empty Window"); window.Show(); }

void OnGUI() { showBtn = EditorGUILayout.Toggle("Show Button", showBtn); if (showBtn) if (GUILayout.Button("Close")) this.Close(); } }