ScrollViewScope

class in UnityEditor

切换到手册

描述

用于管理 BeginScrollView/EndScrollView 的可处置的 Helper 类。

这些方法的运行方式与 GUILayout.ScrollViewScope 一样,但感觉更像应用程序,且应在编辑器中使用


Label inside a scroll view.

using UnityEngine;
using UnityEditor;

// Simple Editor Window that creates a scroll view with a Label inside class BeginEndScrollView : EditorWindow { Vector2 scrollPos; string t = "This is a string inside a Scroll view!";

[MenuItem("Examples/Write text on ScrollView")] static void Init() { var window = GetWindow<BeginEndScrollView>(); window.Show(); }

void OnGUI() { using (var h = new EditorGUILayout.HorizontalScope()) { using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPos, GUILayout.Width(100), GUILayout.Height(100))) { scrollPos = scrollView.scrollPosition; GUILayout.Label(t); } if (GUILayout.Button("Add More Text", GUILayout.Width(100), GUILayout.Height(100))) t += " \nAnd this is more text!"; } if (GUILayout.Button("Clear")) t = ""; } }

变量

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

构造函数

EditorGUILayout.ScrollViewScope创建一个新的 ScrollViewScope 并开始相应的滚动视图。