label | (可选)滑动条前的标签。 |
minValue | 滑动条显示的范围内的下限值,按引用传递。 |
maxValue | 滑动条显示的范围内的上限值,按引用传递。 |
minLimit | 滑动条左端的限值。 |
maxLimit | 滑动条右端的限值。 |
options | 一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。另请参阅:GUILayout.Width、GUILayout.Height、GUILayout.MinWidth、GUILayout.MaxWidth、GUILayout.MinHeight、 GUILayout.MaxHeight、GUILayout.ExpandWidth、GUILayout.ExpandHeight。 |
创建一个特殊滑动条,用户可利用该滑动条指定最小值和最大值之间的一个范围。
Moves the selected object randomly betweeen the interval.
// 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.");
}
}