GUI.BeginScrollView 开始滚动视图

static function BeginScrollView (position : Rect, scrollPosition : Vector2, viewRect : Rect) : Vector2
static function BeginScrollView (position : Rect, scrollPosition : Vector2, viewRect : Rect, alwaysShowHorizontal : bool, alwaysShowVertical : bool) : Vector2
static function BeginScrollView (position : Rect, scrollPosition : Vector2, viewRect : Rect, horizontalScrollbar : GUIStyle, verticalScrollbar : GUIStyle) : Vector2
static function BeginScrollView (position : Rect, scrollPosition : Vector2, viewRect : Rect, alwaysShowHorizontal : bool, alwaysShowVertical : bool, horizontalScrollbar : GUIStyle, verticalScrollbar : GUIStyle) : Vector2

Parameters参数

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.

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

using UnityEngine;
using System.Collections;

public class example : 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();
	}
}
//定义默认的滚动条位置为0,0
var scrollPosition : Vector2 = Vector2.zero;

function OnGUI () {
	//我们创建一个100,100的滚动视图,滚动内容为220,200,就是我们要查看的内容比滚动视图大
	scrollPosition = GUI.BeginScrollView (Rect (10,300,100,100),scrollPosition, Rect (0, 0, 220, 200));

	// 我们创建一个100,100的滚动视图,滚动内容为220,200,就是我们要查看的内容比滚动视图大
	// 返回值赋回给我们定义的变量
	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");

	// 结束滚动视图
	GUI.EndScrollView ();
}
Page last updated: 2011-1-14