Toggle, ToggleLeft

示例程序
说明生成一个开关

用法

二者用法基本一致,除了 ToggleLeft 必须要有参数 label 指定标签, Toggle 可以没有该参数。

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

参数

label

对应的标签名称。

value

开关的状态。

style

(可选)由 GUIStyle 类型定义的 GUI 样式。

options

(可选)用于指定额外的布局属性,该参数将覆盖默认样式。

示例

public override void OnInspectorGUI () {
		_target.ToggleRight = EditorGUILayout.Toggle ("Toggle Right", _target.ToggleRight);
		_target.ToggleLeft = EditorGUILayout.ToggleLeft ("Toggle Left", _target.ToggleLeft);
}

编译后如下: