12 第1页 | 共2 页下一页
返回列表 发新帖
查看: 2846|回复: 17
打印 上一主题 下一主题

Layout Modes 布局模式

[复制链接]

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

跳转到指定楼层
楼主
发表于 2011-8-16 08:19:49 |只看该作者 |倒序浏览
Layout Modes 布局模式
Fixed Layout vs Automatic Layout 确定布局与自动布局

你有两种方式来安排组织你的GUI:确定模式和自动模式。在导读中提供的所有的GUI例子都是用确定布局。利用自动布局模式,写GUI布局来代替GUI调用控制函数,你不必一个个的利用布局模式,而是在同样的OnGUI()函数中调用一次就可以了。

确定布局模式理解起来就像一个已经设计好的工作接口,自动布局模式理解起来就像我们在预先不知道元件,或者是不需要担心去一个个手配控制位置。比如,如果你创建一些基于保存游戏目录的大量的不同按钮,你不知道确切的将会有多少按钮,在这种情况下自动布局模式用起来会更方便,它只依靠你游戏的设计和提供怎样的接口。

这里有两种不同的自动布局模式:

1、 GUI布局用来代替GUI

2、 没有Rect()用来做自动布局控制

/* Two key differences when using Automatic Layout */
function OnGUI () {

// Fixed Layout

GUI.Button (Rect (25,25,100,30), "I am a Fixed Layout Button");
// Automatic Layout

GUILayout.Button ("I am an Automatic Layout Button");

}
Arranging Controls 安排控制

依靠你所用到的布局模式,在你控制端放置的地方有许多不同的钩子并且聚集在一起。你通过利用内部的GUI.BeginGroup()函数和GUI.EndGroup()函数,定义一组函数。组内的所有控制将被放置在组的左上角代替屏幕左上角。这种方法,如果你在运行时重新配置组,组内所有的控制会保持在想关联的位置。

例如,可以很容易的把一系列控制放置在屏幕中心。

/* Center multiple Controls on the screen using Groups */
function OnGUI () {

// Make a group on the center of the screen

GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));

// All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.
// We'll make a box so you can see where the group is on-screen.

GUI.Box (Rect (0,0,100,100), "Group is here");

GUI.Button (Rect (10,40,80,30), "Click me");
// End the group we started above. This is very important to remember!

GUI.EndGroup ();

}




上面例子中的控制中心与屏幕的分辨率无关
你也可以在多个组内部构建,当你这样做的时候,所有组的内容短于它的父空间。

/* Using multiple Groups to clip the displayed Contents */
var bgImage : Texture2D; // background image that is 256 x 32

var fgImage : Texture2D; // foreground image that is 256 x 32

var playerEnergy = 1.0; // a float between 0.0 and 1.0
function OnGUI () {

// Create one Group to contain both images

// Adjust the first 2 coordinates to place it somewhere else on-screen

GUI.BeginGroup (Rect (0,0,256,32));
// Draw the background image

GUI.Box (Rect (0,0,256,32), bgImage);
// Create a second Group which will be clipped

// We want to clip the image and not scale it, which is why we need the second Group

GUI.BeginGroup (Rect (0,0,playerEnergy * 256, 32));
// Draw the foreground image

GUI.Box (Rect (0,0,256,32), fgImage);
// End both Groups

GUI.EndGroup ();

GUI.EndGroup ();

}



你可以构筑一类来创建剪切行为
Automatic Layout – Areas 自动布局-区域

区域只有在布局模式中才会被用到,它们在功能上与确定布局组相类似,它们定义了屏幕中有限的一部分来放置GUI布局控制。由于自动布局的自身性质,你几乎可以利用所有的地方。

在自动布局模式中,你不必忙于定义控制端在控制层在屏幕中的区域,控制端会自动在屏幕左上端放置。或许在屏幕中,你可以创建自己手动创建放置位置,GUI布局控制会放置在区域的最左上方。

/* A button placed in no area, and a button placed in an area halfway across the screen. */
function OnGUI () {

GUILayout.Button ("I am not inside an Area");

GUILayout.BeginArea (Rect (Screen.width/2, Screen.height/2, 300, 300));

GUILayout.Button ("I am completely inside an Area");

GUILayout.EndArea ();

}

注意到在区域中,可见元件的控制端像按钮和盒子一样在整个区域宽度范围上拉伸。
Automatic Layout - Horizontal and Vertical Groups 自动布局-水平和垂直组

