版本:Unity 6 (6000.0)
语言English
  • C#

ScrollViewScope

UnityEngine 中的类

/

实现于:UnityEngine.IMGUIModule

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。尽管我们无法接受所有提交,但我们确实会阅读用户提出的每个建议更改,并在适用的情况下进行更新。

关闭

提交失败

由于某些原因,您的建议更改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

描述

用于管理 BeginScrollView / EndScrollView 的可处置帮助程序类。

自动布局的滚动视图将获取其内部的所有内容并正常显示。如果内容不适合,则会显示滚动条。对 BeginScrollView 的调用必须始终与对 EndScrollView 的调用相匹配。


游戏视图中的滚动视图。

using UnityEngine;
using UnityEditor;
public class ExampleClass : MonoBehaviour
{
    // The variable to control where the scrollview 'looks' into its child elements.
    public Vector2 scrollPosition;

// The string to display inside the scrollview. 2 buttons below add & clear this string. public string longString = "This is a long-ish string";

void OnGUI() { // Begin a scroll view. All rects are calculated automatically - // it will use up any available screen space and make sure contents flow correctly. // This is kept small with the last two parameters to force scrollbars to appear. using (var scrollViewScope = new ScrollViewScope(scrollPosition, GUILayout.Width(100), GUILayout.Height(100))) { scrollPosition = scrollViewScope.scrollPosition;

// We just add a single label to go inside the scroll view. Note how the // scrollbars will work correctly with wordwrap. GUILayout.Label(longString);

// Add a button to clear the string. This is inside the scroll area, so it // will be scrolled as well. Note how the button becomes narrower to make room // for the vertical scrollbar if (GUILayout.Button("Clear")) longString = ""; }

// Now we add a button outside the scrollview - this will be shown below // the scrolling area. if (GUILayout.Button("Add More Text")) longString += "\nHere is another line"; } }

属性

handleScrollWheel此 ScrollView 是否应处理滚轮事件。(默认值:true)。
scrollPosition修改后的 scrollPosition。如示例所示,将其反馈到您传入的变量中。

构造函数

GUILayout.ScrollViewScope创建一个新的 ScrollViewScope 并开始相应的 ScrollView。