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

参数

label(可选)滑动条前的标签。
minValue滑动条显示的范围内的下限值,按引用传递。
maxValue滑动条显示的范围内的上限值,按引用传递。
minLimit滑动条左端的限值。
maxLimit滑动条右端的限值。
options一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。
另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight

描述

创建一个特殊滑动条,用户可利用该滑动条指定最小值和最大值之间的一个范围。

\ 在间隔内随机移动所选对象。

// Place the selected object randomly between the interval of the Min Max Slider
// in the X,Y,Z coords

using UnityEditor; using UnityEngine;

public class ExampleClass : EditorWindow { float minVal = -10; float minLimit = -20; float maxVal = 10; float maxLimit = 20;

[MenuItem("Examples/Place Object Randomly")] static void Init() { ExampleClass window = (ExampleClass)GetWindow(typeof(ExampleClass)); window.Show(); }

void OnGUI() { EditorGUILayout.LabelField("Min Val:", minVal.ToString()); EditorGUILayout.LabelField("Max Val:", maxVal.ToString()); EditorGUILayout.MinMaxSlider(ref minVal, ref maxVal, minLimit, maxLimit); if (GUILayout.Button("Move!")) PlaceRandomly(); }

void PlaceRandomly() { if (Selection.activeTransform) Selection.activeTransform.position = new Vector3(Random.Range(minVal, maxVal), Random.Range(minVal, maxVal), Random.Range(minVal, maxVal)); else Debug.LogError("Select a GameObject to randomize its position."); } }