缩放用户界面以支持多种分辨率/不同的设备
我有一个非常简单的统一GUI,它具有以下方案:
I have a quite simple unity GUI that has the following scheme :
Brett和按钮在哪里.
Where Brekt and so are buttons.
GUI在PC上运行良好,并且在screen space : overlay
上,因此应该可以自动调整以适合每个屏幕.
The GUI works just fine on PC and is on screen space : overlay
so it is supposed to be adapted automatically to fit every screen.
但是在平板电脑上,整个GUI较小,并且在屏幕中央缩小,元素周围有很大的空白(现在无法加入屏幕截图)
But on tablet the whole GUI is smaller and reduced in the center of the screen, with huge margins around the elements (can't join a screenshot now)
解决该问题的方法是什么?是在播放器设置中还是项目设置中?
What is the way to fix that? Is it something in player settings or in project settings?
自动缩放UI要求结合使用锚点,RecTransform
的枢轴点和
Automatically scaling the UI requires using combination of anchor,pivot point of RecTransform
and the Canvas Scaler
component. It is hard to understand it without images or videos. It is very important that you thoroughly understand how to do this and Unity provided full video tutorial for this.You can watch it here.
此外,当使用滚动条,scrollview和其他类似的UI控件时, ContentSizeFitter
组件还用于确保它们适合该布局.
Also, when using scrollbar, scrollview and other similar UI controls, the ContentSizeFitter
component is also used to make sure they fit in that layout.