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

Parameters

label显示在开关旁的标签。
value要编辑的值。
labelStyle(可选)用于标签的 GUIStyle
options一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。
另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight

Description

创建一个开关字段,其中开关位于左侧,标签紧随其右。

EditorGUILayout.ToggleLeftGUILayout.Toggle 类似,但 遵循 EditorGUI.showMixedValue 属性并处理与其他编辑器控件一致的 键盘焦点。EditorGUILayout.ToggleLeft 会使 标签靠近开关左侧。(EditorGUILayout.Toggle 会使 标签位于距离开关一段距离的相对一侧,即靠近开关右侧。)


Show a button if the toggle control is selected.

// Creates a new menu in the Editor called "Examples" with a new menu item called "ToggleLeft example"

using UnityEngine; using UnityEditor;

public class Example : EditorWindow { bool showBtn = true;

[MenuItem("Examples/ToggleLeft example")] static void Init() { Example window = (Example)EditorWindow.GetWindow(typeof(Example), true, "ToggleLeft example"); window.Show(); }

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