查看: 1626|回复: 0
打印 上一主题 下一主题

Unity3D脚本中文教程2.16

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2012-5-18 15:33:43 |只看该作者 |倒序浏览
GUILayout类





GUILayout是用于UnityGUI自动布局的类。

参见:GUI Layout tutoria

类方法

◆ static function BeginArea(screenRect : Rect) : void

◆ static function BeginArea(screenRect : rect, text : string) : void

◆ static function BeginArea(screenRect : Rect, image : Texture) : void

◆ static function BeginArea(screenRect : Rect, content : GUIContent) : void

◆ static function BeginArea(screenRect : Rect, style : GUIStyle) : void

◆ static function BeginArea(screenRect : Rect, text : string, style : GUIStyle) : void

◆ static function BeginArea(screenRect : Rect, image : Texture, style : GUIStyle) : void

◆ static function BeginArea(screenRect : Rect, content : GUIContent, style : GUIStyle) : void

参数

text可选的显示在该区域中的文本

image  可选的显示在该区域中的纹理

content  可选的在该区域顶部显示的文本,图片和提示

style  使用的风格。如果留空,空的GUIStyle(GUIStyle.none)将被使用,给出一个透明的背景。参见:EndArea

描述:在屏幕的固定区域开始一个GUI空间的GUILayout块。

默认的,任何使用GUILayout制作的GUI空间都放置在屏幕的左上角。如果你想在任一区域放置一系列自动布局的控件,使用GUILayout.BeginArea定义一个新的区域以便自动布局系统可以使用它。

function OnGUI()

{

GUILayout.BeginArea(Rect(200, 200, 100, 100));

GUILayout.Button(“Click me”);

GUILayout.Button(“Or me”);

GUILayout.EndArea();

}

在混合GUILayout代码是这个函数是非常有用的。必须与EndArea调用匹配。BeginArea / EndArea不能嵌套。

◆ static function BeginHorizontal(params options : GUILayoutOption[]): void

◆ static function BeginHorizontal(style : GUIStyle, params options : GUILayoutOption[]): void

参数

style这个风格用于背景图片和填充值。如果留空,背景是透明的。

options  一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这个设置的值将覆盖由style定义的设置。

参见:GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight

描述:开始一个水平控件组。

所有在这个元素内部渲染的空间将被一个接一个的水平放置,改组必须调用EndHorizontal关闭。
◆ static function BeginScrollView(scrollPosition : Vector2, params options : GUILayoutOption[]) : Vector2

◆ static function BeginScrollView(scrollPosition : Vector2, horizontalScrollbar : GUIStyle, verticalScrollbar : GUIStyle, params options : GUILayoutOption[]) : Vector2

◆ static function BeginScrollView(scrollPosition : Vector2, alwaysShowHorizontal : bool, alwaysShowVertical : bool, params options : GUILayoutOption[]) : Vector2

◆ static function BeginScrollView(scrollPosition : Vector2, style : GUIStyle) : Vector2

◆ static function BeginScrollView(scrollPosition : Vector2, alwaysShowHorizontal : bool, alwaysShowVertical : bool, horizontalScrollbar : GUIStyle, verticalScrollbar : GUIStyle,  params options : GUILayoutOption[]) : Vector2

◆ static function BeginScrollView(scrollPosition : Vector2, alwaysShowHorizontal : bool, alwaysShowVertical : bool, horizontalScrollbar : GUIStyle, verticalScrollbar : GUIStyle,  background : GUIStyle, params options : GUILayoutOption[]) : Vector2
参数:

scrollPostion 用来显示的位置

alwaysShowHorizontal  可选的参数用来总是显示水平滚动条。如果为假或者留空,它将只在ScrollView中的内容比滚动视宽时显示。

alwaysShowVertical 可选的参数用来总是显示垂直滚动条。如果为假或者留空,它将只在ScrollView中的内容比滚动视高时显示。

horizontalScrollbar 用于水平滚动条的可选GUIStyle。如果不设置,将使用当前GUISkin的horizontalScrollbar。

verticalScrollbar 用于垂直滚动条的可选GUIStyle。如果不设置,将使用当前GUISken的verticalScrollbar风格。

返回Vector2 – 修改过的scrollPosition。回传这个变量,如下的例子:

描述:开始一个自动布局滚动视。

