使用屏幕尺寸缩放GUI.TextArea [英] Scaling GUI.TextArea with Screen Size

查看:154
本文介绍了使用屏幕尺寸缩放GUI.TextArea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试缩放GUI.TextArea.

i'm trying to scale a GUI.TextArea.

代码块在OnGui函数中起作用.但是,当我更改屏幕大小时,textArea的位置和大小将不正确.

the code block works in OnGui function. But when i change screen size , the textArea won't be on correct position and size.

第一屏幕尺寸

第二个屏幕尺寸

是否有诸如Canvas.ScaleMode.ScaleToFit之类的解决方案,还是我应该重新创建GUI.TextArea?

is there any solution like Canvas.ScaleMode.ScaleToFit or should i recreate the GUI.TextArea?

我在画布中使用按钮,一些图像和文本,并使用canvasScaler脚本轻松缩放它们.但是该文本对象不包含多行文本,因此我使用gui创建了textarea来显示多行文本.

I use button,some image and text in canvas and easily scale them with canvasScaler script. But the text object doesn't contain multiple line text so i create textarea with gui for display multiple line text.

推荐答案

统一的UI系统非常易于使用...

The UI system in unity is very easy to use...

1)点击添加画布..选择根据屏幕尺寸缩放"

1) click add canvas .. select "scale with screen size"

(请注意,这在画布缩放器" 部分中-不在画布" 部分中.)

(Note that this is in the "Canvas Scaler" section - it is NOT in the "Canvas" section.)

(2017年-请注意,他们最近将措辞从空格"更改为大小" ...)

(2017 - note they recently changed the wording from "space" to "size"...)

其他选项无关紧要,几乎从未使用过.

The other options are irrelevant and almost never used.

2)单击添加按钮",或添加所需的任何元素:面板.滚动视图,滑块等.

2) click "Add Button", or add any element you want: panel. scroll view, slider, etc.

您已经完全完成了.

就这么简单.

对于给定的项目:要实现您对POSITION所说的话,只需执行此操作...

For a given item: to achieve what you say about POSITION, just do this ...

选择与您相关的选项,可能是中间选项.

select the option relevant to you, probably middle one.

您的脚本中有

  public Text hello

这将在检查器"面板中为该脚本创建一个插槽(标记为"hello").

That will create a slot (labelled "hello") in your Inspector panel for that script.

请确保将.Text物理单元(即,画布"下方)拖动到检查器中的该插槽.用代码设置文本很简单:

be sure to drag the physical .Text unit (ie, underneath "Canvas") to that slot in the Inspector. To set the text, in code, is trivial:

    hello.text = "some text here"; 

就这么简单.您可以在编辑器中设置类型的大小,形状,位置等,所见即所得.

it's that simple. You can set the size, shape, position, etc of the type in the editor, what you see is what you get.

请务必设置以下项目...

Be sure to set the following items ...

...根据需要.干杯.

... as you need them. Cheers.

这篇关于使用屏幕尺寸缩放GUI.TextArea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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