文档

Unity Engine

Unity Engine

Toggle

Makes a toggle.
阅读时间4 分钟最后更新于 1 个月前

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor

Toggle(Rect, bool)

Makes a toggle.
public static bool Toggle(Rect position, bool value)

Parameters

position

Rectangle on the screen to use for the toggle.

value

The shown state of the toggle.

Returns

Type

Description

boolThe selected state of the toggle.

Remarks

EditorGUIToggle (Toggle)
Toggle control in an Editor Window.

Examples

// Use a toggle button to show/hide a button that can close the window.using UnityEngine;using UnityEditor;class EditorGUIToggle : EditorWindow{ bool showClose = true; [MenuItem("Examples/EditorGUI Toggle usage")] static void Init() { EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window"); window.Show(); } void OnGUI() { showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20), "Show Close Button", showClose); if (showClose) if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!")) this.Close(); }}

Toggle(Rect, string, bool)

Makes a toggle.
public static bool Toggle(Rect position, string label, bool value)

Parameters

position

Rectangle on the screen to use for the toggle.

label

Optional label in front of the toggle.

value

The shown state of the toggle.

Returns

Type

Description

boolThe selected state of the toggle.

Remarks

EditorGUIToggle (Toggle)
Toggle control in an Editor Window.

Examples

// Use a toggle button to show/hide a button that can close the window.using UnityEngine;using UnityEditor;class EditorGUIToggle : EditorWindow{ bool showClose = true; [MenuItem("Examples/EditorGUI Toggle usage")] static void Init() { EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window"); window.Show(); } void OnGUI() { showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20), "Show Close Button", showClose); if (showClose) if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!")) this.Close(); }}

Toggle(Rect, bool, GUIStyle)

Makes a toggle.
public static bool Toggle(Rect position, bool value, GUIStyle style)

Parameters

position

Rectangle on the screen to use for the toggle.

value

The shown state of the toggle.

Optional GUIStyle.

Returns

Type

Description

boolThe selected state of the toggle.

Remarks

EditorGUIToggle (Toggle)
Toggle control in an Editor Window.

Examples

// Use a toggle button to show/hide a button that can close the window.using UnityEngine;using UnityEditor;class EditorGUIToggle : EditorWindow{ bool showClose = true; [MenuItem("Examples/EditorGUI Toggle usage")] static void Init() { EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window"); window.Show(); } void OnGUI() { showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20), "Show Close Button", showClose); if (showClose) if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!")) this.Close(); }}

Toggle(Rect, string, bool, GUIStyle)

Makes a toggle.
public static bool Toggle(Rect position, string label, bool value, GUIStyle style)

Parameters

position

Rectangle on the screen to use for the toggle.

label

Optional label in front of the toggle.

value

The shown state of the toggle.

Optional GUIStyle.

Returns

Type

Description

boolThe selected state of the toggle.

Remarks

EditorGUIToggle (Toggle)
Toggle control in an Editor Window.

Examples

// Use a toggle button to show/hide a button that can close the window.using UnityEngine;using UnityEditor;class EditorGUIToggle : EditorWindow{ bool showClose = true; [MenuItem("Examples/EditorGUI Toggle usage")] static void Init() { EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window"); window.Show(); } void OnGUI() { showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20), "Show Close Button", showClose); if (showClose) if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!")) this.Close(); }}

Toggle(Rect, GUIContent, bool)

Makes a toggle.
public static bool Toggle(Rect position, GUIContent label, bool value)

Parameters

position

Rectangle on the screen to use for the toggle.

Optional label in front of the toggle.

value

The shown state of the toggle.

Returns

Type

Description

boolThe selected state of the toggle.

Remarks

EditorGUIToggle (Toggle)
Toggle control in an Editor Window.

Examples

// Use a toggle button to show/hide a button that can close the window.using UnityEngine;using UnityEditor;class EditorGUIToggle : EditorWindow{ bool showClose = true; [MenuItem("Examples/EditorGUI Toggle usage")] static void Init() { EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window"); window.Show(); } void OnGUI() { showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20), "Show Close Button", showClose); if (showClose) if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!")) this.Close(); }}

Toggle(Rect, GUIContent, bool, GUIStyle)

Makes a toggle.
public static bool Toggle(Rect position, GUIContent label, bool value, GUIStyle style)

Parameters

position

Rectangle on the screen to use for the toggle.

Optional label in front of the toggle.

value

The shown state of the toggle.

Optional GUIStyle.

Returns

Type

Description

boolThe selected state of the toggle.

Remarks

EditorGUIToggle (Toggle)
Toggle control in an Editor Window.

Examples

// Use a toggle button to show/hide a button that can close the window.using UnityEngine;using UnityEditor;class EditorGUIToggle : EditorWindow{ bool showClose = true; [MenuItem("Examples/EditorGUI Toggle usage")] static void Init() { EditorGUIToggle window = (EditorGUIToggle)GetWindow(typeof(EditorGUIToggle), true, "My Empty Window"); window.Show(); } void OnGUI() { showClose = EditorGUI.Toggle(new Rect(0, 5, position.width, 20), "Show Close Button", showClose); if (showClose) if (GUI.Button(new Rect(0, 25, position.width, 100), "Close Window!")) this.Close(); }}