position | 屏幕上用于滑动条的矩形。 |
label | (可选)滑动条前的标签。 |
minValue | 滑动条显示的范围内的下限值,按引用传递。 |
maxValue | 滑动条显示的范围内的上限值,按引用传递。 |
minLimit | 滑动条左端的限值。 |
maxLimit | 滑动条右端的限值。 |
Makes a special slider the user can use to specify a range between a min and a max.
MinMax Slider in an Editor Window.
using UnityEngine; using UnityEditor;
// Place the selected object randomly between the interval of the Min Max Slider // in the X,Y,Z coords
class EditorGUIMinMaxSlider : EditorWindow { float minVal = -10; float minLimit = -20; float maxVal = 10; float maxLimit = 20;
[MenuItem("Examples/Editor GUI Move Object Randomly")] static void Init() { var window = GetWindow<EditorGUIMinMaxSlider>(); window.Show(); }
void OnGUI() { EditorGUI.MinMaxSlider( new Rect(0, 0, position.width, 20), new GUIContent("Random range:"), ref minVal, ref maxVal, minLimit, maxLimit); if (GUI.Button(new Rect(0, 25, position.width, position.height - 25), "Randomize!")) { 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."); } } }