当用自动布局时,控制端会按照默认的样式从顶部到底部一个个出现,你会有很多好的机会把它们更好的排列和放置,如果你利用自动布局模式,你可以选择水平和垂直组。

就像其他布局控制一样,你可以调用分离函数来开始或结束组,特定的功能函数是GUILayout.BeginHoriztontal(),GUILayout.EndHoriztontal(),GUILayout.BeginVertical(),GUILayout.EndVertical()。

    任何在水平组内部放置的控制端会被水平放置,任何在垂直组内部放置的控制端会被垂直放置,这听起来很清晰直到你在他们之间嵌套的时候,它可以让你在图形构造中安排任何数量的控制端。

/* Using nested Horizontal and Vertical Groups */
var sliderValue = 1.0;

var maxSliderValue = 10.0;
function OnGUI()

{

// Wrap everything in the designated GUI Area

GUILayout.BeginArea (Rect (0,0,200,60));
// Begin the singular Horizontal Group

GUILayout.BeginHorizontal();
// Place a Button normally

if (GUILayout.RepeatButton ("Increase max
Slider Value"))

{

  maxSliderValue += 3.0 * Time.deltaTime;

}
// Arrange two more Controls vertically beside the Button

GUILayout.BeginVertical();

GUILayout.Box("Slider Value: " + Mathf.Round(sliderValue));

sliderValue = GUILayout.HorizontalSlider (sliderValue, 0.0, maxSliderValue);
// End the Groups and Area

GUILayout.EndVertical();

GUILayout.EndHorizontal();

GUILayout.EndArea();

}



三个控制端按照水平组和垂直组排列
Using GUILayoutOptions to define some controls 利用GUI布局选择来定义一些控制端

你可以利用一些GUI布局选择来优先于一些自动布局参数,你可以通过GUI布局控制端最终参数提供选择。

记住在上面的示例区域中,当按钮拉伸宽度到区域宽度的100%时?我们可以优先于我们想要的。

/* Using GUILayoutOptions to override Automatic Layout Control properties */
function OnGUI () {

GUILayout.BeginArea (Rect (100, 50, Screen.width-200, Screen.height-100));

GUILayout.Button ("I am a regular Automatic Layout Button");

GUILayout.Button ("My width has been overridden", GUILayout.Width (95));

GUILayout.EndArea ();

}

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

使用道具 举报

Asen    

867

主题

0

听众

1万

积分

外协人员

Rank: 7Rank: 7Rank: 7

纳金币
17488
精华
1
沙发
发表于 2011-8-25 11:03:30 |只看该作者
自适应 不错~
回复

使用道具 举报

1026

主题

1

听众

6011

积分

高级设计师

Rank: 6Rank: 6

纳金币
5996
精华
1

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

板凳
发表于 2011-8-27 10:36:21 |只看该作者
图出不来啊
回复

使用道具 举报

tc    

5089

主题

1

听众

33万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

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

地板
发表于 2012-1-26 23:18:37 |只看该作者
祝你新的一年:生活越来越好,脾气越来越小,经济再往上搞,基本解决温饱,顿顿保证没草,家中肉多狼少,饭菜不用再讨,也有异性来骚扰。
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

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

5#
发表于 2012-1-31 23:27:03 |只看该作者
新年狂欢,挥手过往,尘埃落定。迎接新年,快乐无敌。放松心情,能量积蓄。共盼美好,祝福真切。闪亮人生,精彩同行。祝春节愉快!
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

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

6#
发表于 2012-2-8 23:27:00 |只看该作者
水。。。
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

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

7#
发表于 2012-3-12 23:21:56 |只看该作者
我看看就走,你们聊!
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

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

8#
发表于 2012-8-15 23:52:17 |只看该作者
好可爱的字,学习了
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

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

9#
发表于 2012-8-26 00:00:58 |只看该作者
无聊时可以刷屏幕 灌水 也可以试试 帖子的标题究竟可以写多长
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

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

10#
发表于 2012-9-5 23:32:15 |只看该作者
水……生命之源……灌……
回复

使用道具 举报

12 第1页 | 共2 页下一页
返回列表 发新帖
您需要登录后才可以回帖 登录 | 立即注册

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

GMT+8, 2024-9-21 17:58 , Processed in 0.095047 second(s), 28 queries .

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

© 2008-2019 Narkii Inc.

回顶部