NGUI控件的一些说明——基于3.7.7版本

最近在学习unity的NGUI插件,对于在手机上的自动排版功能一直是觉得很不人性化,比起虚幻4差了好多,不过还是就此记录一下

首先是UIRoot,UIRoot 是unity 的ngui插件的核心脚本,正如其名字一样,所有的控件都根据其设定来进行绘制;

由于最近在开发手机游戏,我比较在意Scaling Style 的问题
官方文档中给我们的控件的的缩放模式是这么描述的
Flexible style lets your UI always be in pixels, and a 300x200 widget will always take 300 by 200 pixels on the screen. This also means that viewing your UI on a low-res device will make your widgets appear rather large in size, and viewing your UI on a high-res device will make your widgets appear small. On the plus side, with this setting your UI will always remain as crisp as possible.
这里我用我渣渣的英语水平翻译一下:
Flexible:这样方式保存的场景和控件大小是固定的,如果你设置的像素值为 300*200 那么在屏幕比较小的设备上,它会显的比较大;屏幕比较大的设备上会显得比较小;其实就是大小不会根据屏幕大小变化而变化。这个不符合我们屏幕自适应的要求,应该也不会常用。

Constrained is the exact opposite of that. When the UIRoot is set to this setting, your screen will always remain the same size as far as NGUI is concerned, regardless of the actual screen size. This means that if a 300x200 widget takes 25% of your screen with the resolution of 1920x1080, it will still take 25% of the screen when you drop your resolution to 1280x720. If you don't want to worry about how your UI will look at different screen sizes and you don't care much about making it as crisp as possible, choose this setting. Don't forget to set the Contentdimensions setting when choosing this option.
Constrained:这个与上面那种方式是完全相反的,他不会固定一个值,而是随着设备屏幕大小的变化而变化,大小是依据百分比,但是要注意,在根据百分比缩放的同时 画面有可能会失真。

ConstrainedOnMobiles setting is a combination of the two. It will behave as if the setting was "Flexible" on desktop builds, and it will act as if the size was "Constrained" when targeting mobile platforms.
ConstrainedOnMobiles:这个我没太理解,大概意思应该是在桌面设备上它会以 Flexible 的方式进行显示,如果是移动设备的话它将以 Constrained 的方式显示。
这样我们直接更改Scaling Style 的值为Constrained就可以实现基础的屏幕自适应分辨率大小了,而不用2.X系列版本的代码控制;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值