Version: 2020.2

GUI.VerticalScrollbar

切换到手册
public static float VerticalScrollbar (Rect position, float value, float size, float topValue, float bottomValue);
public static float VerticalScrollbar (Rect position, float value, float size, float topValue, float bottomValue, GUIStyle style);

参数

position 屏幕上用于滚动条的矩形。
value 最小值和最大值之间的位置。
size 我们能看到多少内容?
topValue 滚动条顶部的值。
bottomValue 滚动条底部的值。
style 用于滚动条背景的样式。如果省略,则使用当前 GUISkinhorizontalScrollbar 样式。

返回

float 修改后的值。用户可以通过拖动滚动条或单击末端的箭头来更改该值。

描述

创建一个垂直滚动条。滚动条是用于滚动文档的控件。大多数情况下,您需要的可能是滚动视图。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float vSbarValue;

void OnGUI() { vSbarValue = GUI.VerticalScrollbar(new Rect(25, 25, 100, 30), vSbarValue, 1.0F, 10.0F, 0.0F); } }

搜寻额外的元素:

系统按以下方式在当前皮肤中搜寻滚动条的样式:1) 对于滚动条末端的按钮,向样式名称添加“upbutton”和“downbutton”; 2) 对于滚动条滑块(鼠标拖动的条),向样式名称添加“thumb”。

// This will use the following style names to determine the size / placement of the buttons
// MyVertScrollbarupbutton   - Name of style used for the up button.
// MyVertScrollbardownbutton - Name of style used for the down button.
// MyVertScrollbarthumb      - Name of style used for the draggable thumb.

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { public float scrollPos = 0.5f;

void OnGUI() { scrollPos = GUI.VerticalScrollbar(new Rect(0, 0, 100, 20), scrollPos, 1, 0, 100, "Scroll"); } }