返回介绍

GUI.BeginScrollView 开始滚动视图

发布于 2019-12-18 15:37:44 字数 6694 浏览 1686 评论 0 收藏 0

JavaScript => public static function BeginScrollView(position: Rect, scrollPosition: Vector2, viewRect: Rect): Vector2;
JavaScript => public static function BeginScrollView(position: Rect, scrollPosition: Vector2, viewRect: Rect, alwaysShowHorizontal: bool, alwaysShowVertical: bool): Vector2;
JavaScript => public static function BeginScrollView(position: Rect, scrollPosition: Vector2, viewRect: Rect, horizontalScrollbar: GUIStyle, verticalScrollbar: GUIStyle): Vector2;
JavaScript => public static function BeginScrollView(position: Rect, scrollPosition: Vector2, viewRect: Rect, alwaysShowHorizontal: bool, alwaysShowVertical: bool, horizontalScrollbar: GUIStyle, verticalScrollbar: GUIStyle): Vector2;

C# => public static Vector2 BeginScrollView(Rect position, Vector2 scrollPosition, Rect viewRect);
C# => public static Vector2 BeginScrollView(Rect position, Vector2 scrollPosition, Rect viewRect, bool alwaysShowHorizontal, bool alwaysShowVertical);
C# => public static Vector2 BeginScrollView(Rect position, Vector2 scrollPosition, Rect viewRect, GUIStyle b, GUIStyle verticalScrollbar);
C# => public static Vector2 BeginScrollView(Rect position, Vector2 scrollPosition, Rect viewRect, bool alwaysShowHorizontal, bool alwaysShowVertical, GUIStyle horizontalScrollbar, GUIStyle verticalScrollbar);

Parameters 参数

positionRectangle on the screen to use for the ScrollView.
用于滚动视图在屏幕上矩形的位置
scrollPositionThe pixel distance that the view is scrolled in the X and Y directions.
用来显示滚动位置
viewRectThe rectangle used inside the scrollview.
滚动视图内使用的矩形
horizontalScrollbarOptional GUIStyle to use for the horizontal scrollbar. If left out, the horizontalScrollbar style from the current GUISkin is used.
用于水平滚动条的可选GUIStyle,如果不设置,水平滚动条样式应用当前的GUISkin皮肤。
verticalScrollbarOptional GUIStyle to use for the vertical scrollbar. If left out, the verticalScrollbar style from the current GUISkin is used.
用于垂直滚动条的可选GUIStyle,如果不设置,垂直滚动条样式应用当前的GUISkin皮肤。
alwaysShowHorizontalOptional parameter to always show the horizontal scrollbar. If false or left out, it is only shown when viewRect is wider than position.
可选参数,总是显示水平滚动条,如果false或者不设置,它仅在内矩形比外矩形大的时候显示。
alwaysShowVerticalOptional parameter to always show the vertical scrollbar. If false or left out, it is only shown when viewRect is taller than position.
可选参数,总是显示垂直滚动条,如果false或者不设置,它仅在内矩形比外矩形大的时候显示。

Returns 返回

Vector2 The modified scrollPosition. Feed this back into the variable you pass in, as shown in the example.

返回Vector2类型,被修改的滚动位置scrollPosition。返回值应回传给你的变量,看下面的例子。

Description 描述

Begin a scrolling view inside your GUI.

在你的GUI里,开始一个滚动视图, 注意BeginScrollView和EndScrollView它们是成对出现的。

ScrollViews let you make a smaller area on-screen look 'into' a much larger area, using scrollbars placed on the sides of the ScrollView.

滚动视图让你在屏幕上一个小的区域,使用滚动是视图的滚动条查看一个大的区域。

JavaScript:

// The position on of the scrolling viewport
	var scrollPosition : Vector2 = Vector2.zero;
 
	function OnGUI () {
		// An absolute-positioned example: We make a scrollview that has a really large client
		// rect and put it in a small rect on the screen.
		scrollPosition = GUI.BeginScrollView (Rect (10,300,100,100),
			scrollPosition, Rect (0, 0, 220, 200));
 
		// Make four buttons - one in each corner. The coordinate system is defined
		// by the last parameter to BeginScrollView.
		GUI.Button (Rect (0,0,100,20), "Top-left");
		GUI.Button (Rect (120,0,100,20), "Top-right");
		GUI.Button (Rect (0,180,100,20), "Bottom-left");
		GUI.Button (Rect (120,180,100,20), "Bottom-right");
 
		// End the scroll view that we began above.
		GUI.EndScrollView ();
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Vector2 scrollPosition = Vector2.zero;
    void OnGUI() {
        scrollPosition = GUI.BeginScrollView(new Rect(10, 300, 100, 100), scrollPosition, new Rect(0, 0, 220, 200));
        GUI.Button(new Rect(0, 0, 100, 20), "Top-left");
        GUI.Button(new Rect(120, 0, 100, 20), "Top-right");
        GUI.Button(new Rect(0, 180, 100, 20), "Bottom-left");
        GUI.Button(new Rect(120, 180, 100, 20), "Bottom-right");
        GUI.EndScrollView();
    }
}

gui

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文