Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Toggle

Makes a toggle.
Read time 4 minutesLast updated 6 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule

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(); }}