自动布局滚动视,将使用任何你放置在它们中的内容并正常显示出来。如果他不适合,将显示滚动条,BeginScrollView的调用总是与EndScrollView的调用匹配。

//这个变量对于空间来说就是这个滚动视查看子元素的位置。

var scrollPosition : Vector2;

//显示在滚动视中的字符串,下面两个按钮添加,清除这个字符串。

var longString = “This is a long-ish string”;

function OnGUI()

{

//开始一个滚动视,所有矩形被自动计算。

//它将使用任何可用的空间并确保内容排列正确

//这是小的最后两参数来强制滚动条出现

scrollPosition = GUILayout.BeginScrollView(scrollPosition,  GUILayout.Width(100),  GUILayout.Height(100));

//添加一个简单的标签到滚动视内部。注意

//滚动条如何与文字换行正确的工作。

GUILayout.Height(longString);

//添加一个按钮来消除字符串。这个是在滚动区域内部,因此它

//也将被滚动。注意按钮如何变窄为垂直滚动条留出空间

if(GUILayout.Button(“Clear”)

longString = “”;

//结束我们上面开始的滚动条

GUILayout.EndScrollView();

//现在我们在滚动视外边添加一个按钮 – 这将显示在滚动区域的下边

if(GUILayout.Button(“Add MoreText”))

{

longString += “
Here is another line.”;

}

◆ static function Box(params option : GUILayoutOption[]) : void

◆ static function Box(style : GUIStyle, params option : GUILayoutOption[]) : void

参数

style 这个风格将用于背景图片和填充值,如果留空,背景是透明的。

options  一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

描述:开始一个垂直控件组。

所有在这个元素内部渲染的空间将被一个接一个地垂直放置。改组必须调用EndVertical关闭。

◆ static function Box(image : Texture, params option : GUILayoutOption[]) : void

◆ static function Box(text : string, params option : GUILayoutOption[]) : void

◆ static function Box(contend : GUIContent, params option : GUILayoutOption[]) : void

◆ static function Box(image : Texture, style : GUIStyle, params option : GUILayoutOption[]) : void

◆ static function Box(text : string, style : GUIStyle, params option : GUILayoutOption[]) : void

◆ static function Box(contend : GUIContent, style : GUIStyle, params option : GUILayoutOption[]) : void

参数

text 显示在该box上的文本

image显示在该box上的Texture

content用于这个box的文本,图形和提示

style 使用的风格。如果不设置,将使用当前的GUISkin的box风格。

options  一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

描述:制作一个自动布局box

这将制作一个实心box,如果你想制作一个包含一些内容的box,使用一个子组函数的

风格参数(BeginHorizontal, BeginVertical, 等等)

◆ static function Button(image : Texture, params options : GUILayoutOption[]) : bool

◆ static function Button(text : string, params options : GUILayoutOption[]) : bool

◆ static function Button(content : GUIContent, params options : GUILayoutOption[]) : bool

◆ static function Button(image : Texture, style : GUIStyle, params options : GUILayoutOption[]) : bool

◆ static function Button(text : string, style : GUIStyle, params options : GUILayoutOption[]) : bool

◆ static function Button(content : GUIContent, style : GUIStyle, params options : GUILayoutOption[]) : bool

参数

text 显示在该按钮上的文本

image显示在该按钮上的Texture

content用于这个按钮的文本,图形和提示。

style 使用的风格。如果不设置,将使用当前的GUISkin的button风格。

options  一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight

返回bool – ***e当用户单击按钮时。

描述:制作一个简单的按钮,用户点击它们的时候就会有事情发生。

◆ static functioin EndArea() : void

描述:关闭由BeginArea开始的GUILayout块

◆ static function EndHorizontal() : void

描述:关闭一个开始于BeginHorizontal的组

◆ static functioin EndScrollView() : void

描述:结束由BeginScrollView调用开始的滚动视。

◆ static functioin EndVertical() : void

描述:关闭一个开始于BeginVertical的组

◆ static functioin ExpandHeight(expand : bool) : GUILayoutOption

描述:传递给一个空间的选项来允许或不允许垂直扩展。

◆ static functioin ExpandWidth(expand : bool) : GUILayoutOption

描述:传递给一个空间的选项来允许或不允许水平扩展。

◆ static functioin FlexibleSpace() : void

描述:插入一个灵活的空格元素

灵活的空格用来填充一个布局中任何遗漏的空间。

◆ static functioin Height(height : float) : GUILayoutOption

描述:传递给空间的选项以便给它一个绝对高度。

◆ static functioin HorizontalScrollbar(value : float, size : float, leftValue : float, rightValue : float, params options : GUILayoutOption[]) : float

◆ static functioin HorizontalScrollbar(value : float, size : float, leftValue : float, rightValue : float, style : GUIStyle, params options : GUILayoutOption[]) : float

参数

value在min和max之间的位置

size 能看见多大?

leftValue滚动条左端的值

rightValue  滚动条右端的值

style 用于滚动条背景的风格。如果不设置,将使用当前GUISkin的horizontalScrollbar

options 一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight

返回floar – 修改后的值。这可以通过拖动这个滚动条,或者单击两端的箭头来改变。

描述:一个水平滚动条。滚动条可以用来滚动文档。大多数情况下,你会使用滚动视代替。

找到额外的元素:

在滚动条两端的按钮将在当前皮肤中搜索“leftButton”和“rightButton”作为风格,滚动条的滑块(你拖动的东西)将搜索并使用名为“thumb”的风格。

//这将使用下面的风格名来决定该按钮的尺寸/位置

//MyScrollbarleftButton - 用于左侧按钮的风格位置

//MyScrollbarrightButton - 用于右侧按钮的风格位置

//MyScrollbarthumb - 用于滑块的风格名称

scrollPos = GUILayout.HorizontalScrollbar(scrollPos, 1, 0, 100, “MyScrollbar”);

◆ static functioin HorizontalSlider(value : float, leftValue : float, rightValue : float, params options : GUILayoutOption[]) : float

◆ static functioin HorizontalSlider(value : float, leftValue : float, rightValue : float, slider : GUIStyle, thumb : GUIStyle, params options : GUILayoutOption[]) : float

参数

value滑块显示的值。这个决定可拖动滑块的位置。

leftValue滑杆左端的值。

rightValue  滑杆右边的值。

slider用于显示拖动区域的GUIStyle。如果不设置,将使用当前GUISkin的horizontalSlider。


thumb  用于显示拖动块的GUISkin。如果不设置,将使用当前的GUISkin的horizontalSliderThumb

options  一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

返回float – 被用户设置的值。

描述:一个用户可以拖动的滑杆。可以在min和max之间取一个值。

◆ static function Label(image : Texture, params options : GUILayoutOption[]) : void

◆ static function Label(text : string, params options : GUILayoutOption[]) : void

◆ static function Label(content : GUIContent, params options : GUILayoutOption[]) : void

◆ static function Label(image : Texture, style : GUIStyle, params options : GUILayoutOption[]) : void

◆ static function Label(text : string, style : GUIStyle, params options : GUILayoutOption[]) : void

◆ static function Label(content: GUIContent, style : GUIStyle, params options : GUILayoutOption[]) : void
参数

text 显示在该标签上的文本。

image显示在标签上的Texture。

content用于这个标签的文本,图形和提示。

style 使用的风格。如果不设置。将使用当前GUISkin的label。

options  一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。
参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

描述:制作一个自动布局label

标签没有用户交互。不会获取鼠标点击并总是以普通风格渲染。如果你想制作一个可视化响应用户输出的控件,使用一个Box控件。

◆ static function MaxHeight(maxHeight : float) : GUILayoutOption

描述:传递给控件的选项来指定一个最大高度。

◆ static function MaxWidth(maxWidth : float) : GUILayoutOption

描述:传递给控件的选项来指定一个最大宽度。

◆ static function MinHeight(minHeight : float) : GUILayoutOption

描述:传递给控件的选项来指定一个最小高度。

◆ static function MinWidth(minWidth : float) : GUILayoutOption

描述:传递给控件的选项,来指定一个最小宽度

◆ static function PasswordField(password : string,  maskChar : char, params options : GUILayoutOption[]) : string

◆ static function PasswordField(password : string,  maskChar : char, maxLength : int, params options : GUILayoutOption[]) : string

◆ static function PasswordField(password : string,  maskChar : char, style : GUIStyle, params options : GUILayoutOption[]) : string

◆ static function PasswordField(password : string,  maskChar : char, maxLength : int, style : GUIStyle, params options : GUILayoutOption[]) : string

参数

password 用于编辑的密码。这个函数返回值应该被赋回这个字符串。如下的例子。

maskChar 用来隐藏密码的字符。

maxLength 字符串的最大长度。如果不设置,用户可以一直输入。

style 使用的风格。如果不设置,将使用当前GUISkin的textField风格。

返回string – 编辑过的密码。

描述:制作一个用户可以输入密码的文本域。

var passwordToEdit = “My Password”;

function OnGUI()

{// 制作一个密码与来调整stringToEdit。

  passwordToEdit = GUILayout.PasswordField(passwordToEdit, “*”, 25);

}

◆ static function RepeatButton(image : Texture, params options : GUILayoutOption[]) : bool

◆ static function RepeatButton(text : string, params options : GUILayoutOption[]) : bool

◆ static function RepeatButton(content : GUIContent, params options : GUILayoutOption[]) : bool

◆ static function RepeatButton(image : Texture, style : GUIStyle, params options : GUILayoutOption[]) : bool

◆ static function RepeatButton(text : string, style : GUIStyle, params options : GUILayoutOption[]) : bool

◆ static function RepeatButton(content : GUIContent, style : GUIStyle, params options : GUILayoutOption[]) : bool

参数

text显示在该按钮上的文本。

image  显示在该按钮上的Texture。

content  用于这个按钮的文本,图形和提示。

style使用的风格,如果不设置,将使用当前GUISkin的button风格。
options  一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

返回bool - /***e/当用户按住按钮时

描述:制作一个重复按钮,只要用户按住鼠标这个按钮一直返回真。

◆ static function SeletionGrid(selected : int, texts : string[], xCount : int, params options : GUILayoutOption[]) : int

◆ static function SeletionGrid(selected : int, images : Texture[], xCount : int, params options : GUILayoutOption[]) : int

◆ static function SeletionGrid(selected : int, contents : GUIContent[], xCount : int, params options : GUILayoutOption[]) : int

◆ static function SeletionGrid(selected : int, texts : string[], xCount : int, style : GUIStyle, params options : GUILayoutOption[]) : int

◆ static function SeletionGrid(selected : int, images : Texture[], xCount : int, style : GUIStyle, params options : GUILayoutOption[]) : int

◆ static function SeletionGrid(selected : int, contents : GUIContent[], xCount : int, style : GUIStyle, params options : GUILayoutOption[]) : int

参数

selected选择按钮的索引

texts 显示在按钮的字符串数组。

images在按钮上纹理数组

contents用于按钮的文本,图形和提示。

xCount  在水平方向多少个元素,元素将被缩放来适应,除非风格定义了一个fixedWidth,空间高度将由元素的数量决定。

style 使用的风格。如果不设置,将使用当前GUISkin的button风格。

options 一个可选的布局选项的列表,它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

返回int – 选择按钮的索引

描述:制作一个选择网格

◆ static function Space(pixel : float) : void

描述:在当前布局组中插入一个空格

空格的方向依赖与使用这个命令时当前所在布局组。如果在垂直组,空格是垂直的。

function OnGUI()

{

  GUILayout.Button(“I’m the first button”);

  //在两个按钮间插入20像素

  GUILayout.Space(20);
}

  GUILayout.Button(“I’m a bit futher down”);

}

在水平组,pixels将是水平的;

function OnGUI()

{

  //开始水平组以便显示水平空格

  GUILayout.BeginHorizontal(“box”);

  GUILayout.Button(“I’m the first button”);

  //在两个按钮间插入20像素

  GUILayout.Space(20);

  GUILayout.Button(“I’m to the right”);

  //结束上面开始的水平组

  GUILayout.EndHorizontal();

}

◆ static function TextArea(text : string, params options : GUILayoutOption[]) : string

◆ static function TextArea(text : string, maxLength : int, params options : GUILayoutOption[]) : string

◆ static function TextArea(text : string, style : GUIStyle, params options : GUILayoutOption[]) : string

◆ static function TextArea(text : string, maxLength : int, style : GUIStyle, params options : GUILayoutOption[]) : string

参数

text  用于编辑的文本。这个函数返回值应该被赋回这个字符串。如下的例子。

maxLength  字符串的最大长度。如果不设置,用户可以一直输入。

style 使用的风格。如果不设置,则使用当前GUISkin的textField风格。

options 一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

返回string – 编辑过的字符串。

描述:制作一个多行文本域。这里用户可以编辑这个字符串。

◆ static function TextField(text : string, params options : GUILayoutOption[]) : string

◆ static function TextField (text : string, maxLength : int, params options : GUILayoutOption[]) : string

◆ static function TextField (text : string, style:GUIStyle, params options : GUILayoutOption[]) : string

◆ static function TextField (text : string, maxLength : int, style : GUIStyle, params options : GUILayoutOption[]) : string

参数

text  用于编辑的文本。这个函数返回值应该被赋回这个字符串,如下的例子。
maxLength  字符串的最大长度。如果不设置,用户可以一直输入。

style 使用的风格。如果不设置,将使用当前的GUISkin的textArea

options  一个可选的布局选项的列表,它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

返回string – 编辑过的字符串。

描述:制作一个单行文本域。这里用户可以编辑这个字符串。

var stringToEdit = “Hello, world”;

function OnGUI()

{

  //制作一个文本域来调整stringToEdit

  stringToEdit = GUILayout.TextField(stringToEdit, 25);

}

◆ static function Toogle(value : bool, image : Texture, params options : GUILayoutOption[]) : bool

◆ static function Toogle(value : bool, text : string, params options : GUILayoutOption[]) : bool

◆ static function Toogle(value : bool, content : GUIContent, params options : GUILayoutOption[]) : bool

◆ static function Toogle(value : bool, image : Texture, style : GUIStyle, params options : GUILayoutOption[]) : bool

◆ static function Toogle(value : bool, text : string, style : GUIStyle, params options : GUILayoutOption[]) : bool

◆ static function Toogle(value : bool, content : GUIContent, style : GUIStyle, params options : GUILayoutOption[]) : bool
参数

value按钮是打开或关闭

text 显示在该按钮上的文本

image显示在该按钮上的Texture

content用于这个按钮的文本,图形和提示

style 使用的风格。如果不设置,将使用当前GUISkin的button风格。

options  一个可选的布局选项的列表,它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

返回bool – 按钮的新值

描述:制作一个on/off开关按钮。
◆ static function Toolbar(selected: int, texts : string[], params options : GUILayoutOption[]) : int

◆ static function Toolbar(selected: int, images : Texture[], params options : GUILayoutOption[]) : int

◆ static function Toolbar(selected: int, contents: GUIContent[], params options : GUILayoutOption[]) : int

◆ static function Toolbar(selected: int, texts : string[], style : GUIStyle, params options : GUILayoutOption[]) : int

◆ static function Toolbar(selected: int, image : Texture[],style : GUIStyle, params options : GUILayoutOption[]) : int

◆ static function Toolbar(selected: int, content : GUIContent[],style : GUIStyle, params options : GUILayoutOption[]) : int

参数

selected选择按钮的索引

texts 显示在按钮上的字符串数组

images在按钮上的纹理数组

contents用于按钮的文本,图形和提示数组

style 使用的风格。如果不设置,将使用当前GUISkin的button风格。

options 一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

返回int – 选择按钮的索引

描述:制作一个工具栏

◆ static function VerticalScrollbar(value: float, size : float, topValue : float, buttomValue : float, params options : GUILayoutOption[]) : float

◆ static function VerticalScrollbar(value: float, size : float, topValue : float, buttomValue : float, style : GUIStyle, params options : GUILayoutOption[]) : float

参数

value在min和max之间的位置

size 能看见多大?

topValue滚动条顶端的值

bottomValue  滚动条底端的值

style  用于滚动条背景的风格。如果不设置,将使用当前GUISkin的horizontalScrollbar。

options 一个可选的布局选项的列表。它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

返回float – 修改后的值。这可以通过拖动这个滚动条,或者单击两端的箭头来改变。

描述:制作一个垂直滚动条。滚动条可以用来滚动文档。大多数情况下,你会使用scollView代替。

找到额外的元素:

在滚动条两端的按钮将在当前皮肤中搜索“upbutton”和“downbutton”作为风格。滚动条的滑块(你拖动的东西)将搜索并使用名为thumb的风格。

//这将使用下面的风格名来决定该按钮的尺寸/位置

//MyVerticalScrollb***pbutton – 用于顶端按钮的风格名称

//MyVerticalScrollbardownbutton – 用于底端按钮的风格名称

//MyScrollbarthumb – 用于滑块的风格名称

scrollPos = GUILayout.HorizontalScrollbar(scrollPos, 1, 0, 100, “MyVerticalScrollbar”);

◆ static function VerticalSlider(value : floar, leftValue : float, rightValue : float, params options : GUILayoutOption[]) : float

◆ static function VerticalSlider(value : floar, leftValue : float, rightValue : float, slider : GUIStyle, thumb : GUIStyle, params options : GUILayoutOption[]) : float

参数

value滑杆显示的值。这个决定可拖动滑块的位置。

topValue滑杆顶端的值。

downValue  滑杆底端的值。

slider  用于显示拖动区域的GUIStyle。如果不设置,将使用当前GUISkin的horizontalSlider。

thumb  用于显示拖动块的GUIStyle。如果不设置,将使用当前的GUISkin的horizontalSliderThumb。

options  一个可选的布局选项的列表,它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

◆ static function Width(width : float) : GUILayoutOption

描述:传递给控件的选项以便给它一个绝对宽度

◆ static function Window(id : int, screenRect : Rect, func : GUIWindowFunction, text : string) : Rect

◆ static function Window(id : int, screenRect : Rect, func : GUIWindowFunction, image : Texture) : Rect

◆ static function Window(id : int, screenRect : Rect, func : GUIWindowFunction, content : GUIContent) : Rect

◆ static function Window(id : int, screenRect : Rect, func : GUIWindowFunction, text : string, style : GUIStyle) : Rect

◆ static function Window(id : int, screenRect : Rect, func : GUIWindowFunction, image : Texture, style : GUIStyle) : Rect
◆ static function Window(id : int, screenRect : Rect, func : GUIWindowFunction, content : GUIContent, style : GUIStyle) : Rect

参数

id 用于每个窗口唯一的ID。这是用于接口的ID。

clientRect  屏幕上用于窗口的矩形区域。布局系统将试图使窗体在他内部。如果不能,它将调整矩形去适应它

func  在窗体内部创建GUI的函数。这个函数必须使用一个函数 – 当前创建GUI的窗体id。

image 用于在标题栏上显示图片的Texture。

content 用于这个窗口的文本,图形和提示。

style 使用的风格。如果不设置,将使用当前GUISkin的button风格。

options  一个可选的布局选项的列表,它用来指定额外的布局属性。任何在这里设置的值将覆盖由style定义的设置。

参见:GUILayout.Width,  GUILayout.Height,  GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

返回Rect – 窗口位于举行位置。这个可能与你传入的一个具有不同位置和尺寸。

描述:制作一个弹出窗口。它的内容是自动布局的。

窗口浮动在普通GUI控件之上。具有单击激活的特点并可以有选择的随意被用户拖动。不像其他的控件,你需要传递给他们一个独立的功能并放置在窗口中这儿是一个小例子来帮助你开始:

var windowRect = Rect(20, 20, 120, 50);
function OnGUI()

{

//注册窗口,注意第三个参数

windowRect = GUILayout.Window(0, windowsRect, DoMyWindow, “My Window”);

}
//制作窗口内容

function DoMyWindow(windowed : int)

{

//这个按钮将调整以适应物体

if(GUILayout.Button(“Hello World”))

  print(“Get a click”);

}

你传入的客户区域只是作为一个参考,为了对窗口使用额外的限制。闯入一些额外的布局选项。用在这里的一个将覆盖尺寸的计算。这是一个简单的例子。

var windowRect = Rect(20, 20, 120, 50);
function OnGUI()

{

//注册窗口,这里我们指示布局系统必须使窗体为100像素宽。

windowRect = GUILayout.Window(0, windowRect, DoMyWindow, “My Window”, GUILayout.width(100));

}
//制作窗体内容

function DoMyWindow(windowID : int)

{

//这个按钮大小不能适应这个窗体

//通常,这个窗体将被扩展以便适应这个按钮。但是由于GUILayout.Width将只允//许窗体为100像素宽

if(GUILayout.Button(“Please click me a lot”))

print(“Get a click”);
}

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-7-14 10:09 , Processed in 0.082862 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部