Slider, IntSlider, MinMaxSlider

示例程序
说明生成用户可拖动的滑动条

用法

SliderIntSlider 的用法一致,只需设置左右边界值。

public static float Slider(float value, float leftValue, float rightValue, params GUILayoutOption[] options);

public static float Slider(string label, float value, float leftValue, float rightValue, params GUILayoutOption[] options);

public static float Slider(GUIContent label, float value, float leftValue, float rightValue, params GUILayoutOption[] options);

MinMaxSlider 生成一个有两个滑块的滑动条,确定一个范围,所以增加了对应两个滑块的值的参数。

public static void MinMaxSlider(ref float minValue, ref float maxValue, float minLimit, float maxLimit, params GUILayoutOption[] options);

public static void MinMaxSlider(string label, ref float minValue, ref float maxValue, float minLimit, float maxLimit, params GUILayoutOption[] options);

public static void MinMaxSlider(GUIContent label, ref float minValue, ref float maxValue, float minLimit, float maxLimit, params GUILayoutOption[] options);
Parameters

参数

label

对应的标签名称。

value

滑动条当前表示的值。

minValue

滑动条当前表示的范围的最小值(左滑块对应的值)。

maxValue

滑动条当前表示的范围的最大值(右滑块对应的值)。

leftValue / MinLimit

滑动条可以表示的最小边界值。

rightValue / MaxLimit

滑动条可以表示的最大边界值。

options

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

示例

public override void OnInspectorGUI () {

		_target.FloatValue = EditorGUILayout.Slider ("Float Slider", _target.FloatValue, 5.0f, 25.0f);
	
		_target.IntValue = EditorGUILayout.IntSlider ("Int Slider", _target.IntValue, -10, 10);
	
		EditorGUILayout.MinMaxSlider ("Min Max Slider", ref _minValue, ref _maxValue, -25.0f, 25.0f);

}

需要注意, MinMaxSlider 中参数 minValuemaxValue 必须是引用。

编译结果如下: