Unity 4.6 - 如何为每个分辨率将 GUI 元素缩放到合适的大小 [英] Unity 4.6 - How to scale GUI elements to the right size for every resolution

查看:22
本文介绍了Unity 4.6 - 如何为每个分辨率将 GUI 元素缩放到合适的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的 Unity 4.6 带有一个新的 GUI,当我在 Unity 上更改分辨率时,UI 按钮可以完美缩放,但是当我在 Nexus 7 设备上测试时,按钮看起来太小了.知道如何解决这个问题吗?

The new Unity 4.6 comes with a new GUI, when I change de resolution on Unity the UI Button scales perfectly but when I test on the Nexus 7 device the Button looks too small. Any idea how to solve this?

推荐答案

Unity 的新 GUI 系统使用锚点"来控制 gui 元素(如按钮)相对于其父容器的缩放方式.

Unity's new GUI system uses "anchors" to control how gui elements (like buttons) scale in relation to their parent container.

Unity 有一个关于如何使用新的矩形变换"组件(在其中配置锚点)的教程视频:http://unity3d.com/learn/tutorials/modules/beginner/ui/rect-transform.

Unity has a tutorial video on how to use the new "Rect Transform" component (where the anchors are configured) here: http://unity3d.com/learn/tutorials/modules/beginner/ui/rect-transform.

教程的后半部分都是关于锚点的.该页面包含指向整个教程系列的链接.时间不算长.你应该看整件事.

The last half of the tutorial is all about anchors. That page has links to the entire tutorial series. It's not too long. You should watch the whole thing.

针对您的问题:

锚点在您的第一个屏幕截图中可见.它们是按钮左上角的 4 个小箭头.

The anchors are visible in your first screen shot. They are those 4 little arrows at the top left of your button.

现在,您的按钮仅锚定在左上角.

Right now, your button is only anchored by it's top left corner.

需要将两个右锚点向右拖动,以便按钮的右边缘锚定到其父容器内的空间.

The two right anchors need to be dragged to the right so that the right edge of your button is anchored to a space inside its parent container.

根据您的情况,可能需要向下拖动底部的两个箭头,以便将按钮的底部边缘也固定.

Depending on your situation, the two bottom arrows may need to be dragged down so that the bottom edge of your button is anchored as well.

我上面链接的视频详细介绍了所有这些.

The video I linked above covers all this in detail.

最后,为了在不同分辨率下很好地缩放字体大小,您需要向 UI 的基本画布添加和配置参考分辨率组件,如 Ash-Bash32 之前所写.

Lastly, for the font size to scale nicely on different resolutions, you will need to add and configure a reference resolution component to the base canvas of your UI, as Ash-Bash32 wrote earlier.

更新:添加参考分辨率组件的最佳方式是通过 UI 中基础画布的检查器窗口.

Update: The best way to add a Reference Resolution component is through the inspector window for the base canvas in your UI.

1) 单击检查器底部的添加组件按钮".

1) click the "Add Component Button" at the bottom of the inspector.

2) 在搜索过滤器字段中输入参考"一词.

2) type the word "Reference" in the search filter field.

3) 在搜索结果中选择Reference Resolution"组件.

3) select the "Reference Resolution" component in the search results.

这篇关于Unity 4.6 - 如何为每个分辨率将 GUI 元素缩放到合适的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